1 package demo.hwDispatch.client; 2 3 import java.io.File ; 4 import java.io.InputStream ; 5 import java.net.URL ; 6 7 import javax.xml.namespace.QName ; 8 import javax.xml.soap.MessageFactory ; 9 import javax.xml.soap.SOAPMessage ; 10 import javax.xml.transform.dom.DOMSource ; 11 import javax.xml.ws.Dispatch; 12 import javax.xml.ws.Service.Mode; 13 14 import org.objectweb.hello_world_soap_http.SOAPService1; 15 import org.objectweb.hello_world_soap_http.SOAPService2; 16 import org.objectweb.hello_world_soap_http.SOAPService3; 17 18 public final class Client { 19 20 private Client() { 21 } 22 23 public static void main(String args[]) throws Exception { 24 25 if (args.length == 0) { 26 System.out.println("please specify wsdl"); 27 System.exit(1); 28 } 29 30 URL wsdlURL; 31 File wsdlFile = new File (args[0]); 32 if (wsdlFile.exists()) { 33 wsdlURL = wsdlFile.toURL(); 34 } else { 35 wsdlURL = new URL (args[0]); 36 } 37 38 MessageFactory factory = MessageFactory.newInstance(); 39 System.out.println(wsdlURL + "\n\n"); 40 41 QName serviceName1 = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService1"); 42 QName portName1 = new QName ("http://objectweb.org/hello_world_soap_http", "SoapPort1"); 43 44 SOAPService1 service1 = new SOAPService1(wsdlURL, serviceName1); 45 InputStream is1 = Client.class.getResourceAsStream("GreetMeDocLiteralReq1.xml"); 46 SOAPMessage soapReq1 = factory.createMessage(null, is1); 47 48 Dispatch<SOAPMessage > dispSOAPMsg = service1.createDispatch(portName1, 49 SOAPMessage .class, Mode.MESSAGE); 50 51 System.out.println("Invoking server through Dispatch interface using SOAPMessage"); 52 SOAPMessage soapResp = dispSOAPMsg.invoke(soapReq1); 53 System.out.println("Response from server: " + soapResp.getSOAPBody().getTextContent()); 54 55 QName serviceName2 = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService2"); 56 QName portName2 = new QName ("http://objectweb.org/hello_world_soap_http", "SoapPort2"); 57 58 SOAPService2 service2 = new SOAPService2(wsdlURL, serviceName2); 59 InputStream is2 = Client.class.getResourceAsStream("GreetMeDocLiteralReq2.xml"); 60 SOAPMessage soapReq2 = factory.createMessage(null, is2); 61 DOMSource domReqMessage = new DOMSource (soapReq2.getSOAPPart()); 62 63 Dispatch<DOMSource > dispDOMSrcMessage = service2.createDispatch(portName2, 64 DOMSource .class, Mode.MESSAGE); 65 System.out.println("Invoking server through Dispatch interface using DOMSource in MESSAGE Mode"); 66 DOMSource domRespMessage = dispDOMSrcMessage.invoke(domReqMessage); 67 System.out.println("Response from server: " 68 + domRespMessage.getNode().getFirstChild().getTextContent()); 69 70 71 QName serviceName3 = new QName ("http://objectweb.org/hello_world_soap_http", "SOAPService3"); 72 QName portName3 = new QName ("http://objectweb.org/hello_world_soap_http", "SoapPort3"); 73 74 SOAPService3 service3 = new SOAPService3(wsdlURL, serviceName3); 75 InputStream is3 = Client.class.getResourceAsStream("GreetMeDocLiteralReq3.xml"); 76 SOAPMessage soapReq3 = MessageFactory.newInstance().createMessage(null, is3); 77 DOMSource domReqPayload = new DOMSource (soapReq3.getSOAPBody().extractContentAsDocument()); 78 79 Dispatch<DOMSource > dispDOMSrcPayload = service3.createDispatch(portName3, 80 DOMSource .class, Mode.PAYLOAD); 81 System.out.println("Invoking server through Dispatch interface using DOMSource in PAYLOAD Mode"); 82 DOMSource domRespPayload = dispDOMSrcPayload.invoke(domReqPayload); 83 System.out.println("Response from server: " 84 + domRespPayload.getNode().getFirstChild().getTextContent()); 85 86 System.exit(0); 87 } 88 89 } 90 | Popular Tags |