1 package org.objectweb.celtix.systest.provider; 2 3 import java.io.InputStream ; 4 5 import javax.xml.namespace.QName ; 6 import javax.xml.soap.MessageFactory ; 7 import javax.xml.soap.SOAPBody ; 8 import javax.xml.soap.SOAPMessage ; 9 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 @WebServiceProvider(portName = "SoapPortRPCLit3", serviceName = "SOAPServiceRPCLit3", 22 targetNamespace = "http://objectweb.org/hello_world_rpclit", 23 wsdlLocation = "/wsdl/hello_world_rpc_lit.wsdl") 24 @ServiceMode(value = Service.Mode.MESSAGE) 25 public class HWSAXSourceMessageProvider implements Provider<SAXSource > { 26 27 private static QName sayHi = new QName ("http://objectweb.org/hello_world_rpclit", "sayHi"); 28 private static QName greetMe = new QName ("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("resources/sayHiRpcLiteralResp.xml"); 38 sayHiInputSource = new InputSource (is1); 39 40 InputStream is2 = getClass().getResourceAsStream("resources/GreetMeRpcLiteralResp.xml"); 41 greetMeInputSource = new InputSource (is2); 42 43 } catch (Exception ex) { 44 ex.printStackTrace(); 45 } 46 } 47 48 public SAXSource invoke(SAXSource request) { 49 SAXSource response = new SAXSource (); 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.setInputSource(sayHiInputSource); 61 } else if (n.getLocalName().equals(greetMe.getLocalPart())) { 62 response.setInputSource(greetMeInputSource); 63 } 64 } catch (Exception ex) { 65 ex.printStackTrace(); 66 } 67 return response; 68 } 69 70 } 71 | Popular Tags |