Java & XML, 2nd Edition // (Web server certificate) Build the
Friday, November 30th, 2007Java & XML, 2nd Edition // Build the Call object Call call = new Call( ); call.setSOAPMappingRegistry(registry); call.setTargetObjectURI(”urn:cd-catalog”); call.setMethodName(”addCD”); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); // Set up parameters Vector params = new Vector( ); params.addElement(new Parameter(”cd”, CD.class, cd, null)); call.setParams(params); // Invoke the call Response response; response = call.invoke(url, “”); if (!response.generatedFault( )) { System.out.println(”Successful CD Addition.”); } else { Fault fault = response.getFault( ); System.out.println(”Error encountered: ” + fault.getFaultString( )); } } public static void main(String[] args) { if (args.length != 4) { System.out.println(”Usage: java javaxml2.CDAdder ” + “[SOAP server URL] ” + “”[CD Title]” “[Artist Name]” “[CD Label]”"); return; } try { // URL for SOAP server to connect to URL url = new URL(args[0]); // Get values for new CD String title = args[1]; String artist = args[2]; String label = args[3]; // Add the CD CDAdder adder = new CDAdder( ); adder.add(url, title, artist, label); } catch (Exception e) { e.printStackTrace( ); } } } The only really interesting change is in dealing with the mapping of the CD class: // Map this type so SOAP can use it SOAPMappingRegistry registry = new SOAPMappingRegistry( ); BeanSerializer serializer = new BeanSerializer( ); registry.mapTypes(Constants.NS_URI_SOAP_ENC, new QName(”urn:cd-catalog-demo”, “cd”), CD.class, serializer, serializer);
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.