Web Service Passing Binary Data, pt7: Logging and Optimizing the Service
JAX-WS provides an easy and effective way to optimize
binary data transfer. It is known as "message optimization",
provided by the Message Transmission Optimization Mechanism (MTOM).
Message optimization is the process of transmitting web service
messages in the most efficient manner. It is achieved in web
service communication by encoding messages prior to
transmission and then de-encoding them when they reach their
final destination. MTOM uses XOP (XML-binary Optimized
Packaging) to transmit binary data to and from the web service.
The Web Service Designer lets you enable MTOM easily, as shown in this section and
described here.
To be able to verify, later, that MTOM is working correctly, begin by setting up a logging mechanism on the server. This lets you
monitor the request and response messages without changing the client
code. Pass the system property
-Dcom.sun.xml.ws.transport.http.HttpAdapter.dump=true
to the server so that you can monitor the
SOAP messages as well as the HTTP headers that the
web service is receiving and sending from and to the client.
To Log and Optimize the Web Service:
Open the Admin Console, from the server's node
in the Services window, as shown here:
The Admin Console opens in the browser. Enter your
username and password and press Enter.
In the Admin Console, use the JVM Options section,
shown below, to set this property on the server.
While the server starts up,
look in the Output window and make sure you see the property
amongst the other server output,
as shown below.
Redeploy the enterprise application to the Tester application, invoke an operation
via the Tester application, and notice the Output window again,
showing HTTP requests and responses, because of the logging mechanism
that you enabled in the previous steps.
Now that we have HTTP logging working correctly,
we will optimize the message transfer of our images.
Open the web service in the Web Service Visual Designer
and select "Optimize Transfer of Binary Data (MTOM)".
In the Services window, restart the server.
While the server starts up, notice the following in the Output window.
As indicated in the highlighted lines in the Output window,
by using MTOM we ensure that binary data is
not contained within the SOAP body. Instead, it
is sent as a SOAP attachment, while the attachment is
included in the SOAP message.
To send comments and suggestions, get support, and keep informed on the latest
developments on the NetBeans IDE Java EE development features, join
the mailing list.