001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.swa;
019:
020: import java.awt.Image;
021: import java.io.IOException;
022: import java.io.InputStream;
023:
024: import javax.activation.DataHandler;
025: import javax.jws.WebService;
026: import javax.mail.util.ByteArrayDataSource;
027: import javax.xml.transform.Source;
028: import javax.xml.ws.Holder;
029: import javax.xml.ws.WebServiceException;
030:
031: import org.apache.cxf.swa.SwAServiceInterface;
032: import org.apache.cxf.swa.types.DataStruct;
033: import org.apache.cxf.swa.types.OutputResponseAll;
034: import org.apache.cxf.swa.types.VoidRequest;
035:
036: @WebService(endpointInterface="org.apache.cxf.swa.SwAServiceInterface",serviceName="SwAService",targetNamespace="http://cxf.apache.org/swa",portName="SwAServiceHttpPort")
037: public class SwAServiceImpl implements SwAServiceInterface {
038:
039: public void echoDataRef(Holder<DataStruct> data) {
040: try {
041: InputStream bis = null;
042: bis = data.value.getDataRef().getDataSource()
043: .getInputStream();
044: byte b[] = new byte[6];
045: bis.read(b, 0, 6);
046: String string = new String(b);
047:
048: ByteArrayDataSource source = new ByteArrayDataSource(
049: ("test" + string).getBytes(),
050: "application/octet-stream");
051: data.value.setDataRef(new DataHandler(source));
052: } catch (IOException e) {
053: e.printStackTrace();
054: }
055: }
056:
057: public void echoData(Holder<String> text, Holder<DataHandler> data) {
058:
059: try {
060: InputStream bis = null;
061: bis = data.value.getDataSource().getInputStream();
062: byte b[] = new byte[6];
063: bis.read(b, 0, 6);
064: String string = new String(b);
065:
066: ByteArrayDataSource source = new ByteArrayDataSource(
067: ("test" + string).getBytes(),
068: "application/octet-stream");
069: data.value = new DataHandler(source);
070: } catch (IOException e) {
071: e.printStackTrace();
072: }
073: }
074:
075: public void echoDataWithHeader(Holder<String> text,
076: Holder<DataHandler> data, Holder<String> headerText) {
077: try {
078: InputStream bis = null;
079: bis = data.value.getDataSource().getInputStream();
080: byte b[] = new byte[6];
081: bis.read(b, 0, 6);
082: String string = new String(b);
083:
084: ByteArrayDataSource source = new ByteArrayDataSource(
085: ("test" + string).getBytes(),
086: "application/octet-stream");
087: data.value = new DataHandler(source);
088: } catch (IOException e) {
089: e.printStackTrace();
090: }
091: }
092:
093: public OutputResponseAll echoAllAttachmentTypes(
094: VoidRequest request, Holder<DataHandler> attach1,
095: Holder<DataHandler> attach2, Holder<Source> attach3,
096: Holder<Image> attach4, Holder<Image> attach5) {
097: try {
098: System.out.println("Enter echoAllAttachmentTypes() ......");
099: OutputResponseAll theResponse = new OutputResponseAll();
100: theResponse.setResult("ok");
101: theResponse.setReason("ok");
102: if (attach1 == null || attach1.value == null) {
103: System.err
104: .println("attach1.value is null (unexpected)");
105: theResponse
106: .setReason("attach1.value is null (unexpected)");
107: theResponse.setResult("not ok");
108: }
109: if (attach2 == null || attach2.value == null) {
110: System.err
111: .println("attach2.value is null (unexpected)");
112: if (theResponse.getReason().equals("ok")) {
113: theResponse
114: .setReason("attach2.value is null (unexpected)");
115: } else {
116: theResponse.setReason(theResponse.getReason()
117: + "\nattach2.value is null (unexpected)");
118: }
119: theResponse.setResult("not ok");
120: }
121: if (attach3 == null || attach3.value == null) {
122: System.err
123: .println("attach3.value is null (unexpected)");
124: if (theResponse.getReason().equals("ok")) {
125: theResponse
126: .setReason("attach3.value is null (unexpected)");
127: } else {
128: theResponse.setReason(theResponse.getReason()
129: + "\nattach3.value is null (unexpected)");
130: }
131: theResponse.setResult("not ok");
132: }
133: if (attach4 == null || attach4.value == null) {
134: System.err
135: .println("attach4.value is null (unexpected)");
136: if (theResponse.getReason().equals("ok")) {
137: theResponse
138: .setReason("attach4.value is null (unexpected)");
139: } else {
140: theResponse.setReason(theResponse.getReason()
141: + "\nattach4.value is null (unexpected)");
142: }
143: theResponse.setResult("not ok");
144: }
145: if (attach5 == null || attach5.value == null) {
146: System.err
147: .println("attach5.value is null (unexpected)");
148: if (theResponse.getReason().equals("ok")) {
149: theResponse
150: .setReason("attach5.value is null (unexpected)");
151: } else {
152: theResponse.setReason(theResponse.getReason()
153: + "\nattach5.value is null (unexpected)");
154: }
155: theResponse.setResult("not ok");
156: }
157: System.out.println("Leave echoAllAttachmentTypes() ......");
158: return theResponse;
159: } catch (Exception e) {
160: throw new WebServiceException(e.getMessage());
161: }
162: }
163: }
|