01: package org.objectweb.celtix.systest.provider;
02:
03: import java.io.InputStream;
04:
05: import javax.xml.namespace.QName;
06: import javax.xml.soap.MessageFactory;
07: import javax.xml.soap.SOAPBody;
08: import javax.xml.soap.SOAPMessage;
09: import javax.xml.ws.Provider;
10: import javax.xml.ws.Service;
11: import javax.xml.ws.ServiceMode;
12: import javax.xml.ws.WebServiceProvider;
13:
14: import org.w3c.dom.Node;
15:
16: //The following wsdl file is used.
17: //wsdlLocation = "C:/CeltixSVN/trunk/celtix-testutils/src/main/resources/wsdl/hello_world_rpc_lit.wsdl"
18: @WebServiceProvider(portName="SoapPortRPCLit",serviceName="SOAPServiceRPCLit",targetNamespace="http://objectweb.org/hello_world_rpclit",wsdlLocation="/wsdl/hello_world_rpc_lit.wsdl")
19: @ServiceMode(value=Service.Mode.MESSAGE)
20: public class HWSoapMessageProvider implements Provider<SOAPMessage> {
21:
22: private static QName sayHi = new QName(
23: "http://objectweb.org/hello_world_rpclit", "sayHi");
24: private static QName greetMe = new QName(
25: "http://objectweb.org/hello_world_rpclit", "greetMe");
26: private SOAPMessage sayHiResponse;
27: private SOAPMessage greetMeResponse;
28:
29: public HWSoapMessageProvider() {
30:
31: try {
32: MessageFactory factory = MessageFactory.newInstance();
33: InputStream is = getClass().getResourceAsStream(
34: "resources/sayHiRpcLiteralResp.xml");
35: sayHiResponse = factory.createMessage(null, is);
36: is.close();
37: is = getClass().getResourceAsStream(
38: "resources/GreetMeRpcLiteralResp.xml");
39: greetMeResponse = factory.createMessage(null, is);
40: is.close();
41: } catch (Exception ex) {
42: ex.printStackTrace();
43: }
44: }
45:
46: public SOAPMessage invoke(SOAPMessage request) {
47: SOAPMessage response = null;
48: try {
49: SOAPBody body = request.getSOAPBody();
50: Node n = body.getFirstChild();
51:
52: while (n.getNodeType() != Node.ELEMENT_NODE) {
53: n = n.getNextSibling();
54: }
55: if (n.getLocalName().equals(sayHi.getLocalPart())) {
56: response = sayHiResponse;
57: } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
58: response = greetMeResponse;
59: }
60: } catch (Exception ex) {
61: ex.printStackTrace();
62: }
63: return response;
64: }
65: }
|