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:
@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:
<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:
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