import java.io.FileOutputStream;
public class MTOMService {
public OMElement mtomSample(OMElement element) throws Exception {
OMElement imageEle = element.getFirstElement();
OMElement imageName = (OMElement) imageEle.getNextOMSibling();
OMText binaryNode = (OMText) imageEle.getFirstOMChild();
String fileName = imageName.getText();
//Extracting the data and saving
DataHandler actualDH;
actualDH = (DataHandler)binaryNode.getDataHandler();
Image actualObject = new ImageIO().loadImage(actualDH.getDataSource()
.getInputStream());
FileOutputStream imageOutStream = new FileOutputStream(fileName);
new ImageIO().saveImage("image/jpeg", actualObject, imageOutStream);
//setting response
OMFactory fac = OMAbstractFactory.getOMFactory();
OMNamespace ns = fac.createOMNamespace("urn://fakenamespace", "ns");
OMElement ele = fac.createOMElement("response", ns);
ele.setText("Image Saved");
return ele;
}