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