Search in sources :

Example 6 with PingMeFault

use of org.apache.cxf.greeter_control.PingMeFault in project cxf by apache.

the class FaultHandlingInterceptor method handleMessage.

public synchronized void handleMessage(Message message) throws Fault {
    FaultMode mode = MessageUtils.getFaultMode(message);
    if (null != mode) {
        Throwable cause = message.getContent(Exception.class).getCause();
        if (FaultMode.CHECKED_APPLICATION_FAULT == mode) {
            PingMeFault original = (PingMeFault) cause;
            FaultDetail detail = new FaultDetail();
            detail.setMajor((short) 20);
            detail.setMinor((short) 10);
            PingMeFault replaced = new PingMeFault(original.getMessage(), detail);
            message.setContent(Exception.class, new Fault(replaced));
        } else {
            RuntimeException original = (RuntimeException) cause;
            RuntimeException replaced = new RuntimeException(original.getMessage().toUpperCase());
            message.setContent(Exception.class, new Fault(replaced));
        }
    }
}
Also used : FaultMode(org.apache.cxf.message.FaultMode) PingMeFault(org.apache.cxf.greeter_control.PingMeFault) FaultDetail(org.apache.cxf.greeter_control.types.FaultDetail) Fault(org.apache.cxf.interceptor.Fault) PingMeFault(org.apache.cxf.greeter_control.PingMeFault)

Example 7 with PingMeFault

use of org.apache.cxf.greeter_control.PingMeFault in project camel by apache.

the class JaxWsWebFaultAnnotationToFaultTest method testInvokingServiceFromCXFClient.

@Test
public void testInvokingServiceFromCXFClient() throws Exception {
    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    ClientFactoryBean clientBean = proxyFactory.getClientFactoryBean();
    clientBean.setAddress(ROUTER_ADDRESS);
    clientBean.setServiceClass(Greeter.class);
    Greeter client = (Greeter) proxyFactory.create();
    try {
        client.pingMe();
        fail("Expect to get an exception here");
    } catch (PingMeFault expected) {
        assertEquals(MESSAGE, expected.getMessage());
    } catch (Throwable t) {
        t.printStackTrace();
        fail("The CXF client did not manage to map the client exception " + t.getClass().getName() + " to a " + PingMeFault.class.getName() + ": " + t.getMessage());
    }
}
Also used : PingMeFault(org.apache.cxf.greeter_control.PingMeFault) ClientFactoryBean(org.apache.cxf.frontend.ClientFactoryBean) Greeter(org.apache.cxf.greeter_control.Greeter) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Test(org.junit.Test)

Example 8 with PingMeFault

use of org.apache.cxf.greeter_control.PingMeFault in project cxf by apache.

the class GreeterImpl11 method pingMe.

public void pingMe() throws PingMeFault {
    FaultDetail faultDetail = new FaultDetail();
    faultDetail.setMajor((short) 2);
    faultDetail.setMinor((short) 1);
    LOG.info("Executing operation pingMe, throwing PingMeFault exception");
    // System.out.println("Executing operation pingMe, throwing PingMeFault exception\n");
    throw new PingMeFault("PingMeFault raised by server", faultDetail);
}
Also used : PingMeFault(org.apache.cxf.greeter_control.PingMeFault) FaultDetail(org.apache.cxf.greeter_control.types.FaultDetail)

Example 9 with PingMeFault

use of org.apache.cxf.greeter_control.PingMeFault in project cxf by apache.

the class Soap11ClientServerTest method testPingMeFault.

@Test
public void testPingMeFault() throws Exception {
    Greeter greeter = getGreeter();
    try {
        greeter.pingMe();
        fail("Should throw Exception!");
    } catch (PingMeFault ex) {
        FaultDetail detail = ex.getFaultInfo();
        assertEquals((short) 2, detail.getMajor());
        assertEquals((short) 1, detail.getMinor());
        assertEquals("PingMeFault raised by server", ex.getMessage());
        StackTraceElement[] element = ex.getStackTrace();
        assertEquals("org.apache.cxf.systest.soapfault.details.GreeterImpl11", element[0].getClassName());
    }
}
Also used : PingMeFault(org.apache.cxf.greeter_control.PingMeFault) Greeter(org.apache.cxf.greeter_control.Greeter) FaultDetail(org.apache.cxf.greeter_control.types.FaultDetail) Test(org.junit.Test)

Example 10 with PingMeFault

use of org.apache.cxf.greeter_control.PingMeFault in project cxf by apache.

the class AddressingInlinePolicyTest method testUsingAddressing.

@Test
public void testUsingAddressing() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-inline-policy-old.xml");
    BusFactory.setDefaultBus(bus);
    BasicGreeterService gs = new BasicGreeterService();
    final Greeter greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");
    ConnectionHelper.setKeepAliveConnection(greeter, true);
    testInterceptors(bus);
    // oneway
    greeter.greetMeOneWay("CXF");
    // two-way
    assertEquals("CXF", greeter.greetMe("cxf"));
    try {
        greeter.pingMe();
    } catch (PingMeFault ex) {
        fail("First invocation should have succeeded.");
    }
    try {
        greeter.pingMe();
        fail("Expected PingMeFault not thrown.");
    } catch (PingMeFault ex) {
        assertEquals(2, ex.getFaultInfo().getMajor());
        assertEquals(1, ex.getFaultInfo().getMinor());
    }
    ((Closeable) greeter).close();
}
Also used : PingMeFault(org.apache.cxf.greeter_control.PingMeFault) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.cxf.greeter_control.Greeter) Closeable(java.io.Closeable) BasicGreeterService(org.apache.cxf.greeter_control.BasicGreeterService) Test(org.junit.Test)

Aggregations

PingMeFault (org.apache.cxf.greeter_control.PingMeFault)15 Greeter (org.apache.cxf.greeter_control.Greeter)13 Test (org.junit.Test)13 Closeable (java.io.Closeable)11 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)9 BasicGreeterService (org.apache.cxf.greeter_control.BasicGreeterService)9 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)5 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)5 MessageFlow (org.apache.cxf.systest.ws.util.MessageFlow)5 FaultDetail (org.apache.cxf.greeter_control.types.FaultDetail)3 InMessageRecorder (org.apache.cxf.testutil.recorders.InMessageRecorder)3 MessageRecorder (org.apache.cxf.testutil.recorders.MessageRecorder)3 OutMessageRecorder (org.apache.cxf.testutil.recorders.OutMessageRecorder)3 Endpoint (javax.xml.ws.Endpoint)2 WebServiceException (javax.xml.ws.WebServiceException)2 SocketTimeoutException (java.net.SocketTimeoutException)1 URL (java.net.URL)1 Bus (org.apache.cxf.Bus)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1 ClientFactoryBean (org.apache.cxf.frontend.ClientFactoryBean)1