Search in sources :

Example 1 with BadRecordLitFault

use of org.apache.hello_world_soap_http.BadRecordLitFault 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 2 with BadRecordLitFault

use of org.apache.hello_world_soap_http.BadRecordLitFault 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 3 with BadRecordLitFault

use of org.apache.hello_world_soap_http.BadRecordLitFault 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)

Example 4 with BadRecordLitFault

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

the class CxfProducerSoapFaultTest method invokeSoapFault.

private void invokeSoapFault(boolean sync) throws Exception {
    String cxfEndpointURI = JAXWS_ENDPOINT_URI;
    if (sync) {
        cxfEndpointURI = cxfEndpointURI + "&synchronous=true";
    }
    Exchange exchange = sendJaxWsMessage(cxfEndpointURI, "BadRecordLitFault", "testDocLitFault");
    Exception exception = exchange.getException();
    // assert we got the exception first
    assertNotNull("except to get the exception", exception);
    assertTrue("Get a wrong soap fault", exception instanceof BadRecordLitFault);
    // check out the message header which is copied from in message
    String fileName = exchange.getOut().getHeader(Exchange.FILE_NAME, String.class);
    assertEquals("Should get the file name from out message header", "testFile", fileName);
}
Also used : Exchange(org.apache.camel.Exchange) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault)

Example 5 with BadRecordLitFault

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

the class JaxWsClientTest method testEndpoint.

@Test
public void testEndpoint() throws Exception {
    ReflectionServiceFactoryBean bean = new JaxWsServiceFactoryBean();
    URL resource = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(resource);
    bean.setWsdlURL(resource.toString());
    bean.setBus(getBus());
    bean.setServiceClass(GreeterImpl.class);
    GreeterImpl greeter = new GreeterImpl();
    BeanInvoker invoker = new BeanInvoker(greeter);
    bean.setInvoker(invoker);
    Service service = bean.create();
    String namespace = "http://apache.org/hello_world_soap_http";
    EndpointInfo ei = service.getServiceInfos().get(0).getEndpoint(new QName(namespace, "SoapPort"));
    JaxWsEndpointImpl endpoint = new JaxWsEndpointImpl(getBus(), service, ei);
    ClientImpl client = new ClientImpl(getBus(), endpoint);
    BindingOperationInfo bop = ei.getBinding().getOperation(new QName(namespace, "sayHi"));
    assertNotNull(bop);
    bop = bop.getUnwrappedOperation();
    assertNotNull(bop);
    MessagePartInfo part = bop.getOutput().getMessageParts().get(0);
    assertEquals(0, part.getIndex());
    d.setMessageObserver(new MessageReplayObserver("sayHiResponse.xml"));
    Object[] ret = client.invoke(bop, new Object[] { "hi" }, null);
    assertNotNull(ret);
    assertEquals("Wrong number of return objects", 1, ret.length);
    // test fault handling
    bop = ei.getBinding().getOperation(new QName(namespace, "testDocLitFault"));
    bop = bop.getUnwrappedOperation();
    d.setMessageObserver(new MessageReplayObserver("testDocLitFault.xml"));
    try {
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (BadRecordLitFault fault) {
        assertEquals("foo", fault.getFaultInfo().trim());
        assertEquals("Hadrian did it.", fault.getMessage());
    }
    try {
        client.getEndpoint().getOutInterceptors().add(new NestedFaultThrower());
        client.getEndpoint().getOutInterceptors().add(new FaultThrower());
        client.invoke(bop, new Object[] { "BadRecordLitFault" }, null);
        fail("Should have returned a fault!");
    } catch (Fault fault) {
        assertTrue(fault.getMessage().indexOf("Foo") >= 0);
    }
    client.close();
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) QName(javax.xml.namespace.QName) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) Service(org.apache.cxf.service.Service) ClientImpl(org.apache.cxf.endpoint.ClientImpl) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) URL(java.net.URL) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) BadRecordLitFault(org.apache.hello_world_soap_http.BadRecordLitFault) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) ReflectionServiceFactoryBean(org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean) Test(org.junit.Test)

Aggregations

BadRecordLitFault (org.apache.hello_world_soap_http.BadRecordLitFault)5 URL (java.net.URL)3 NoSuchCodeLitFault (org.apache.hello_world_soap_http.NoSuchCodeLitFault)3 Test (org.junit.Test)3 Map (java.util.Map)2 ExecutorService (java.util.concurrent.ExecutorService)2 BindingProvider (javax.xml.ws.BindingProvider)2 Greeter (org.apache.hello_world_soap_http.Greeter)2 SOAPService (org.apache.hello_world_soap_http.SOAPService)2 ExecutionException (java.util.concurrent.ExecutionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 QName (javax.xml.namespace.QName)1 Endpoint (javax.xml.ws.Endpoint)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 Exchange (org.apache.camel.Exchange)1 ClientImpl (org.apache.cxf.endpoint.ClientImpl)1 Fault (org.apache.cxf.interceptor.Fault)1 JaxWsEndpointImpl (org.apache.cxf.jaxws.support.JaxWsEndpointImpl)1 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)1 Service (org.apache.cxf.service.Service)1