RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


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

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.

Enabling MTOM for Large-Sized Binary Data Only
The reference implementation of JAX-WS 2.0 has a proprietary feature that allows the service and/or client to optimize only binary data that are larger than a configured threshold. With the example application, you can set the threshold on the client side by uncommenting the third bold line in Listing 6. The number is measured in bytes, and the following sample will instruct the client runtime to optimize only binary data with a size larger than 5 KB (Yes, the property is named MTOM_THRESHOLOD_VALUE, obviously a typo not caught before the final release):

((BindingProvider) port).getRequestContext().put(JAXWSProperties.MTOM_THRESHOLOD_VALUE, 6120);

Binary data less than 5 KB will remain in line in the SOAP message and stay base64 encoded. The default threshold value of the JAX-WS 2.0 reference implementation is 1 KB.

On the service side, you can set the threshold programmatically by adding the following lines in the endpoint implementation class CatalogImpl.java:

private WebServiceContext wsContext;

wsContext.getMessageContext().put(com.sun.xml.ws.developer.JAXWSProperties.MTOM_THRESHOLOD_VALUE, 30720);

The following code snippet shows how you can set the threshold for the retrieve() method using this approach:

public class CatalogImpl implements CatalogPortType {

     WebServiceContext wsContext;

     public Chapter retrieve(String isbn) {
          wsContext.getMessageContext().put(com.sun.xml.ws.developer.JAXWSProperties.MTOM_THRESHOLOD_VALUE, 30720);

     public boolean upload(Book bookInfo) {


You may also specify the service side threshold value in the 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'>

While the threshold value set in the deployment descriptor applies to all web methods exposed in the corresponding endpoint, using the programmatic approach allows different web methods to have different threshold values.

MTOM Features in JAX-WS 2.1.1 Release
The next version of JAX-WS (2.1.1) standardizes the feature of setting thresholds to enable MTOM only for large-sized data. It also will feature two new annotations (@javax.xml.ws.Feature and @javax.xml.ws.FeatureParameter) for easily configuring MTOM support.

Young Yang, who holds a Ph.D. in mathematics, is a senior enterprise architect at a Wall Street financial company. He is certified by IBM in e-business design, DB2 administration, business intelligence, XML and related technologies, and WebSphere Application Server; by Bea on WebLogic Application Server; and by Sun as an enterprise architect among others.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date