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.ws.Provider;
27: import javax.xml.ws.Service;
28: import javax.xml.ws.ServiceMode;
29: import javax.xml.ws.WebServiceProvider;
30:
31: import org.w3c.dom.Node;
32:
33: //The following wsdl file is used.
34: //wsdlLocation = "/trunk/testutils/src/main/resources/wsdl/hello_world.wsdl"
35: @WebServiceProvider(portName="SoapProviderPort",serviceName="SOAPProviderService",targetNamespace="http://apache.org/hello_world_soap_http",wsdlLocation="/wsdl/hello_world.wsdl")
36: @ServiceMode(value=Service.Mode.MESSAGE)
37: public class HWSoapMessageDocProvider implements Provider<SOAPMessage> {
38:
39: private static QName sayHi = new QName(
40: "http://apache.org/hello_world_soap_http", "sayHi");
41: private static QName greetMe = new QName(
42: "http://apache.org/hello_world_soap_http", "greetMe");
43: private SOAPMessage sayHiResponse;
44: private SOAPMessage greetMeResponse;
45:
46: public HWSoapMessageDocProvider() {
47:
48: try {
49: MessageFactory factory = MessageFactory.newInstance();
50: InputStream is = getClass().getResourceAsStream(
51: "resources/sayHiDocLiteralResp.xml");
52: sayHiResponse = factory.createMessage(null, is);
53: is.close();
54: is = getClass().getResourceAsStream(
55: "resources/GreetMeDocLiteralResp.xml");
56: greetMeResponse = factory.createMessage(null, is);
57: is.close();
58: } catch (Exception ex) {
59: ex.printStackTrace();
60: }
61: }
62:
63: public SOAPMessage invoke(SOAPMessage request) {
64: SOAPMessage response = null;
65: try {
66: SOAPBody body = request.getSOAPBody();
67: Node n = body.getFirstChild();
68:
69: while (n.getNodeType() != Node.ELEMENT_NODE) {
70: n = n.getNextSibling();
71: }
72: if (n.getLocalName().equals(sayHi.getLocalPart())) {
73: response = sayHiResponse;
74: } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
75: response = greetMeResponse;
76: }
77: } catch (Exception ex) {
78: ex.printStackTrace();
79: }
80: return response;
81: }
82: }
|