Archive for November, 2007

Java & XML, 2nd Edition // (Web server certificate) Build the

Friday, November 30th, 2007

Java & 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.

Web hosting uk - Java & XML, 2nd Edition It’s no accident

Friday, November 30th, 2007

Java & XML, 2nd Edition It’s no accident that the CD class follows the JavaBean conventions. Most data classes fit easily into this format, and I knew I wanted to avoid writing my own custom serializer and deserializer. These are a pain to write (not overly difficult, but easy to mess up), and I recommend you go to great lengths to try and use the Bean conventions in your own custom parameters. In many cases, the Bean conventions only require that a default constructor (with no arguments) is present in your class. Now recreate your service jar file. Then, redeploy your service: (gandalf)/javaxml2/Ch12$ java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter xml/CDCatalogDD.xml If you have kept your servlet engine running and the service deployed all this time, you’ll need to restart the servlet engine to activate the new classes for the SOAP service, and redeploy the service. At this point, all that’s left is modifying the client to use the new class and methods. Example 12-10 is an updated version of the client class CDAdder . The changes from the previous version of the class are highlighted. Example 12-10. The updated CDAdder class package javaxml2; import java.net.URL; import java.util.Vector; import org.apache.soap.Constants; import org.apache.soap.Fault; import org.apache.soap.SOAPException; import org.apache.soap.encoding.SOAPMappingRegistry; import org.apache.soap.encoding.soapenc.BeanSerializer; import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Parameter; import org.apache.soap.rpc.Response; import org.apache.soap.util.xml.QName; public class CDAdder { public void add(URL url, String title, String artist, String label) throws SOAPException { System.out.println(”Adding CD titled ‘” + title + “‘ by ‘” + artist + “‘, on the label ” + label); CD cd = new CD(title, artist, label); // 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);
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Java & XML, 2nd Edition // Return the (Php web hosting)

Thursday, November 29th, 2007

Java & XML, 2nd Edition // Return the requested CD return (CD)catalog.get(title); } public Hashtable list( ) { return catalog; } } In addition to the obvious changes, I’ve also updated the old getArtist(String title) method to getCD(String title), and made the return value a CD object. This means the SOAP server will need to serialize and deserialize this new class, and the client will be updated. First, I look at an updated deployment descriptor that details the serialization issues related to this custom type. Add the following lines to the deployment descriptor for the CD catalog, as well as changing the available method names to match the updated CDCatalogclass: org.apache.soap.server.DOMFaultListener The new element, mappings, specifies how a SOAP server should handle custom parameters such as the CD class. First, define a map element for each custom parameter type. For the encodingStyle attribute, at least as of Apache SOAP 2.2, you should always supply the value http://schemas.xmlsoap.org/soap/encoding/, the only encoding currently supported. You need to supply a namespace for the custom type and then the name of the class, with this namespace prefix, for the type. In my case, I used a “dummy” namespace and the simple prefix “x” for this purpose. Then, using the javaType attribute, supply the actual Java class name: javaxml2.CD in this case. Finally, the magic occurs in the java2XMLClassName and xml2JavaClassName attributes. These specify a class to convert from Java to XML and from XML to Java, respectively. I’ve used the incredibly handy BeanSerializer class, also provided with Apache SOAP. If your custom parameter is in a JavaBean format, this serializer and deserializer will save you from having to write your own. You need to have a class with a default constructor (remember that I defined an empty, no-args constructor within the CD class), and expose all the data in that class through setXXX and getXXX style methods. Since the CD class fits the bill here, the BeanSerializer works perfectly.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Web host music - Java & XML, 2nd Edition public String getArtist(

Thursday, November 29th, 2007

Java & XML, 2nd Edition public String getArtist( ) { return artist; } public void setArtist(String artist) { this.artist = artist; } public String getLabel( ) { return label; } public void setLabel(String label) { this.label = label; } public String toString( ) { return “‘” + title + “‘ by ” + artist + “, on ” + label; } } This requires a whole slew of changes to the CDCatalog class as well. Example 12-9 shows a modified version of this class with the changes that use the new CD support class highlighted. Example 12-9. An updated CDCatalog class package javaxml2; import java.util.Hashtable; public class CDCatalog { /** The CDs, by title */ private Hashtable catalog; public CDCatalog( ) { catalog = new Hashtable( ); // Seed the catalog addCD(new CD(”Nickel Creek”, “Nickel Creek”, “Sugar Hill”)); addCD(new CD(”Let it Fall”, “Sean Watkins”, “Sugar Hill”)); addCD(new CD(”Aerial Boundaries”, “Michael Hedges”, “Windham Hill”)); addCD(new CD(”Taproot”, “Michael Hedges”, “Windham Hill”)); } public void addCD(CD cd) { if (cd == null) { throw new IllegalArgumentException( “The CD object cannot be null.”); } catalog.put(cd.getTitle( ), cd); } public CD getCD(String title) { if (title == null) { throw new IllegalArgumentException(”Title cannot be null.”); }
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Java & XML, 2nd Edition ‘Aerial Boundaries’ by (Web host)

Wednesday, November 28th, 2007

Java & XML, 2nd Edition ‘Aerial Boundaries’ by Michael Hedges That’s really all there is to basic RPC functionality in SOAP. I’d like to push on a bit, though, and talk about a few more complex topics. 12.4 Going Further Although you can now do everything in SOAP you knew how to do in XML-RPC, there is a lot more to SOAP. As I said in the beginning of the chapter, two important things that SOAP brings to the table are the ability to use custom parameters with a minimal amount of effort, and more advanced fault handling. In this section, I cover both of these topics. 12.4.1 Custom Parameter Types The most limiting thing with the CD catalog, at least at this point, is that it stores only the title and artist for a given CD. It is much more realistic to have an object (or set of objects) that represents a CD with the title, artist, label, track listings, perhaps a genre, and all sorts of other information. I’m not going to build this entire structure, but will move from a title and artist to a CD object with a title, artist, and label. This object needs to be passed from the client to the server and back, and demonstrates how SOAP can handle these custom types. Example 12-8 shows this new class. Example 12-8. The CD class package javaxml2; public class CD { /** The title of the CD */ private String title; /** The artist performing on the CD */ private String artist; /** The label of the CD */ private String label; public CD( ) { // Default constructor } public CD(String title, String artist, String label) { this.title = title; this.artist = artist; this.label = label; } public String getTitle( ) { return title; } public void setTitle(String title) { this.title = title; }
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Java & XML, 2nd Edition call.setMethodName(”list”); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); // (Web hosting colocation)

Wednesday, November 28th, 2007

Java & XML, 2nd Edition call.setMethodName(”list”); call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); // No parameters needed // Invoke the call Response response; response = call.invoke(url, “”); if (!response.generatedFault( )) { Parameter returnValue = response.getReturnValue( ); Hashtable catalog = (Hashtable)returnValue.getValue( ); Enumeration e = catalog.keys( ); while (e.hasMoreElements( )) { String title = (String)e.nextElement( ); String artist = (String)catalog.get(title); System.out.println(” ‘” + title + “‘ by ” + artist); } } else { Fault fault = response.getFault( ); System.out.println(”Error encountered: ” + fault.getFaultString( )); } } public static void main(String[] args) { if (args.length != 1) { System.out.println(”Usage: java javaxml2.CDAdder ” + “[SOAP server URL]”); return; } try { // URL for SOAP server to connect to URL url = new URL(args[0]); // List the current CDs CDLister lister = new CDLister( ); lister.list(url); } catch (Exception e) { e.printStackTrace( ); } } } The only difference in this method from the CDAdder class is that the Response object has a return value (the Hashtable from the list( ) method). This is returned as a Parameter object, which allows a client to check its encoding and then extract the actual method return value. Once that’s done, the client can use the returned value like any other Java object, and in the example simply runs through the CD catalog and prints out each one. You can now run this additional client to see it in action: C:javaxml2build>java javaxml2.CDListerhttp://localhost:8080/soap/servlet/rpcrouter Listing current CD catalog. ‘Riding the Midnight Train’ by Doc Watson’Taproot’ by Michael Hedges’Nickel Creek’ by Nickel Creek’Let it Fall’ by Sean Watkins
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Java & XML, 2nd Edition (Web proxy server) This program captures

Tuesday, November 27th, 2007

Java & XML, 2nd Edition This program captures the URL of the SOAP server to connect to, as well as information needed to create and add a new CD to the catalog. Then, in the add( ) method, the code creates the SOAP Call object, on which all the interesting interaction occurs. The target URI of the SOAP service and the method to invoke are set on the call, and both match up to values from the service’s deployment descriptor from Example 12-5. Next, the encoding is set, which should always be the constant Constants.NS_URI_SOAP_ENC unless you have very unique encoding needs. The program creates a new Vector populated with SOAP Parameter objects. Each of these represents a parameter to the specified method, and since the addCD( ) method takes two String values, this is pretty simple. Supply the name of the parameter (for use in the XML and debugging), the class for the parameter, and the value. The fourth argument is an optional encoding, if a single parameter needs a special encoding. For no special treatment, the value null suffices. The resulting Vector is then added to the Call object. Once your call is set up, use the invoke( ) method on that object. The return value from this method is an org.apache.soap.Response instance, which is queried for any problems that resulted. This is fairly self-explanatory, so I’ll leave it to you to walk through the code. Once you’ve compiled your client and followed the instructions earlier in this chapter for setting up your classpath, run the example as follows: C:javaxml2build>java javaxml2.CDAdder http://localhost:8080/soap/servlet/rpcrouter “Riding the Midnight Train” “Doc Watson” Adding CD titled ‘Riding the Midnight Train’ by ‘Doc Watson’Successful CD Addition Example 12-7 is another simple class, CDLister , which lists all current CDs in the catalog. I won’t go into detail on it, as it’s very similar to Example 12-6, and is mainly a reinforcement of what I’ve already talked about. Example 12-7. The CDLister class package javaxml2; import java.net.URL; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import org.apache.soap.Constants; import org.apache.soap.Fault; import org.apache.soap.SOAPException; import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Parameter; import org.apache.soap.rpc.Response; public class CDLister { public void list(URL url) throws SOAPException { System.out.println(”Listing current CD catalog.”); // Build the Call object Call call = new Call( ); call.setTargetObjectURI(”urn:cd-catalog”);
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Best web hosting site - Java & XML, 2nd Edition public class CDAdder

Tuesday, November 27th, 2007

Java & XML, 2nd Edition public class CDAdder { public void add(URL url, String title, String artist) throws SOAPException { System.out.println(”Adding CD titled ‘” + title + “‘ by ‘” + artist + “‘”); // Build the Call object Call call = new Call( ); 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(”title”, String.class, title, null)); params.addElement(new Parameter(”artist”, String.class, artist, 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 != 3) { System.out.println(”Usage: java javaxml2.CDAdder ” + “[SOAP server URL] ” + “”[CD Title]” “[Artist Name]”"); 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]; // Add the CD CDAdder adder = new CDAdder( ); adder.add(url, title, artist); } catch (Exception e) { e.printStackTrace( ); } } }
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Jetty web server - Java & XML, 2nd Edition (gandalf)/javaxml2/Ch12$ java org.apache.soap.server.ServiceManagerClient

Tuesday, November 27th, 2007

Java & XML, 2nd Edition (gandalf)/javaxml2/Ch12$ java org.apache.soap.server.ServiceManagerClient http://localhost:8080/soap/servlet/rpcrouter listDeployed Services: urn:cd-catalog urn:AddressFetcher urn:xml-soap-demo-calculator At a minimum, this should show any and all services you have available on the server. Finally, you can easily undeploy the service, as long as you know its name: C:javaxml2Ch12>java org.apache.soap.server.ServiceManagerClienthttp://localhost:8080/soap/servlet/rpcrouter undeploy urn:cd-catalog Every time you update your service code, you must undeploy and then redeploy to ensure the SOAP server is running the newest copy. 12.3.3 An RPC Client Next up is the client. I’m going to keep things simple, and just write a couple of command- line programs that invoke SOAP-RPC. It would be impossible to try and guess your business case, so I just focus on the SOAP details and let you work out integration with your existing software. Once you have the business portion of your code working, there are some basic steps you’ll take in every SOAP-RPC call: Create the SOAP-RPC call Set up any type mappings for custom parameters Set the URI of the SOAP service to use Specify the method to invoke Specify the encoding to use Add any parameters to the call Connect to the SOAP service Receive and interpret a response That may seem like a lot, but most of the operations are one- or two-line method invocations. In other words, talking to a SOAP service is generally a piece of cake. Example 12-6 shows the code for the CDAdder class, which allows you to add a new CD to the catalog. Take a look at the code, and then I’ll walk you through the juicy bits. Example 12-6. The CDAdder class package javaxml2; import java.net.URL; import java.util.Vector; import org.apache.soap.Constants; import org.apache.soap.Fault; import org.apache.soap.SOAPException; import org.apache.soap.rpc.Call; import org.apache.soap.rpc.Parameter; import org.apache.soap.rpc.Response;
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Java & XML, 2nd Edition First, I referenced (Free web hosting services)

Monday, November 26th, 2007

Java & XML, 2nd Edition First, I referenced the Apache SOAP deployment namespace, and then supplied a URN for my service through the id attribute. This should be something unique across services, and descriptive of the service. I showed about as much originality in naming the service as Dave Matthews did with his band, but it gets the job done. Then, I specified through the javaelement the class to expose, including its package name (through the class attribute), and indicated that the methods being exposed were not static ones (through the static attribute). Next, I specified a fault listener implementation to use. Apache’s SOAP implementation provides two; I used the first, DOMFaultListener. This listener returns any exception and fault information through an additional DOM element in the response to the client. I’ll get back to this when I look at writing clients, so don’t worry too much about it right now. The other fault listener implementation is org.apache.soap.server.ExceptionFaultListener. This listener exposes any faults through an additional parameter returned to the client. Since quite a few SOAP-based applications are already going to be working in Java and XML APIs like DOM, it’s common to use the DOMFaultListener in most cases. 12.3.2.3 Deploying the service At this point, you’ve got a working deployment descriptor and a set of code artifacts to expose, and you can deploy your service. Apache SOAP comes with a utility to do this task, provided you have done the setup work. First, you need a deployment descriptor for your service, which I just talked about. Second, you need to make the classes for your service available to the SOAP server. The best way to do this is to jar up the service class from the last section: jar cvf javaxml2.jar javaxml2/CDCatalog.class Take this jar file and drop it into your lib/ directory (or wherever libraries are auto-loaded for your servlet engine), and restart your servlet engine. When you do this, you have created a snapshot of your class file. Changing the code in the CDCatalog.java file and recompiling it will not cause the servlet engine to pick up the changes. You’ll need to re-jar the archive and copy it over to your lib/ directory each time code changes are made to ensure your service is updated. You’ll also want to restart your servlet engine to make sure the changes are picked up by the engine as well. With your service class (or classes) accessible by your SOAP server, you can now deploy the service, using Apache SOAP’s org.apache.soap.server.ServiceManager utility class: C:javaxml2Ch12>java org.apache.soap.server.ServiceManagerClienthttp://localhost:8080/soap/servlet/rpcrouter deploy xmlCDCatalogDD.xml The first argument is the SOAP server and RPC router servlet, the second is the action to take, and the third is the relevant deployment descriptor. Once this has executed, verify your service was added:
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.