1 16 package sample.mtom; 17 18 import java.awt.Image ; 19 import java.io.FileOutputStream ; 20 21 import javax.activation.DataHandler ; 22 23 import org.apache.axis2.attachments.JDK13IO; 24 import org.apache.axis2.om.OMAbstractFactory; 25 import org.apache.axis2.om.OMElement; 26 import org.apache.axis2.om.OMFactory; 27 import org.apache.axis2.om.OMNamespace; 28 import org.apache.axis2.om.OMText; 29 32 public class MTOMService { 33 public OMElement mtomSample(OMElement element) throws Exception { 34 OMElement imageEle = element.getFirstElement(); 35 OMElement imageName = (OMElement) imageEle.getNextSibling(); 36 OMText binaryNode = (OMText) imageEle.getFirstChild(); 37 String nameNode = imageName.getText(); 38 DataHandler actualDH; 40 actualDH = binaryNode.getDataHandler(); 41 Image actualObject = new JDK13IO().loadImage(actualDH.getDataSource() 42 .getInputStream()); 43 FileOutputStream imageOutStream = new FileOutputStream (nameNode); 44 new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream); 45 46 OMFactory fac = OMAbstractFactory.getOMFactory(); 48 OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns"); 49 OMElement ele = fac.createOMElement("response", ns); 50 ele.setText("Image Saved"); 51 return ele; 52 } 53 } | Popular Tags |