Search in sources :

Example 6 with XMLService

use of org.apache.hello_world_xml_http.wrapped.XMLService in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithJAXBPayloadModeXMLBinding.

@Test
public void testInvokeWithJAXBPayloadModeXMLBinding() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    XMLService service = new XMLService();
    assertNotNull(service);
    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_xml_http.wrapped.types");
    Dispatch<Object> disp = service.createDispatch(portNameXML, jc, Mode.PAYLOAD);
    setAddress(disp, greeterAddress);
    TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
    addHandlersProgrammatically(disp, handler);
    org.apache.hello_world_xml_http.wrapped.types.GreetMe req = new org.apache.hello_world_xml_http.wrapped.types.GreetMe();
    req.setRequestType("tli");
    Object response = disp.invoke(req);
    assertNotNull(response);
    org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse value = (org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse) response;
    assertEquals("Hello tli", value.getResponseType());
}
Also used : JAXBContext(javax.xml.bind.JAXBContext) URL(java.net.URL) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) Test(org.junit.Test)

Example 7 with XMLService

use of org.apache.hello_world_xml_http.wrapped.XMLService 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]);
    }
    System.out.println(wsdlURL);
    XMLService ss = new XMLService(wsdlURL, SERVICE_NAME);
    Greeter port = ss.getXMLPort();
    String resp;
    System.out.println("Invoking sayHi...");
    resp = port.sayHi();
    System.out.println("Server responded with: " + resp);
    System.out.println();
    System.out.println("Invoking greetMe...");
    resp = port.greetMe(System.getProperty("user.name"));
    System.out.println("Server responded with: " + resp);
    System.out.println();
    System.out.println("Invoking greetMeOneWay...");
    port.greetMeOneWay(System.getProperty("user.name"));
    System.out.println("No response from server as method is OneWay");
    System.out.println();
    try {
        System.out.println("Invoking pingMe, expecting exception...");
        port.pingMe();
    } catch (PingMeFault ex) {
        System.out.println("Expected exception: " + ex.getMessage());
    }
    System.exit(0);
}
Also used : PingMeFault(org.apache.hello_world_xml_http.wrapped.PingMeFault) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) Greeter(org.apache.hello_world_xml_http.wrapped.Greeter) File(java.io.File) URL(java.net.URL)

Example 8 with XMLService

use of org.apache.hello_world_xml_http.wrapped.XMLService in project cxf by apache.

the class DispatchXMLClientServerTest method testStreamSourceMESSAGE.

@Test
public void testStreamSourceMESSAGE() throws Exception {
    /*URL wsdl = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
        assertNotNull(wsdl);

        XMLService service = new XMLService(wsdl, serviceName);
        assertNotNull(service);*/
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://cxf.apache.org/bindings/xformat", "http://localhost:" + port + "/XMLService/XMLDispatchPort");
    InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
    StreamSource reqMsg = new StreamSource(is);
    assertNotNull(reqMsg);
    Dispatch<Source> disp = service.createDispatch(PORT_NAME, Source.class, Service.Mode.MESSAGE);
    Source source = disp.invoke(reqMsg);
    assertNotNull(source);
    String streamString = StaxUtils.toString(source);
    Document doc = StaxUtils.read(new StringReader(streamString));
    assertEquals("greetMeResponse", doc.getFirstChild().getLocalName());
    assertEquals("Hello tli", doc.getFirstChild().getTextContent());
}
Also used : InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) Service(javax.xml.ws.Service) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 9 with XMLService

use of org.apache.hello_world_xml_http.wrapped.XMLService in project cxf by apache.

the class DispatchXMLClientServerTest method testJAXBMESSAGE.

@Test
public void testJAXBMESSAGE() throws Exception {
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://cxf.apache.org/bindings/xformat", "http://localhost:" + port + "/XMLService/XMLDispatchPort");
    GreetMe gm = new GreetMe();
    gm.setRequestType("CXF");
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
    Dispatch<Object> disp = service.createDispatch(PORT_NAME, ctx, Service.Mode.MESSAGE);
    GreetMeResponse resp = (GreetMeResponse) disp.invoke(gm);
    assertNotNull(resp);
    assertEquals("Hello CXF", resp.getResponseType());
    try {
        disp.invoke(null);
        fail("Should have thrown a fault");
    } catch (WebServiceException ex) {
    // expected
    }
}
Also used : GreetMe(org.apache.hello_world_xml_http.wrapped.types.GreetMe) WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) JAXBContext(javax.xml.bind.JAXBContext) GreetMeResponse(org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse) Test(org.junit.Test)

Example 10 with XMLService

use of org.apache.hello_world_xml_http.wrapped.XMLService in project cxf by apache.

the class DispatchHandlerInvocationTest method testInvokeWithDataSourcMessageModeXMLBinding.

@Test
public void testInvokeWithDataSourcMessageModeXMLBinding() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);
    XMLService service = new XMLService();
    assertNotNull(service);
    Dispatch<DataSource> disp = service.createDispatch(portNameXML, DataSource.class, Mode.MESSAGE);
    setAddress(disp, addNumbersAddress);
    TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
    addHandlersProgrammatically(disp, handler);
    URL is = getClass().getResource("/messages/XML_GreetMeDocLiteralReq.xml");
    DataSource ds = new URLDataSource(is);
    DataSource resp = disp.invoke(ds);
    assertNotNull(resp);
}
Also used : URLDataSource(javax.activation.URLDataSource) XMLService(org.apache.hello_world_xml_http.wrapped.XMLService) URL(java.net.URL) URLDataSource(javax.activation.URLDataSource) DataSource(javax.activation.DataSource) Test(org.junit.Test)

Aggregations

XMLService (org.apache.hello_world_xml_http.wrapped.XMLService)11 Test (org.junit.Test)10 URL (java.net.URL)9 InputStream (java.io.InputStream)5 DOMSource (javax.xml.transform.dom.DOMSource)5 JAXBContext (javax.xml.bind.JAXBContext)3 Document (org.w3c.dom.Document)3 DataSource (javax.activation.DataSource)2 URLDataSource (javax.activation.URLDataSource)2 MessageFactory (javax.xml.soap.MessageFactory)2 SOAPMessage (javax.xml.soap.SOAPMessage)2 Service (javax.xml.ws.Service)2 Node (org.w3c.dom.Node)2 File (java.io.File)1 StringReader (java.io.StringReader)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 WebServiceException (javax.xml.ws.WebServiceException)1 Greeter (org.apache.hello_world_xml_http.wrapped.Greeter)1 PingMeFault (org.apache.hello_world_xml_http.wrapped.PingMeFault)1