// shall I write some keywords here to boost search engine ranking?

Saturday, October 05, 2013

Set Transfer Encoding of Attachment for Axis2

When sending SOAP request with attachment, Axis2 handle the attachment via Axiom, and the default transfer encoding for binary file are binary.

In order to change the transfer encoding to something else, we will utilize the org.apache.axiom.attachments.ConfigurableDataHandler instead of the usual javax.activation.DataHandler.

Below is the sample code:

//
// import these:
//
// import org.apache.axiom.attachments.Attachments;
// import org.apache.axiom.attachments.ConfigurableDataHandler;
// import javax.activation.FileDataSource
Attachments attachments = new Attachments();
ConfigurableDataHandler dh = new ConfigurableDataHandler(new FileDataSource("testing.gif")); // file path
dh.setContentType("image/gif");
dh.setTransferEncoding("base64");
attachments.addDataHandler("testing.gif", dh); // just file name

No comments: