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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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:
Post a Comment