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."
Moderators: Site Manager, fjwalraven
"By doing nothing: if the server WSDL advertises that it supports MTOM, the MTOM support in the client will be automatically enabled."
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;
}
}
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>
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"));
}
}
Hi,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:The WSDL being published is then: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 Client code (without enabling MTOM, but still you will get the image as an attachment)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>
Does this answer your question?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")); } }
Regards,
Frits
Users browsing this forum: No registered users and 1 guest