|
Page Created :
CXF20DOC :
MTOM Attachments
MTOM Attachments has been created by Dan Diephouse (Apr 17, 2007). Content:MTOM is a standard which allows your services to transfer binary data efficiently and conveniently. Many frameworks have support for MTOM - Axis2, JAX-WS RI, JBoss WS, XFire, and more. If the binary is part of the XML document, it needs to be base64 encoded - taking CPU time and increasing the payload size. When MTOM is enabled on a service, it takes binary data which might normally be part of the XML document, and creates an attachment for it. Enabling MTOM is a rather simple process. First, you must annotate your schema type or POJO to let JAXB know that a particular field could be a candidate for MTOM optimization. Second, you just tell CXF that you wish to enable MTOM. 1a) Modifying your schema for MTOMLets say we have a Picture schema type like this: <schema targetNamespace="http://pictures.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <element name="Picture"> <complexType> <sequence> <element name="Title" type="xsd:string"/> <element name="ImageData" type="xsd:base64Binary"/> </sequence> </complexType> </element> </schema> In this case the ImageData element is something we would like to have transferred as an attachment. To do this we just need to add an xmime:expectedContentTypes annotation: <schema targetNamespace="http://pictures.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xmime="http://www.w3.org/2005/05/xmlmime"> <element name="Picture"> <complexType> <sequence> <element name="Title" type="xsd:string"/> <element name="ImageData" type="xsd:base64Binary" xmime:expectedContentTypes="application/octet-stream"/> </sequence> </complexType> </element> </schema> This tells JAXB (which WSDL2Java uses to generate POJOs for your service) that this field could be of any content type. Instead of creating a byte[] array for the base64Binary element, it will not create a DataHandler instead which can be used to stream the data.
|
Unsubscribe or edit your notifications preferences
