Search in sources :

Example 1 with NoSuchCodeLitFault

use of org.apache.hello_world_soap_http.NoSuchCodeLitFault in project camel by apache.

the class AbstractCXFGreeterRouterTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    Service service = Service.create(serviceName);
    service.addPort(routerPortName, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + getPort2() + "/" + getClass().getSimpleName() + "/CamelContext/RouterPort");
    Greeter greeter = service.getPort(routerPortName, Greeter.class);
    String reply = greeter.greetMe("test");
    assertNotNull("No response received from service", reply);
    assertEquals("Got the wrong reply ", "Hello test", reply);
    reply = greeter.sayHi();
    assertNotNull("No response received from service", reply);
    assertEquals("Got the wrong reply ", "Bonjour", reply);
    greeter.greetMeOneWay("call greetMe OneWay !");
    // test throw the exception
    try {
        greeter.testDocLitFault("NoSuchCodeLitFault");
        // should get the exception here
        fail("Should get the NoSuchCodeLitFault here.");
    } catch (NoSuchCodeLitFault fault) {
        // expect the fault here
        assertNotNull("The fault info should not be null", fault.getFaultInfo());
    }
}
Also used : NoSuchCodeLitFault(org.apache.hello_world_soap_http.NoSuchCodeLitFault) Greeter(org.apache.hello_world_soap_http.Greeter) Service(javax.xml.ws.Service) Test(org.junit.Test)

Example 2 with NoSuchCodeLitFault

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

the class ClientServerTest method testFaults.

@Test
public void testFaults() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    ExecutorService ex = Executors.newFixedThreadPool(1);
    service.setExecutor(ex);
    assertNotNull(service);
    String noSuchCodeFault = "NoSuchCodeLitFault";
    String badRecordFault = "BadRecordLitFault";
    String illegalArgumentException = "IllegalArgumentException";
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateAddressPort(greeter, PORT);
    for (int idx = 0; idx < 2; idx++) {
        try {
            greeter.testDocLitFault(noSuchCodeFault);
            fail("Should have thrown NoSuchCodeLitFault exception");
        } catch (NoSuchCodeLitFault nslf) {
            int responseCode = (Integer) ((BindingProvider) greeter).getResponseContext().get(MessageContext.HTTP_RESPONSE_CODE);
            assertEquals(responseCode, 500);
            assertNotNull(nslf.getFaultInfo());
            assertNotNull(nslf.getFaultInfo().getCode());
        }
        try {
            greeter.testDocLitFault(illegalArgumentException);
            fail("Should have thrown SOAPFaultException exception");
        } catch (SOAPFaultException sfe) {
            assertEquals("TestIllegalArgumentException", sfe.getCause().getMessage());
            sfe.printStackTrace();
        }
        try {
            greeter.testDocLitFault(badRecordFault);
            fail("Should have thrown BadRecordLitFault exception");
        } catch (BadRecordLitFault brlf) {
            BindingProvider bp = (BindingProvider) greeter;
            Map<String, Object> responseContext = bp.getResponseContext();
            String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
            assertEquals("text/xml;charset=utf-8", stripSpaces(contentType.toLowerCase()));
            Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
            assertEquals(500, responseCode.intValue());
            assertNotNull(brlf.getFaultInfo());
            assertEquals("BadRecordLitFault", brlf.getFaultInfo());
        }
        try {
            greeter.testDocLitFaultAsync(noSuchCodeFault).get();
            fail("Should have thrown NoSuchCodeLitFault exception");
        } catch (ExecutionException ee) {
            NoSuchCodeLitFault nslf = (NoSuchCodeLitFault) ee.getCause();
            assertNotNull(nslf.getFaultInfo());
            assertNotNull(nslf.getFaultInfo().getCode());
        }
        try {
            greeter.testDocLitFaultAsync(illegalArgumentException).get();
            fail("Should have thrown SOAPFaultException exception");
        } catch (ExecutionException ee) {
            SOAPFaultException sfe = (SOAPFaultException) ee.getCause();
            assertEquals("TestIllegalArgumentException", sfe.getCause().getMessage());
        }
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) NoSuchCodeLitFault(org.apache.hello_world_soap_http.NoSuchCodeLitFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Endpoint(javax.xml.ws.Endpoint) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) Greeter(org.apache.hello_world_soap_http.Greeter) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 3 with NoSuchCodeLitFault

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

