Codehaus XFire
DocumentationQuicklinksDevelopers
Sponsors |
MTOM is a way to handle large amounts of binary data in your services. Unlike attachments, the XML infoset stays the same. MTOM just "optimizes" any base64Binary data you have in your messages. When MTOM is turned on, this base64 data gets sent as a binary attachment saving time and space. Turning on MTOM is easy. You can do it via the API: service.setProperty("mtom-enabled", "true"); Or via services.xml: <service> ... normal service definition <properties> <property key="mtom-enabled">true</property> </properties> </service> You also need to set the mtom-enabled property on your client: MyService myClient = ...; Client client = Client.getInstance(myClient); client.setProperty("mtom-enabled", "true"); MTOM and the Aegis BindingThe Aegis (aka POJO) binding has support for optimization of the following classes:
MTOM and JAXB 2.0Any base64Binary type in a schema is a candidate for optimization with JAXB. You can also specify the expected mime content type: <s:element name="GetPictureResponse"> <s:complexType> <s:sequence> <s:element name="image" type="s:base64Binary" xmime:expectedContentTypes="image/jpeg"/> </s:sequence> </s:complexType> </s:element> JAXB is then smart enough to use an Image instead of a byte array. Cleaning up attachments (IMPORTANT!)In XFire 1.2.3+In XFire 1.2.3 we automatically delete attachments for you. If you wish to not have the attachment deleted, and the attachment was saved to disk, you'll want to do something like this: DataHandler handler = ... // the datahandler or data source from your attachment InputStream is = handler.getInputStream(); // A DeleteOnCloseFileInputStream is only used if the attachment was saved to disk if (is instanceof DeleteOnCloseFileInputStream) { // tell XFire not to delete the file ((DeleteOnCloseFileInputStream) is).setDelete(false); } AttachmentDataSource attSource = (AttachmentDataSource) handler.getDataSource(); File file = attSource.getFile(); // do something with the file... In XFire 1.2.2 and beforeAfter you're done with your attachment, you'll probably want to delete it if it was saved to disk. The default threshold for saving an attachment to disk is about 100K. You only need to do this if it is a DataHandler or DataSource. import org.codehaus.xfire.attachments.AttachmentDataSource; // if you specified a DataHandler DataHandler handler = ...; AttachmentDataSource attSource = (AttachmentDataSource) handler.getDataSource(); // or if you specified a DataSource DataSource source = ...; AttachmentDataSource attSource = (AttachmentDataSource) source; // Delete the file if there is one File attFile = attSource.getFile(); if (attFile != null) attFile.delete(); Configuring attachmentsThere are two parameters you can tweak to configure how attachments work: These can be set on both the service and the client: Service service = ...; service.setProperty(StreamedAttachments.ATTACHMENT_DIRECTORY, new File("/some/directory")); service.setProperty(StreamedAttachments.ATTACHMENT_MEMORY_THRESHOLD, new Integer(10000000)); |