• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Kumar Raja
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Hany Shafik
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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-"
 
reply
    Bookmark Topic Watch Topic
  • New Topic