the class AbstractGreeterImpl method testDocLitFault.

public void testDocLitFault(String faultType) throws BadRecordLitFault, NoSuchCodeLitFault {
    verifyMAPs();
    if (faultType.equals(BadRecordLitFault.class.getSimpleName())) {
        throw new BadRecordLitFault("TestBadRecordLit", "BadRecordLitFault");
    }
    if (faultType.equals(NoSuchCodeLitFault.class.getSimpleName())) {
        ErrorCode ec = new ErrorCode();
        ec.setMajor((short) 1);
        ec.setMinor((short) 1);
        NoSuchCodeLit nscl = new NoSuchCodeLit();
        nscl.setCode(ec);
        throw new NoSuchCodeLitFault("TestNoSuchCodeLit", nscl);
    }
}
Also used : BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) NoSuchCodeLit(org.apache.hello_world_soap_http.types.NoSuchCodeLit) NoSuchCodeLitFault(org.apache.hello_world_soap_http.NoSuchCodeLitFault) ErrorCode(org.apache.hello_world_soap_http.types.ErrorCode)

Example 4 with NoSuchCodeLitFault

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

the class ClientServerWebSocketTest method testFaults.

@Test
public void testFaults() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    ExecutorService ex = Executors.newFixedThreadPool(1);
    service.setExecutor(ex);
    assertNotNull(service);
    String noSuchCodeFault = "NoSuchCodeLitFault";
    String badRecordFault = "BadRecordLitFault";
    Greeter greeter = service.getPort(portName, Greeter.class);
    updateGreeterAddress(greeter, PORT);
    for (int idx = 0; idx < 2; idx++) {
        try {
            greeter.testDocLitFault(noSuchCodeFault);
            fail("Should have thrown NoSuchCodeLitFault exception");
        } catch (NoSuchCodeLitFault nslf) {
            assertNotNull(nslf.getFaultInfo());
            assertNotNull(nslf.getFaultInfo().getCode());
        }
        try {
            greeter.testDocLitFault(badRecordFault);
            fail("Should have thrown BadRecordLitFault exception");
        } catch (BadRecordLitFault brlf) {
            BindingProvider bp = (BindingProvider) greeter;
            Map<String, Object> responseContext = bp.getResponseContext();
            String contentType = (String) responseContext.get(Message.CONTENT_TYPE);
            assertEquals("text/xml; charset=utf-8", contentType.toLowerCase());
            Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
            assertEquals(500, responseCode.intValue());
            assertNotNull(brlf.getFaultInfo());
            assertEquals("BadRecordLitFault", brlf.getFaultInfo());
        }
    }
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) NoSuchCodeLitFault(org.apache.hello_world_soap_http.NoSuchCodeLitFault) Greeter(org.apache.hello_world_soap_http.Greeter) ExecutorService(java.util.concurrent.ExecutorService) BindingProvider(javax.xml.ws.BindingProvider) Map(java.util.Map) URL(java.net.URL) Test(org.junit.Test)

Aggregations

NoSuchCodeLitFault (org.apache.hello_world_soap_http.NoSuchCodeLitFault)4 BadRecordLitFault (org.apache.hello_world_soap_http.BadRecordLitFault)3 Greeter (org.apache.hello_world_soap_http.Greeter)3 Test (org.junit.Test)3 URL (java.net.URL)2 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 BindingProvider (javax.xml.ws.BindingProvider)2 SOAPService (org.apache.hello_world_soap_http.SOAPService)2 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Endpoint (javax.xml.ws.Endpoint)1 Service (javax.xml.ws.Service)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 SOAPServiceBogusAddressTest (org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest)1 SOAPServiceMultiPortTypeTest (org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest)1 ErrorCode (org.apache.hello_world_soap_http.types.ErrorCode)1 NoSuchCodeLit (org.apache.hello_world_soap_http.types.NoSuchCodeLit)1