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.stream.StreamSource;
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="SoapPortRPCLit4",serviceName="SOAPServiceRPCLit4",targetNamespace="http://objectweb.org/hello_world_rpclit",wsdlLocation="/wsdl/hello_world_rpc_lit.wsdl")
20: @ServiceMode(value=Service.Mode.MESSAGE)
21: public class HWStreamSourceMessageProvider implements
22: Provider<StreamSource> {
23:
24: private static QName sayHi = new QName(
25: "http://objectweb.org/hello_world_rpclit", "sayHi");
26: private static QName greetMe = new QName(
27: "http://objectweb.org/hello_world_rpclit", "greetMe");
28: private InputStream sayHiInputStream;
29: private InputStream greetMeInputStream;
30: private MessageFactory factory;
31:
32: public HWStreamSourceMessageProvider() {
33:
34: try {
35: factory = MessageFactory.newInstance();
36: sayHiInputStream = getClass().getResourceAsStream(
37: "resources/sayHiRpcLiteralResp.xml");
38: greetMeInputStream = getClass().getResourceAsStream(
39: "resources/GreetMeRpcLiteralResp.xml");
40:
41: } catch (Exception ex) {
42: ex.printStackTrace();
43: }
44: }
45:
46: public StreamSource invoke(StreamSource request) {
47: StreamSource response = new StreamSource();
48: try {
49: SOAPMessage msg = factory.createMessage();
50: msg.getSOAPPart().setContent(request);
51: SOAPBody body = msg.getSOAPBody();
52: Node n = body.getFirstChild();
53:
54: while (n.getNodeType() != Node.ELEMENT_NODE) {
55: n = n.getNextSibling();
56: }
57: if (n.getLocalName().equals(sayHi.getLocalPart())) {
58: response.setInputStream(sayHiInputStream);
59: } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
60: response.setInputStream(greetMeInputStream);
61: }
62: } catch (Exception ex) {
63: ex.printStackTrace();
64: }
65: return response;
66: }
67:
68: }
|