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 3

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
Enabling the Example Application with MTOM
JAX-WS 2.0 supports MTOM for both SOAP 1.1 and SOAP 1.2 HTTP bindings. This section describes how to enable the example application with MTOM using the SOAP 1.1 binding. Working with SOAP 1.2 would require slight adjustments to the application and obvious changes to the instructions to follow.

With JAX-WS 2.0, you can enable MTOM on the client side, the service side, or both. To enable MTOM on the client side for the example application, all you need to do is uncomment the first two bold lines in Listing 6, the client application:

SOAPBinding binding = (SOAPBinding)((BindingProvider)port).getBinding(); binding.setMTOMEnabled (true);



When you call the upload() method in this case (with the client MTOM enabled and the service not), the request SOAP message will look like Listing 2, indicating the client is sending optimized messages. Even though the service is not MTOM-enabled, the call succeeds. This shows that the service is able to respond to both optimized and ordinary messages.

When you invoke the retrieve() operation, the response SOAP message looks like Listing 7, indicating the service is sending ordinary messages even though the client is MTOM-enabled.

Two provisions to note are:

  1. The SOAPBinding interface also provides a method for checking if MTOM is enabled on the binding, javax.xml.ws.soap.SOAPBinding.isMTOMEnabled().
  2. JAX-WS 2.0 allows clients to interact with a web service through either a port proxy (as in this example) or the Dispatch API. MTOM can be enabled only for port proxy-based clients.

On the service side, you can enable MTOM in one of three ways:

  1. You can add one line to the proprietary web service deployment descriptor, sun-jaxws.xml, as follows:

    <?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" enable-mtom="true"/> </endpoints>

  2. Use the same descriptor as in the following example:

    <?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" binding="http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true" port="{http://catalog.mtom.company.com/service}CatalogPort" url-pattern="/Catalog"/> </endpoints>

    Notice the binding attribute of endpoint. To enable MTOM for SOAP 1.1 or SOAP 1.2 HTTP bindings, you may specify one of the following identifiers for the binding attribute, respectively:

    • http://schemas.xmlsoap.org/wsdl/soap/http?mtom=true
    • http://www.w3.org/2003/05/soap/bindings/HTTP/?mtom=true
  3. Use the @javax.xml.ws.BindingType annotation on the service endpoint implementation class, specifying a value of javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING (or javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_MTOM_BINDING for SOAP 1.2). This approach is a variant of the second and is JAX-WS 2.0 standard compliant. The following example illustrates it:

    @WebService(endpointInterface = "com.company.mtom.catalog.service.CatalogPortType") @BindingType(value=SOAPBinding.SOAP11HTTP_MTOM_BINDING) public class CatalogImpl implements CatalogPortType { ...... }

    The predefined constant javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_MTOM_BINDING (.SOAP12HTTP_MTOM_BINDING) corresponds to the MTOM-enabled SOAP 1.1 (SOAP 1.2) HTTP binding identifier listed above.

When the service-side MTOM is enabled, if you disable MTOM at the client side you will find from tcpmon that the web service will send an optimized SOAP response when the client calls the retrieve() method (see Listing 8). Comparing this with Listing 7, the content of the .../chapter/content element in the SOAP body is replaced with an xop:Include element, which refers to the actual sample chapter content as a binary stream in a MIME part.

With MTOM enabled only on the service side, when the client invokes the upload() method it sends an ordinary SOAP request message, and the service is able to respond properly per the JAX-WS 2.0 specification.

If you have both the service side and the client side MTOM enabled, all communications are optimized when applicable.



Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap