Search in sources :

Example 6 with SOAPServiceRPCLit

use of org.apache.hello_world_rpclit.SOAPServiceRPCLit in project cxf by apache.

the class ClientServerRPCLitTest method testBasicConnection.

@Test
public void testBasicConnection() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    assertNotNull(service);
    String response1 = new String("Hello Milestone-");
    String response2 = new String("Bonjour");
    try {
        GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
        ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
        updateAddressPort(greeter, PORT);
        for (int idx = 0; idx < 1; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            String exResponse = response1 + idx;
            assertEquals(exResponse, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
            try {
                greeter.greetMe("return null");
                fail("should catch WebServiceException");
            } catch (WebServiceException e) {
            // do nothing
            } catch (Exception e) {
                fail("should catch WebServiceException");
                throw e;
            }
            try {
                greeter.greetMe(null);
                fail("should catch WebServiceException");
            } catch (WebServiceException e) {
            // do nothing
            } catch (Exception e) {
                fail("should catch WebServiceException");
                throw e;
            }
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) WebServiceException(javax.xml.ws.WebServiceException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Endpoint(javax.xml.ws.Endpoint) UnmarshalException(javax.xml.bind.UnmarshalException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.junit.Test)

Example 7 with SOAPServiceRPCLit

use of org.apache.hello_world_rpclit.SOAPServiceRPCLit in project cxf by apache.

the class ClientServerRPCLitTest method testComplexType.

@Test
public void testComplexType() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    assertNotNull(service);
    GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
    updateAddressPort(greeter, PORT);
    MyComplexStruct in = new MyComplexStruct();
    in.setElem1("elem1");
    in.setElem2("elem2");
    in.setElem3(45);
    try {
        ((BindingProvider) greeter).getRequestContext().put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.TRUE);
        MyComplexStruct out = greeter.sendReceiveData(in);
        assertNotNull("no response received from service", out);
        assertEquals(in.getElem1(), out.getElem1());
        assertEquals(in.getElem2(), out.getElem2());
        assertEquals(in.getElem3(), out.getElem3());
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
    try {
        in.setElem2("invalid");
        greeter.sendReceiveData(in);
    } catch (SOAPFaultException f) {
        assertTrue(f.getCause() instanceof UnmarshalException);
    }
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) UnmarshalException(javax.xml.bind.UnmarshalException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) Test(org.junit.Test)

Example 8 with SOAPServiceRPCLit

use of org.apache.hello_world_rpclit.SOAPServiceRPCLit in project cxf by apache.

the class ClientServerRPCLitTest method testDispatchClient.

@Test
public void testDispatchClient() throws Exception {
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    Dispatch<Source> disp = service.createDispatch(portName, Source.class, javax.xml.ws.Service.Mode.PAYLOAD);
    updateAddressPort(disp, PORT);
    String req = "<ns1:sendReceiveData xmlns:ns1=\"http://apache.org/hello_world_rpclit\">" + "<in xmlns:ns2=\"http://apache.org/hello_world_rpclit/types\">" + "<ns2:elem1>elem1</ns2:elem1><ns2:elem2>elem2</ns2:elem2><ns2:elem3>45</ns2:elem3>" + "</in></ns1:sendReceiveData>";
    Source source = new StreamSource(new StringReader(req));
    Source resp = disp.invoke(source);
    assertNotNull(resp);
    Node nd = StaxUtils.read(resp);
    if (nd instanceof Document) {
        nd = ((Document) nd).getDocumentElement();
    }
    XPathUtils xpu = new XPathUtils(new W3CNamespaceContext((Element) nd));
    assertTrue(xpu.isExist("/ns1:sendReceiveDataResponse/out", nd, XPathConstants.NODE));
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) W3CNamespaceContext(org.apache.cxf.staxutils.W3CNamespaceContext) XPathUtils(org.apache.cxf.helpers.XPathUtils) StreamSource(javax.xml.transform.stream.StreamSource) Node(org.w3c.dom.Node) XmlRootElement(javax.xml.bind.annotation.XmlRootElement) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 9 with SOAPServiceRPCLit

use of org.apache.hello_world_rpclit.SOAPServiceRPCLit in project cxf by apache.

the class ProviderRPCClientServerTest method testPayloadModeWithDOMSourceData.

@Test
public void testPayloadModeWithDOMSourceData() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world_rpc_lit.wsdl");
    assertNotNull(wsdl);
    QName serviceName = new QName("http://apache.org/hello_world_rpclit", "SOAPServiceProviderRPCLit");
    QName portName = new QName("http://apache.org/hello_world_rpclit", "SoapPortProviderRPCLit3");
    SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl, serviceName);
    assertNotNull(service);
    doGreeterRPCLit(service, portName, 1, true);
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) QName(javax.xml.namespace.QName) URL(java.net.URL) Test(org.junit.Test)

Example 10 with SOAPServiceRPCLit

use of org.apache.hello_world_rpclit.SOAPServiceRPCLit in project cxf by apache.

the class ProviderRPCClientServerTest method testPayloadModeWithSourceData.

@Test
public void testPayloadModeWithSourceData() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world_rpc_lit.wsdl");
    assertNotNull(wsdl);
    QName serviceName = new QName("http://apache.org/hello_world_rpclit", "SOAPServiceProviderRPCLit");
    QName portName = new QName("http://apache.org/hello_world_rpclit", "SoapPortProviderRPCLit8");
    SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdl, serviceName);
    assertNotNull(service);
    String[] addresses = { "http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8", "http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-dom", "http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-sax", "http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-cxfstax", "http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-stax", "http://localhost:" + PORT + "/SOAPServiceProviderRPCLit/SoapPortProviderRPCLit8-stream" };
    String response1 = new String("TestGreetMeResponseServerLogicalHandlerServerSOAPHandler");
    GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
    for (String ad : addresses) {
        ((BindingProvider) greeter).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ad);
        String greeting = greeter.greetMe("Milestone-0");
        assertNotNull("no response received from service " + ad, greeting);
        assertEquals("wrong response received from service " + ad, response1, greeting);
    }
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) QName(javax.xml.namespace.QName) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SOAPServiceRPCLit (org.apache.hello_world_rpclit.SOAPServiceRPCLit)11 Test (org.junit.Test)10 URL (java.net.URL)8 QName (javax.xml.namespace.QName)7 GreeterRPCLit (org.apache.hello_world_rpclit.GreeterRPCLit)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)3 UnmarshalException (javax.xml.bind.UnmarshalException)2 MyComplexStruct (org.apache.hello_world_rpclit.types.MyComplexStruct)2 File (java.io.File)1 StringReader (java.io.StringReader)1 XmlRootElement (javax.xml.bind.annotation.XmlRootElement)1 Source (javax.xml.transform.Source)1 StreamSource (javax.xml.transform.stream.StreamSource)1 Endpoint (javax.xml.ws.Endpoint)1 WebServiceException (javax.xml.ws.WebServiceException)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1 XPathUtils (org.apache.cxf.helpers.XPathUtils)1 W3CNamespaceContext (org.apache.cxf.staxutils.W3CNamespaceContext)1 Document (org.w3c.dom.Document)1