Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Boost Web Service Performance in JAX-WS with Fast Infoset : Page 2

Web service performance depends largely on the size of the XML data being transmitted and the speed of XML processing. Fast Infoset helps greatly with those aspects.


advertisement
Fast Infoset in Practice with a JAX-WS 2.0 Web Service
In this section, you will develop and examine a sample web service with JAX-WS RI, which will demonstrate Fast Infoset in practice.

This sample web service simulates a book catalog management system. The web service endpoint interface CatalogPort defines three operations: echo, upload, and retrieve. You will use the echo() method later to allow clients to initiate a request to the service and establish Fast Infoset encoding for the remaining message exchanges. The upload() and retrieve() methods allow client applications to register (and update) book information and retrieve the sample chapter stored in the system, respectively.

In the endpoint implementation class CatalogImpl.java, the upload() method stores the following:

  • Basic information about the book and the sample chapter name in a properties file with the name of ${isbn}.properties under the book_info folder
  • The cover image in a file ${isbn}.jpg under the book_cover folder
  • The description (desc) string in a file ${isbn}.txt under the book_desc folder
  • The sample chapter content in a file ${isbn}.pdf under the folder book_sample



The upload() method simply returns a Boolean value indicating whether the implementation process completed successfully. The retrieve() method on the other hand obtains the sample chapter name from the properties file and the content from the book_sample directory (all based on an input parameter isbn) and returns a Chapter object to the client. In the message exchange related to the upload() method call, XML processing and transport overhead is associated mainly with requests, and the size of the request message depends mainly on the sizes of the cover image and sample chapter content. In the message exchange related to the retrieve() method call, XML processing and transport overhead is associated mainly with responses, and the size of the response message depends mainly on the size of the sample chapter content. You will consider these behaviors later to design your performance test harness and present the collected performance data.

Extract the application source code for the web service WSDL and related XML schema file from the code download. To implement the web service with JAX-WS 2.0, you need to use the apt tool to generate the port type interface CatalogPortType.java, the domain objects in the com.company.mtom.catalog.book package, and the service class Catalog.java, which the clients will use to obtain the CatalogPort.

After creating the service endpoint implementation class, you're ready to get the web service up and running. You need to come up with the web service deployment descriptor (sun-jaxws.xml) and the web application deployment descriptor (web.xml), and then deploy the application war into a container (Tomcat, in this example). That's about it for the service.

On the client side, you keep the input book information in a properties file named isbn and the book cover image, sample chapter content, and description text in separate files under ./etc. In the sample client, the private method getBook() creates a Book object for invoking upload(), and compareSample() compares retrieved (through retrieve()) sample chapter names and content with information available in the local repository (.../etc). Note that the client uses the open source JAMon library to collect response time information.

The sample application comes with all the input files utilized by the client for three sample books. To look at the SOAP messages in transmission, you can install tcpmon as a proxy. Later, you will see that when Fast Infoset is enabled for the message exchanges, the messages displayed in tcpmon are mostly gibberish.

Next, you will see how to enable Fast Infoset in JAX-WS RI with the sample web service.

Fast Infoset in Action with JAX-WS RI
The reference implementation of JAX-WS supports Fast Infoset by negotiating HTTP content with the standard HTTP headers Accept and Content-Type. By default, all JAX-WS web services are Fast Infoset-enabled (through the service runtime). To turn on Fast Infoset for message exchanges, the client needs to indicate to the service that the client runtime is capable of working with Fast Infoset documents. It accomplishes this by sending an initial request encoded in standard XML and including the MIME type application/fastinfoset as part of the HTTP Accept header list. After this initial request, all the conversations between the client and the service will be encoded in Fast Infoset, as long as the client continues to use the same BindingProvider instance to converse with the service.

In JAX-WS RI, you can enable the above content negotiation in two ways:

  1. Set a system property on the JVM used to run the client
  2. Set a property on the binding provider object (a port proxy or a dispatch)

In either case, both the property name, "com.sun.xml.ws.client.ContentNegotiation", and its value, "pessimistic", are identical. (In contrast, for the optimistic form, the client directly initiates a message exchange using Fast Infoset encoding.) The JAX-WS 2.0 RI also defines a constant, CONTENT_NEGOTIATION_PROPERTY, in the interface, com.sun.xml.ws.developer.JAXWSProperties, to represent the property name, but this constant was deprecated in a later release of the reference implementation, version 2.1.1.

With the first approach (setting the system property on the JVM), you can start the JVM in which the web service client runs like this:

java –Dcom.sun.xml.ws.client.ContentNegotiation=pessimistic ...

This code snippet shows an Ant target that runs the sample web service client with content negotiation enabled:

<target name="run"> <java fork="true" classname="${client}"> <classpath> <path refid="client.classpath"/> <pathelement location="${build.classes.home}"/> <pathelement location="${basedir}/conf"/> </classpath> <sysproperty key="com.sun.xml.ws.client.ContentNegotiation" value="pessimistic"/> <arg value="${isbn}"/> </java> </target>

You can also enable the sample application with content negotiation by following the second approach (setting the property on the binding provider object) like this:

...... CatalogPortType port = service.getCatalogPort(); ((BindingProvider) port).getRequestContext().put(JAXWSProperties.CONTENT_NEGOTIATION_PROPERTY,
"pessimistic"); //((BindingProvider) port).getRequestContext().put("com.sun.xml.ws.client.ContentNegotiation",
"pessimistic"); ......

The example uses a port proxy. If you are working with a Dispatch instance, you can again cast it, get the request context, and set the corresponding property to enable content negotiation because a Dispatch instance in JAX-WS is also a BindingProvider.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap