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