About Question enthuware.ocejws.v6.2.154 :

Moderators: Site Manager, fjwalraven

Post Reply
Igor Makarov
Posts: 14
Joined: Tue Sep 08, 2015 3:27 am
Contact:

About Question enthuware.ocejws.v6.2.154 :

Post by Igor Makarov » Wed Jul 20, 2016 5:02 am

Hi.

Could you please explain this option, I couldn't find any references in the internet
"By doing nothing:  if the server WSDL advertises that it supports MTOM, the MTOM support in the client will be automatically enabled."

fjwalraven
Posts: 419
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.ocejws.v6.2.154 :

Post by fjwalraven » Thu Jul 21, 2016 2:08 pm

Hi Igor,

This is implicit. JAX-WS v2.x says: "Enabling this feature on either the server or client will result the JAX-WS runtime using MTOM and for binary data being sent as an attachment."

If the WSDL does have a ws-policy assertion stating that MTOM is enabled, the related WebService has an MTOM annotation. The client in that case does not have to explicitly enable MTOM again.

The following code example will hopefully help you understand. Let's say we have this WebService on the server-side:

Code: Select all

@MTOM
public class GifServiceImpl implements GifService {
	@Override
	public Image getGifImage(String name) {
		BufferedImage img = null;
		try {
			System.out.println("getting image: " + name);
			img = ImageIO.read(new File(name));
		} catch (IOException e) {
			System.out.println("image not found");
		}
		return img;
	}
}
The WSDL being published is then:

Code: Select all

<definitions ... left out ...>
<wsp:Policy wsu:Id="GifServiceImplPortBinding_MTOM_Policy-GifServiceImplPortBinding_MTOM_Policy">
   <ns1:OptimizedMimeSerialization xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" wsp:Optional="true"/>
</wsp:Policy>
 ... left out ...
</portType>
<binding name="GifServiceImplPortBinding" type="tns:GifService">
  <wsp:PolicyReference URI="#GifServiceImplPortBinding_MTOM_Policy-GifServiceImplPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
 <operation name="getGifImage">
  <soap:operation soapAction=""/>
     <input>
        <soap:body use="literal"/>
     </input>
     <output>
        <soap:body use="literal"/>
      </output>
  </operation>
</binding>
  ... left out ...
</definitions>
The Client code (without enabling MTOM, but still you will get the image as an attachment)

Code: Select all

public class GifServiceClient {
	public static void main(String[] args) throws IOException {
		GifServiceImplService service = new GifServiceImplService();
		GifService port = service.getPort(GifService.class);
		Image gifImage = port.getGifImage("rssLogo.gif");
		ImageIO.write((RenderedImage) gifImage, "gif", new File("receivedLogo.gif"));
	}
}
Does this answer your question?

Regards,
Frits

Igor Makarov
Posts: 14
Joined: Tue Sep 08, 2015 3:27 am
Contact:

Re: About Question enthuware.ocejws.v6.2.154 :

Post by Igor Makarov » Sat Jul 23, 2016 2:46 am

Thank you.

victor2016
Posts: 12
Joined: Wed Jan 20, 2016 7:16 pm
Contact:

Re: About Question enthuware.ocejws.v6.2.154 :

Post by victor2016 » Mon Jan 02, 2017 1:26 pm

fjwalraven wrote:Hi Igor,

This is implicit. JAX-WS v2.x says: "Enabling this feature on either the server or client will result the JAX-WS runtime using MTOM and for binary data being sent as an attachment."

If the WSDL does have a ws-policy assertion stating that MTOM is enabled, the related WebService has an MTOM annotation. The client in that case does not have to explicitly enable MTOM again.

The following code example will hopefully help you understand. Let's say we have this WebService on the server-side:

Code: Select all

@MTOM
public class GifServiceImpl implements GifService {
	@Override
	public Image getGifImage(String name) {
		BufferedImage img = null;
		try {
			System.out.println("getting image: " + name);
			img = ImageIO.read(new File(name));
		} catch (IOException e) {
			System.out.println("image not found");
		}
		return img;
	}
}
The WSDL being published is then:

Code: Select all

<definitions ... left out ...>
<wsp:Policy wsu:Id="GifServiceImplPortBinding_MTOM_Policy-GifServiceImplPortBinding_MTOM_Policy">
   <ns1:OptimizedMimeSerialization xmlns:ns1="http://schemas.xmlsoap.org/ws/2004/09/policy/optimizedmimeserialization" wsp:Optional="true"/>
</wsp:Policy>
 ... left out ...
</portType>
<binding name="GifServiceImplPortBinding" type="tns:GifService">
  <wsp:PolicyReference URI="#GifServiceImplPortBinding_MTOM_Policy-GifServiceImplPortBinding_MTOM_Policy"/>
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
 <operation name="getGifImage">
  <soap:operation soapAction=""/>
     <input>
        <soap:body use="literal"/>
     </input>
     <output>
        <soap:body use="literal"/>
      </output>
  </operation>
</binding>
  ... left out ...
</definitions>
The Client code (without enabling MTOM, but still you will get the image as an attachment)

Code: Select all

public class GifServiceClient {
	public static void main(String[] args) throws IOException {
		GifServiceImplService service = new GifServiceImplService();
		GifService port = service.getPort(GifService.class);
		Image gifImage = port.getGifImage("rssLogo.gif");
		ImageIO.write((RenderedImage) gifImage, "gif", new File("receivedLogo.gif"));
	}
}
Does this answer your question?

Regards,
Frits
Hi,

I'm a bit confused here, why is client able to consume Image type directly from web service? Isn't it returned as byte[] unless web service (SEI) uses @XmlMimeType annotation or adds xmime:expectedContentType in XSD as per question (enthuware.ocejws.v6.2.130) Am I missing something?

Thanks,
Victor.

fjwalraven
Posts: 419
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.ocejws.v6.2.154 :

Post by fjwalraven » Mon Jan 02, 2017 2:15 pm

Hi Victor,

With the MTOM Feature the binary data is sent in it's original form as an attachment. There is no base64 encoding/decoding taking place.

Regards,
Frits

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests