aspose file tools*
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Question on MTOM - The image is returned inline instead of an attachment. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Question on MTOM - The image is returned inline instead of an attachment." Watch "Question on MTOM - The image is returned inline instead of an attachment." New topic
Author

Question on MTOM - The image is returned inline instead of an attachment.

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Hello All,

I'm working on the example quoted in Ivan's notes (Section 10.3, MessageOptimization), the ImageManager example. I coded the webservice as below



My environment is Glassfish v 3.0 and I deployed and ran the service and I can successfully access the WSDL and snippet is below



First of all, I see "wsp:Optional = "true". What does this mean? I thought, this attribute being false, does not mandate MTOM. Is this right?

secondly, in the xsd



I was expecting to see encodedContentType attribute. First of all do I see this here or should I be expecting this at some other location or not at all.

Thirdly, when I tested my service using SOAPUI, I see

SOAP Request


SOAP Response


The return is really huge, so I removed most of the data.

In SOAPUi, I have observed few things which may be irrelevant to my question, but just for information purpose. Under Request properties of getImage() request, I see following options as false.

Enable MTOM, Force MTOM, InlineResponseAttach, ExpandMTOMAttachment, EncodeAttachments.

Coming to the question, I was expecting the response to be a part of attachment as the image "Sample.bmp" is bigger than threshold. But I see the result to be inline in the SOAP Response.

Can you advise me what mistake I'm doing here and also any thoughts on SOAPUi Request properties

Regards
KumarRaja

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Merry Christmas to All.

I know people might be busy in Christmas celebrations, but anytime if you get a chance, could you please look into my post and guide me.
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
To reply your first question, as quoted from the ws-policy specification optional-policy optional means

A policy assertion is marked as optional using the wsp:Optional attribute. Optional assertions represent the capabilities of the service provider as opposed to the requirements of the service provider.


To answer your second question about encodedContentType (it should be expectedContentTypes instead) attribute you should add annotation @XmlMimeType("image/gif") to the instance variable of the JAXB class. this will cause to generate expectedContentTypes="image/gif" in the respective element.
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
Sorry forgot to answer your original question I am using soapUI 3.5 you just right click and click insert file as Base64 and you must enable and force using MTOM in the request properties.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Hany Shafik wrote:To reply your first question, as quoted from the ws-policy specification optional-policy optional means

A policy assertion is marked as optional using the wsp:Optional attribute. Optional assertions represent the capabilities of the service provider as opposed to the requirements of the service provider.


To answer your second question about encodedContentType (it should be expectedContentTypes instead) attribute you should add annotation @XmlMimeType("image/gif") to the instance variable of the JAXB class. this will cause to generate expectedContentTypes="image/gif" in the respective element.


Thanks Hany. In order to see the expectedContentTypes in generated xsd, you mentioned that we need to add @XmlMimeType annotation to the JAXB class. I'm currently following the Java first approach. So after the generation of WSDL and XSD through wsgen, I'm using wsimport to generate the client side artifacts and JAXB binding classes.

so where do I add this annotation on SEI implementation class, so that in the generated XSD I can see expectedContentTypes. I tried something like




But I do not see any difference in xsd generated from what it was when @XmlMimeType was not used. Probably I did not use this annotation appropriately.
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
May be you got me wrong, What I meant is the JAXB annotated class and not the SEI. please see below an example that can help you



in your case you will annotate the image instance variable inside the GetImageResponse JAXB generated class
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Thanks Hany,

I tried to change my code as follows but getting an exception while generating WSDL using wsgen.





build.xml


Exception


I knew that I'm doing a terrible mistake here, but could not locate what it is.

Also, from Ivan's notes (the example is taken from Ivan's notes), there are no instructions to annotate a domain object with @XmlType...

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Hany Shafik wrote:Sorry forgot to answer your original question I am using soapUI 3.5 you just right click and click insert file as Base64 and you must enable and force using MTOM in the request properties.

Sorry, have been busy over the holidays, so I didn't see this thread until today.
Yes, Hany is right - the Enable MTOM and Force MTOM properties in soapUI must be set to true. This has been described in a more recent version of the study notes. Please make sure you have the lates version Kumar!

I see that you have modified the code - it is different than the example in my study notes.
While it is an excellent exercise, I am more limited in answering questions in connection to such endeavors since I have not tried the program myself.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
Hi Kumar,

You should add the annotation @XmlAccessorType(XmlAccessType.FIELD) to your class (or remove the getter method), as by default jaxb will try to bind both field and getter method to the same element name, that is why this exception is raised.

Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Thanks Hany. Your suggestion worked.

But, this time I was trying an example quoted in Ivan's notes. The class is defined as below



The above class is same as whats given in the notes, except that I removed an operation and kept the example much simple. I ran wsgen and generated the WSDL and XSD.

The WSDL is as below



As seen above, there is no MTOM policy generated in the WSDL. However, after deployment if I browse for the wsdl "http://localhost:8080/ImageManager/ImgManagerService?wsdl" I see the MTOM policy



Am I doing any mistake here ?

In the notes, Ivan advised to look at the WSDL to see if MTOM is enabled or not, but not sure, if he meant to check this in the wsgen generated WSDL or through browser.
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
Hi Kumar,

I assume this is because the jax-ws wsgen you used to generate the wsdl is of different version than the one used in glassfish.
Please try wsgen -v to print the jax-ws version for both the wsgen tool you used and go inside the glassfish bin directory and try wsgen -v.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Hany,

I'm using the wsgen that is a part of JDK1.6. So when I ran -version on wsgen, I got "JAX-WS RI 2.1.6 in JDK 6". Do I need to use any other version ?
Hany Shafik
Ranch Hand

Joined: Jun 21, 2008
Posts: 80
Glassfish v3 implements jax-ws 2.2. As I told you before please try wsgen -v for the one that resides inside glassfish bin directory.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Thanks Hany,

I used the wsgen that shipped along with glassfish and I see the wsdl with the policy element. By the way, -version I see here is "JAX-WS RI 2.2.1-hudson-28-"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on MTOM - The image is returned inline instead of an attachment.