KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > mtom > MTOMService


1 /*
2  * Copyright 2004,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package sample.mtom;
17
18 import java.awt.Image JavaDoc;
19 import java.io.FileOutputStream JavaDoc;
20
21 import javax.activation.DataHandler JavaDoc;
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 /**
30  * @author <a HREF="mailto:thilina@opensource.lk">Thilina Gunarathne </a>
31  */

32 public class MTOMService {
33     public OMElement mtomSample(OMElement element) throws Exception JavaDoc {
34         OMElement imageEle = element.getFirstElement();
35         OMElement imageName = (OMElement) imageEle.getNextSibling();
36         OMText binaryNode = (OMText) imageEle.getFirstChild();
37         String JavaDoc nameNode = imageName.getText();
38         //Extracting the data and saving
39
DataHandler JavaDoc actualDH;
40         actualDH = binaryNode.getDataHandler();
41         Image JavaDoc actualObject = new JDK13IO().loadImage(actualDH.getDataSource()
42                 .getInputStream());
43         FileOutputStream JavaDoc imageOutStream = new FileOutputStream JavaDoc(nameNode);
44         new JDK13IO().saveImage("image/jpeg", actualObject, imageOutStream);
45         
46         //setting response
47
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