wood burning stoves
The moose likes Web Services and the fly likes JAX-WS MTOM is not workink as expected. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "JAX-WS MTOM is not workink as expected." Watch "JAX-WS MTOM is not workink as expected." New topic

JAX-WS MTOM is not workink as expected.

Sagar Lakade

Joined: Apr 08, 2010
Posts: 3
Here is my test code

import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.jws.WebService;
import javax.xml.ws.BindingType;
import javax.xml.ws.soap.MTOM;

* @author sagar.lakade
@MTOM(threshold = 1, enabled = true )
public class AttachService {

public DataHandler getFile(String id) {
FileDataSource fileSource = new FileDataSource("C:\\realtek.log");
return new DataHandler(fileSource);

response of web service I got In SOAPUI
HTTP/1.1 200 OK
X-Powered-By: Servlet/2.5
Server: GlassFish/v3
Content-Type: multipart/related;start="<rootpart*677e28d1-4ba9-4edb-a7ed-7deab5867df0@example.jaxws.sun.com>";type="application/xop+xml";boundary="uuid:677e28d1-4ba9-4edb-a7ed-7deab5867df0";start-info="text/xml"
Transfer-Encoding: chunked
Date: Thu, 08 Apr 2010 13:00:39 GMT

Content-Id: <rootpart*677e28d1-4ba9-4edb-a7ed-7deab5867df0@example.jaxws.sun.com>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getFileResponse xmlns:ns2="http://srvc/"><return>W0luc3RhbGxTaGllbGQgU2lsZW50XQ0KVmVyc2lvbj12Ny4wMA0KRmlsZT1Mb2cgRmlsZQ0KW1Jlc3BvbnNlUmVzdWx0XQ0KUmVzdWx0Q29kZT0wDQpbQXBwbGljYXRpb25dDQpOYW1lPVJlYWx0ZWsgSGlnaCBEZWZpbml0aW9uIEF1ZGlvIERyaXZlcg0KVmVyc2lvbj0yLjMzDQpDb21wYW55PVJlYWx0ZWsgU2VtaWNvbmR1Y3RvciBDb3JwLg0KTGFuZz0wMDA5DQo=</return></ns2:getFileResponse></S:Body></S:Envelope>

from above response , we can see that response is inline and not as attachment.
What should be the changes in service provider class so that I get desired result.

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183

Apparently you need to decrease the value of @MTOM threshold to 0.

Enabling MTOM for JAX-WS Web services says -
The threshold parameter has an integer value, and it specifies the minimum size for messages that are sent using MTOM. When the message size is less than this specified integer, the message is inlined in the XML document as base64 or hexBinary data.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Sagar Lakade

Joined: Apr 08, 2010
Posts: 3
Hi Dan,

Thanks you for the response. I have made the changes - @MTOM( threshold = 0, enabled = true ) in service provider class.
But still not getting desired result.

I have searched for this issue on net, some of the these blogs say that it is related to MTOM and jdk1.6 . They also suggest to copy webserservice related jar files to endorsed directory .

I am using following version of netbeans :

Product Version: NetBeans IDE 6.7.1 (Build 200911211148)
Java: 1.6.0_07; Java HotSpot(TM) Client VM 10.0-b23
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Userdir: C:\Documents and Settings\sagar.lakade\.netbeans\6.7

Is it the real cause in may case? I will try this code with jdk 1.5 and post my findings.

Please comment.


Sagar Lakade

Joined: Apr 08, 2010
Posts: 3
Even with following combination not getting desired result

Product Version: NetBeans IDE 6.7.1 (Build 200907230233)
Java: 1.5.0_08; Java HotSpot(TM) Client VM 1.5.0_08-b03
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Userdir: C:\Documents and Settings\Administrator\.netbeans\6.7
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
I don't know if it is of interest to you, but I have written a tutorial on developing a SOAP web service with MTOM.
You can find it on page 361 in this document: http://www.slideshare.net/krizsan/scdjws-5-study-notes-3085287
If you choose to work through the tutorial and there are problems, please let me know!
Best wishes!
Binu George

Joined: May 20, 2013
Posts: 2
If an attachment is smaller than the size specified in threshold parameter, the runtime will inline the binary data as base64 binary instead of creating an attachment.
Check your threshold configuration and size of attachment. May be helpful. JAX-WS Attachment – Enable MTOM for JAX-WS Web services

Binu George
Enterprise Java Technology Blog
I agree. Here's the link: http://aspose.com/file-tools
subject: JAX-WS MTOM is not workink as expected.
It's not a secret anymore!