Search in sources :

Example 1 with GreeterRPCLit

use of org.apache.hello_world_rpclit.GreeterRPCLit 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]);
    }
    SOAPServiceRPCLit service = new SOAPServiceRPCLit(wsdlURL, SERVICE_NAME);
    GreeterRPCLit greeter = (GreeterRPCLit) service.getPort(PORT_NAME, GreeterRPCLit.class);
    System.out.println("Invoking sayHi...");
    System.out.println("server responded with: " + greeter.sayHi());
    System.out.println();
    System.out.println("Invoking greetMe...");
    System.out.println("server responded with: " + greeter.greetMe(System.getProperty("user.name")));
    System.out.println();
    MyComplexStruct argument = new MyComplexStruct();
    MyComplexStruct retVal = null;
    String str1 = "this is element 1";
    String str2 = "this is element 2";
    int int1 = 42;
    argument.setElem1(str1);
    argument.setElem2(str2);
    argument.setElem3(int1);
    System.out.println("Invoking sendReceiveData...");
    retVal = greeter.sendReceiveData(argument);
    System.out.println("Response from sendReceiveData operation :");
    System.out.println("Element-1 : " + retVal.getElem1());
    System.out.println("Element-2 : " + retVal.getElem2());
    System.out.println("Element-3 : " + retVal.getElem3());
    System.out.println();
    System.exit(0);
}
Also used : SOAPServiceRPCLit(org.apache.hello_world_rpclit.SOAPServiceRPCLit) GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) MyComplexStruct(org.apache.hello_world_rpclit.types.MyComplexStruct) File(java.io.File) URL(java.net.URL)

Example 2 with GreeterRPCLit

use of org.apache.hello_world_rpclit.GreeterRPCLit 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 3 with GreeterRPCLit

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

the class RespectBindingFeatureClientServerTest method testOperationInputRespectBindingFeature.

@Test
public void testOperationInputRespectBindingFeature() throws Exception {
    startServers("/wsdl_systest/cxf_operation_input_respectbing.wsdl");
    try {
        GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class, new RespectBindingFeature(true));
        updateAddressPort(greeter, PORT);
        greeter.greetMe("hello");
        fail("WebServiceException is expected");
    } catch (Exception ex) {
        assertTrue("WebServiceException is expected", ex instanceof javax.xml.ws.WebServiceException);
        assertTrue("RespectBindingFeature message is expected: " + ex.getMessage(), ex.getMessage().indexOf("extension with required=true attribute") > -1);
    }
}
Also used : GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) RespectBindingFeature(javax.xml.ws.RespectBindingFeature) Test(org.junit.Test)

Example 4 with GreeterRPCLit

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

the class ProviderRPCClientServerTest method doGreeterRPCLit.

private void doGreeterRPCLit(SOAPServiceRPCLit service, QName portName, int count, boolean doFault) throws Exception {
    String response1 = new String("TestGreetMeResponse");
    String response2 = new String("TestSayHiResponse");
    try {
        GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
        updateAddressPort(greeter, PORT);
        for (int idx = 0; idx < count; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            assertEquals(response1, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
            if (doFault) {
                try {
                    greeter.greetMe("throwFault");
                } catch (SOAPFaultException ex) {
                    assertNotNull(ex.getFault().getDetail());
                    try {
                        assertTrue(ex.getFault().getDetail().getDetailEntries().hasNext());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 5 with GreeterRPCLit

use of org.apache.hello_world_rpclit.GreeterRPCLit 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

GreeterRPCLit (org.apache.hello_world_rpclit.GreeterRPCLit)11 Test (org.junit.Test)9 RespectBindingFeature (javax.xml.ws.RespectBindingFeature)5 SOAPServiceRPCLit (org.apache.hello_world_rpclit.SOAPServiceRPCLit)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)4 URL (java.net.URL)3 UnmarshalException (javax.xml.bind.UnmarshalException)2 QName (javax.xml.namespace.QName)2 MyComplexStruct (org.apache.hello_world_rpclit.types.MyComplexStruct)2 File (java.io.File)1 Endpoint (javax.xml.ws.Endpoint)1 WebServiceException (javax.xml.ws.WebServiceException)1 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)1