01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.sample.mtom;
20:
21: import java.awt.Image;
22: import java.io.ByteArrayInputStream;
23:
24: import javax.activation.DataHandler;
25: import javax.activation.DataSource;
26: import javax.imageio.ImageIO;
27: import javax.jws.WebService;
28: import javax.xml.ws.BindingType;
29: import javax.xml.ws.WebServiceException;
30: import javax.xml.ws.soap.SOAPBinding;
31:
32: import org.apache.axis2.jaxws.provider.DataSourceImpl;
33: import org.apache.axis2.jaxws.TestLogger;
34: import org.test.mtom.ImageDepot;
35: import org.test.mtom.ObjectFactory;
36:
37: @WebService(endpointInterface="org.apache.axis2.jaxws.sample.mtom.MtomSample")
38: @BindingType(SOAPBinding.SOAP11HTTP_MTOM_BINDING)
39: public class MtomSampleService implements MtomSample {
40:
41: public ImageDepot sendImage(ImageDepot input) {
42: TestLogger.logger.debug("[new sendImage request received]");
43: DataHandler data = input.getImageData();
44:
45: TestLogger.logger.debug("[contentType] "
46: + data.getContentType());
47: ImageDepot output = (new ObjectFactory()).createImageDepot();
48: Image image = null;
49: try {
50: ByteArrayInputStream stream = (ByteArrayInputStream) data
51: .getContent();
52: image = ImageIO.read(stream);
53:
54: DataSource imageDS = new DataSourceImpl("image/jpeg",
55: "test.jpg", image);
56: DataHandler handler = new DataHandler(imageDS);
57: output.setImageData(handler);
58: } catch (Exception e) {
59: throw new WebServiceException(e);
60: }
61: return output;
62: }
63:
64: public ImageDepot sendText(byte[] input) {
65: TestLogger.logger.debug("[new sendText request received]");
66: return null;
67: }
68:
69: }
|