WSO2Con 2013 CFP Banner

More Control Over MIME Attachments with Axis2

Archived Content
This article is provided for historical perspective only, and may not reflect current conditions. Please refer to relevant product page for more up-to-date product information and resources.
Discuss this article on Stack Overflow
  • 15 Feb, 2007
  • Level: 
  • Reads: 8547
Apache Axis2/Java supports sending binary attachments over MIME using both SOAP Message Transmission Optimization Mechanism (MTOM) and SOAP with Attachments (SwA). This KB discusses the advanced attachment configuration options available with Apache Axis2 when sending attachments using MIME packages.

Users should note that the following configurations are optional, and should be used only when the users need more control over the attachments. Basic attachment configuration options needed to send and receive MTOM/SwA messages were discussed in the earlier KB item. Apache Axis2 provides the users with the ability to specify a custom MIME boundary for the outgoing messages. This can be specified either through the MessageContext or through the client side Options object. E.g. messageContext.setProperty( Constants.Configuration.MIME_BOUNDARY, "Axis2_MIME_Boundary"); options.setProperty (Constants.Configuration.MIME_BOUNDARY, "Axis2_MIME_Boundary"); There can be situations where users need to specify a transfer encoding and a custom content-type for the attachments they send as MIME parts, as some service endpoints have enforced restrictions about the transfer-encodings they support. AXIOM (AXis Object Model) has a special javax.activation.DataHandler wrapper called ConfigurableDataHandler to allow the user to set custom values for the content-type and the content-transfer-encoding. Usage of the ConfigurableDataHandler is similar to the javax.activation.DataHandler except for the setting of the following properties. When content-transfer-encoding for an attachment is not configured, Axis2 uses "binary" by default. When content-type is not configured, Axis2 uses the content-type of the underlying data source. E.g. ConfigurableDataHandler dataHandler = new ConfigurableDataHandler(new ByteArrayDataSource(byteArray)); // content of the MIME part containing the // attachment will be encoded using "base64" encoding dataHandler.setTransferEncoding("base64"); // content of the MIME part containing the attachment // will be encoded using "quoted-printable" encoding //dataHandler.setTransferEncoding("quoted-printable"); dataHandler.setContentType("image/gif"); Applies To: Apache Axis2/Java, post 1.1.1 versions Apache Axiom/Java, post 1.2.2 versions More Information: MTOM: SwA: