Search in sources :

Example 1 with SOAPService1

use of org.apache.hello_world_soap_http.SOAPService1 in project cxf by apache.

the class Client method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.out.println("please specify wsdl");
        System.exit(1);
    }
    URL wsdlURL;
    File wsdlFile = new File(args[0]);
    if (wsdlFile.exists()) {
        wsdlURL = wsdlFile.toURI().toURL();
    } else {
        wsdlURL = new URL(args[0]);
    }
    MessageFactory factory = MessageFactory.newInstance();
    System.out.println(wsdlURL + "\n\n");
    final String ns = "http://apache.org/hello_world_soap_http";
    QName serviceName1 = new QName(ns, "SOAPService1");
    QName portName1 = new QName(ns, "SoapPort1");
    SOAPService1 service1 = new SOAPService1(wsdlURL, serviceName1);
    InputStream is1 = Client.class.getResourceAsStream("/GreetMeDocLiteralReq1.xml");
    SOAPMessage soapReq1 = factory.createMessage(null, is1);
    Dispatch<SOAPMessage> dispSOAPMsg = service1.createDispatch(portName1, SOAPMessage.class, Mode.MESSAGE);
    System.out.println("Invoking server through Dispatch interface using SOAPMessage");
    SOAPMessage soapResp = dispSOAPMsg.invoke(soapReq1);
    System.out.println("Response from server: " + soapResp.getSOAPBody().getTextContent());
    QName serviceName3 = new QName(ns, "SOAPService3");
    QName portName3 = new QName(ns, "SoapPort3");
    SOAPService3 service3 = new SOAPService3(wsdlURL, serviceName3);
    InputStream is3 = Client.class.getResourceAsStream("/GreetMeDocLiteralReq2.xml");
    SOAPMessage soapReq3 = MessageFactory.newInstance().createMessage(null, is3);
    DOMSource domReqPayload = new DOMSource(soapReq3.getSOAPBody().extractContentAsDocument());
    Dispatch<DOMSource> dispDOMSrcPayload = service3.createDispatch(portName3, DOMSource.class, Mode.PAYLOAD);
    System.out.println("Invoking server through Dispatch interface using DOMSource in PAYLOAD Mode");
    DOMSource domRespPayload = dispDOMSrcPayload.invoke(domReqPayload);
    System.out.println("Response from server: " + domRespPayload.getNode().getFirstChild().getTextContent());
    System.exit(0);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) MessageFactory(javax.xml.soap.MessageFactory) SOAPService1(org.apache.hello_world_soap_http.SOAPService1) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) SOAPService3(org.apache.hello_world_soap_http.SOAPService3) File(java.io.File) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL)

Aggregations

File (java.io.File)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 QName (javax.xml.namespace.QName)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 DOMSource (javax.xml.transform.dom.DOMSource)1 SOAPService1 (org.apache.hello_world_soap_http.SOAPService1)1 SOAPService3 (org.apache.hello_world_soap_http.SOAPService3)1