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