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: */package org.apache.cxf.systest.provider;
19:
20: import java.io.InputStream;
21: import java.io.StringWriter;
22: import java.io.Writer;
23:
24: import javax.jws.HandlerChain;
25: import javax.xml.transform.OutputKeys;
26: import javax.xml.transform.Source;
27: import javax.xml.transform.Transformer;
28: import javax.xml.transform.TransformerFactory;
29: import javax.xml.transform.stream.StreamResult;
30: import javax.xml.transform.stream.StreamSource;
31: import javax.xml.ws.Provider;
32: import javax.xml.ws.ServiceMode;
33: import javax.xml.ws.WebServiceProvider;
34:
35: //The following wsdl file is used.
36: //wsdlLocation = "/trunk/testutils/src/main/resources/wsdl/hello_world_rpc_lit.wsdl"
37: @WebServiceProvider(portName="SoapPortProviderRPCLit3",serviceName="SOAPServiceProviderRPCLit",targetNamespace="http://apache.org/hello_world_rpclit",wsdlLocation="/wsdl/hello_world_rpc_lit.wsdl")
38: @ServiceMode(value=javax.xml.ws.Service.Mode.PAYLOAD)
39: @HandlerChain(file="./handlers_invocation.xml",name="TestHandlerChain")
40: public class HWSourcePayloadProvider implements Provider<Source> {
41:
42: public HWSourcePayloadProvider() {
43:
44: }
45:
46: public Source invoke(Source request) {
47: try {
48: String input = getSourceAsString(request);
49: System.out.println(input);
50:
51: if (input.indexOf("ServerLogicalHandler") >= 0) {
52: StreamSource source = new StreamSource();
53:
54: InputStream greetMeInputStream = getClass()
55: .getResourceAsStream(
56: "resources/GreetMeRpcLiteralRespBody.xml");
57:
58: source.setInputStream(greetMeInputStream);
59: return source;
60: }
61:
62: } catch (Exception e) {
63: System.out
64: .println("Received an exception while parsing the source");
65: e.printStackTrace();
66: }
67: return null;
68: }
69:
70: public static String getSourceAsString(Source s) throws Exception {
71: Transformer transformer = TransformerFactory.newInstance()
72: .newTransformer();
73: transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
74: "yes");
75: transformer.setOutputProperty(OutputKeys.METHOD, "xml");
76: Writer out = new StringWriter();
77: StreamResult streamResult = new StreamResult();
78: streamResult.setWriter(out);
79: transformer.transform(s, streamResult);
80: return streamResult.getWriter().toString();
81: }
82: }
|