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:
22: import javax.xml.namespace.QName;
23: import javax.xml.soap.MessageFactory;
24: import javax.xml.soap.SOAPBody;
25: import javax.xml.soap.SOAPMessage;
26: import javax.xml.transform.sax.SAXSource;
27: import javax.xml.ws.Provider;
28: import javax.xml.ws.Service;
29: import javax.xml.ws.ServiceMode;
30: import javax.xml.ws.WebServiceProvider;
31:
32: import org.w3c.dom.Node;
33:
34: import org.xml.sax.InputSource;
35:
36: //The following wsdl file is used.
37: //wsdlLocation = "/trunk/testutils/src/main/resources/wsdl/hello_world_rpc_lit.wsdl"
38: @WebServiceProvider(portName="SoapPortProviderRPCLit4",serviceName="SOAPServiceProviderRPCLit",targetNamespace="http://apache.org/hello_world_rpclit",wsdlLocation="/wsdl/hello_world_rpc_lit.wsdl")
39: @ServiceMode(value=Service.Mode.MESSAGE)
40: public class HWSAXSourceMessageProvider implements Provider<SAXSource> {
41:
42: private static QName sayHi = new QName(
43: "http://apache.org/hello_world_rpclit", "sayHi");
44: private static QName greetMe = new QName(
45: "http://apache.org/hello_world_rpclit", "greetMe");
46: private InputSource sayHiInputSource;
47: private InputSource greetMeInputSource;
48: private MessageFactory factory;
49:
50: public HWSAXSourceMessageProvider() {
51:
52: try {
53: factory = MessageFactory.newInstance();
54: InputStream is1 = getClass().getResourceAsStream(
55: "resources/sayHiRpcLiteralResp.xml");
56: sayHiInputSource = new InputSource(is1);
57:
58: InputStream is2 = getClass().getResourceAsStream(
59: "resources/GreetMeRpcLiteralResp.xml");
60: greetMeInputSource = new InputSource(is2);
61:
62: } catch (Exception ex) {
63: ex.printStackTrace();
64: }
65: }
66:
67: public SAXSource invoke(SAXSource request) {
68: SAXSource response = new SAXSource();
69: try {
70: SOAPMessage msg = factory.createMessage();
71: msg.getSOAPPart().setContent(request);
72: SOAPBody body = msg.getSOAPBody();
73: Node n = body.getFirstChild();
74:
75: while (n.getNodeType() != Node.ELEMENT_NODE) {
76: n = n.getNextSibling();
77: }
78: if (n.getLocalName().equals(sayHi.getLocalPart())) {
79: response.setInputSource(sayHiInputSource);
80: } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
81: response.setInputSource(greetMeInputSource);
82: }
83: } catch (Exception ex) {
84: ex.printStackTrace();
85: }
86: return response;
87: }
88:
89: }
|