private static final int BUFFER = 2048;
public OMElement uploadFileUsingMTOM(OMElement request) throws Exception {
OMText binaryNode = (OMText) request.
getFirstChildWithName(new QName("http://services.samples", "request")).
getFirstChildWithName(new QName("http://services.samples", "image")).
getFirstOMChild();
DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler();
InputStream is = dataHandler.getInputStream();
File tempFile = File.createTempFile("mtom-", ".gif");
FileOutputStream fos = new FileOutputStream(tempFile);
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
byte data[] = new byte[BUFFER];
int count;
while ((count = is.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
System.out.println("Wrote MTOM content to temp file : " + tempFile.getAbsolutePath());
OMFactory factory = request.getOMFactory();
OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
OMElement payload = factory.createOMElement("uploadFileUsingMTOMResponse", ns);
OMElement response = factory.createOMElement("response", ns);
OMElement image = factory.createOMElement("image", ns);
FileDataSource fileDataSource = new FileDataSource(tempFile);
dataHandler = new DataHandler(fileDataSource);
OMText textData = factory.createOMText(dataHandler, true);
image.addChild(textData);
response.addChild(image);
payload.addChild(response);
MessageContext outMsgCtx = MessageContext.getCurrentMessageContext()