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.provider.sourcemsg;
20:
21: import org.apache.axis2.jaxws.TestLogger;
22:
23: import java.io.ByteArrayInputStream;
24: import java.io.InputStream;
25: import java.io.StringWriter;
26:
27: import javax.xml.transform.Result;
28: import javax.xml.transform.Source;
29: import javax.xml.transform.Transformer;
30: import javax.xml.transform.TransformerFactory;
31: import javax.xml.transform.stream.StreamResult;
32: import javax.xml.transform.stream.StreamSource;
33: import javax.xml.ws.Provider;
34: import javax.xml.ws.Service;
35: import javax.xml.ws.ServiceMode;
36: import javax.xml.ws.WebServiceProvider;
37:
38: @WebServiceProvider()
39: @ServiceMode(value=Service.Mode.MESSAGE)
40: public class SourceMessageProvider implements Provider<Source> {
41: String responseAsString = new String(
42: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header/><soapenv:Body><ns2:ReturnType xmlns:ns2=\"http://test\"><return_str>some response</return_str></ns2:ReturnType></soapenv:Body></soapenv:Envelope>");
43:
44: public Source invoke(Source source) {
45: TestLogger.logger
46: .debug(">> SourceMessageProvider: Request received.");
47: //System.out.println(">> Source toString: \n"+source.toString());
48:
49: try {
50: StringWriter writer = new StringWriter();
51: Transformer t = TransformerFactory.newInstance()
52: .newTransformer();
53: Result result = new StreamResult(writer);
54: t.transform(source, result);
55: TestLogger.logger.debug(">> Source Request on Server: \n"
56: + writer.getBuffer().toString());
57:
58: byte[] bytes = responseAsString.getBytes();
59: ByteArrayInputStream stream = new ByteArrayInputStream(
60: bytes);
61: Source srcStream = new StreamSource((InputStream) stream);
62: return srcStream;
63: } catch (Exception e) {
64: e.printStackTrace();
65: }
66: return null;
67: }
68:
69: }
|