01: package demo.hwDispatch.client;
02:
03: import java.io.File;
04: import java.io.InputStream;
05: import java.net.URL;
06:
07: import javax.xml.namespace.QName;
08: import javax.xml.soap.MessageFactory;
09: 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.SOAPService3;
16:
17: public final class Client {
18:
19: private Client() {
20: }
21:
22: public static void main(String args[]) throws Exception {
23:
24: if (args.length == 0) {
25: System.out.println("please specify wsdl");
26: System.exit(1);
27: }
28:
29: URL wsdlURL;
30: File wsdlFile = new File(args[0]);
31: if (wsdlFile.exists()) {
32: wsdlURL = wsdlFile.toURL();
33: } else {
34: wsdlURL = new URL(args[0]);
35: }
36:
37: MessageFactory factory = MessageFactory.newInstance();
38: System.out.println(wsdlURL + "\n\n");
39:
40: final String ns = "http://objectweb.org/hello_world_soap_http";
41: QName serviceName1 = new QName(ns, "SOAPService1");
42: QName portName1 = new QName(ns, "SoapPort1");
43:
44: SOAPService1 service1 = new SOAPService1(wsdlURL, serviceName1);
45: InputStream is1 = Client.class
46: .getResourceAsStream("GreetMeDocLiteralReq1.xml");
47: SOAPMessage soapReq1 = factory.createMessage(null, is1);
48:
49: Dispatch<SOAPMessage> dispSOAPMsg = service1.createDispatch(
50: portName1, SOAPMessage.class, Mode.MESSAGE);
51:
52: System.out
53: .println("Invoking server through Dispatch interface using SOAPMessage");
54: SOAPMessage soapResp = dispSOAPMsg.invoke(soapReq1);
55: System.out.println("Response from server: "
56: + soapResp.getSOAPBody().getTextContent());
57:
58: QName serviceName3 = new QName(ns, "SOAPService3");
59: QName portName3 = new QName(ns, "SoapPort3");
60:
61: SOAPService3 service3 = new SOAPService3(wsdlURL, serviceName3);
62: InputStream is3 = Client.class
63: .getResourceAsStream("GreetMeDocLiteralReq3.xml");
64: SOAPMessage soapReq3 = MessageFactory.newInstance()
65: .createMessage(null, is3);
66: DOMSource domReqPayload = new DOMSource(soapReq3.getSOAPBody()
67: .extractContentAsDocument());
68:
69: Dispatch<DOMSource> dispDOMSrcPayload = service3
70: .createDispatch(portName3, DOMSource.class,
71: Mode.PAYLOAD);
72: System.out
73: .println("Invoking server through Dispatch interface using DOMSource in PAYLOAD Mode");
74: DOMSource domRespPayload = dispDOMSrcPayload
75: .invoke(domReqPayload);
76: System.out.println("Response from server: "
77: + domRespPayload.getNode().getFirstChild()
78: .getTextContent());
79:
80: System.exit(0);
81: }
82:
83: }
|