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
 

Faster Data Transport Means Faster Web Services with MTOM/XOP : Page 2

MTOM/XOP provides optimized SOAP message transmission, which boosts the performance of web services. Get an overview of the technology and see it in action with JAX-WS 2.0.


advertisement
A Simple JAX-WS 2.0 Web Service
The sample web service developed in this section simulates a book catalog management system. (Listing 3 shows the web service WSDL.) It defines two operations in the service endpoint interface CatalogPort: upload and retrieve, which allow client applications to register (and update) book information and retrieve the sample chapter stored in the system, respectively. Listing 4 presents the schema file, Book.xsd, which is referred to in the WSDL. Pay particular attention to two previously mentioned elements, /book/coverImage and /book/sample/content.

To implement the sample web service with JAX-WS 2.0, you first need to use the apt tool to generate the port type interface CatalogPortType.java (see Listing 5), 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.

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

  1. 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.
  2. The cover image in a file ${isbn}.jpg under the book_cover folder.
  3. The description (desc) string in a file ${isbn}.txt under the book_desc folder.
  4. The sample chapter content in a file ${isbn}.pdf under the folder book_sample.



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.

To get the web service up and running, all you have to do now is 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). You can download the accompanying source code and look at these artifacts and the various Ant tasks for packaging, deployment, etc. For reference, here is the example's sun-jaxws.xml descriptor:

<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'> <endpoint name="catalog" implementation="com.company.mtom.catalog.service.CatalogImpl" wsdl="WEB-INF/wsdl/Catalog.wsdl" service='{http://catalog.mtom.company.com/service}Catalog' port='{http://catalog.mtom.company.com/service}CatalogPort' url-pattern="/Catalog"/> </endpoints>

That's about it for the service. Listing 6 shows the main body of the sample web service client, in which the input book information is captured in a properties file named isbn, and the book cover image, sample chapter content, and description text are all kept in separate files (under ./etc). The private method getBook() creates a Book object to be used for invoking upload(), and compareSample() compares retrieved (through retrieve()) sample chapter names and content with information available in the local repository at this client side (./etc).

The example 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. Listing 1 shows a SOAP request message as captured by tcpmon while invoking the upload() method with information about one of the sample books. Listing 7 shows the response from the web service when the client calls the retrieve() method. In this listing, the sample chapter content is base64 encoded and embedded in the SOAP body.



Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap