Search in sources :

Example 6 with FaultMode

use of org.apache.cxf.message.FaultMode 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 FaultMode

use of org.apache.cxf.message.FaultMode in project cxf by apache.

the class ResponseTimeCounter method increase.

public void increase(MessageHandlingTimeRecorder mhtr) {
    if (!enabled) {
        return;
    }
    long handlingTime = 0;
    if (mhtr.isOneWay()) {
        // We can count the response time
        if (mhtr.getEndTime() > 0) {
            handlingTime = mhtr.getHandlingTime();
        }
    } else {
        handlingTime = mhtr.getHandlingTime();
    }
    write.lock();
    try {
        FaultMode faultMode = mhtr.getFaultMode();
        invocations.getAndIncrement();
        if (null == faultMode) {
        // no exception occured
        } else {
            switch(faultMode) {
                case CHECKED_APPLICATION_FAULT:
                    checkedApplicationFaults.incrementAndGet();
                    break;
                case LOGICAL_RUNTIME_FAULT:
                    logicalRuntimeFaults.incrementAndGet();
                    break;
                case RUNTIME_FAULT:
                    runtimeFaults.incrementAndGet();
                    break;
                case UNCHECKED_APPLICATION_FAULT:
                    unCheckedApplicationFaults.incrementAndGet();
                    break;
                default:
                    runtimeFaults.incrementAndGet();
                    break;
            }
        }
        totalHandlingTime.addAndGet(handlingTime);
        averageProcessingTime.getAndSet(totalHandlingTime.get() / invocations.get());
    } finally {
        write.unlock();
    }
    updateMax(handlingTime);
    updateMin(handlingTime);
}
Also used : FaultMode(org.apache.cxf.message.FaultMode)

Example 8 with FaultMode

use of org.apache.cxf.message.FaultMode in project cxf by apache.

the class ResponseTimeMessageOutInterceptorTest method testServerFaultMessageOut.

public void testServerFaultMessageOut(FaultMode faultMode) {
    // need to increase the counter and is not a client
    setupCounterRepository(true, false);
    setupExchangeForMessage();
    EasyMock.expect(message.getExchange()).andReturn(exchange);
    EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE).anyTimes();
    EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
    EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(null);
    EasyMock.expectLastCall();
    EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
    MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
    EasyMock.replay(mhtr);
    // EasyMock.expect(exchange.get(MessageHandlingTimeRecorder.class)).andReturn(mhtr);
    EasyMock.replay(exchange);
    EasyMock.replay(message);
    rtmoi.handleFault(message);
    EasyMock.verify(message);
    EasyMock.verify(bus);
    EasyMock.verify(exchange);
    EasyMock.verify(mhtr);
}
Also used : FaultMode(org.apache.cxf.message.FaultMode) MessageHandlingTimeRecorder(org.apache.cxf.management.counters.MessageHandlingTimeRecorder)

Example 9 with FaultMode

use of org.apache.cxf.message.FaultMode in project cxf by apache.

the class ResponseTimeMessageInInterceptor method handleFault.

@Override
public void handleFault(Message message) {
    Exchange ex = message.getExchange();
    if (Boolean.TRUE.equals(ex.get("org.apache.cxf.management.counter.enabled"))) {
        FaultMode mode = message.get(FaultMode.class);
        if (mode == null) {
            mode = FaultMode.UNCHECKED_APPLICATION_FAULT;
        }
        ex.put(FaultMode.class, mode);
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) FaultMode(org.apache.cxf.message.FaultMode)

Example 10 with FaultMode

use of org.apache.cxf.message.FaultMode in project cxf by apache.

the class ResponseTimeMessageOutInterceptor method handleFault.

@Override
public void handleFault(Message message) {
    Exchange ex = message.getExchange();
    if (ex.get("org.apache.cxf.management.counter.enabled") != null) {
        if (ex.isOneWay()) {
        // do nothing, done by the ResponseTimeInvokerInterceptor
        } else {
            FaultMode faultMode = message.get(FaultMode.class);
            if (faultMode == null) {
                // client side exceptions don't have FaultMode set un the message properties (as of 2.1.4)
                faultMode = FaultMode.RUNTIME_FAULT;
            }
            ex.put(FaultMode.class, faultMode);
            endHandlingMessage(ex);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) FaultMode(org.apache.cxf.message.FaultMode)

Aggregations

FaultMode (org.apache.cxf.message.FaultMode)12 Exchange (org.apache.cxf.message.Exchange)4 Message (org.apache.cxf.message.Message)3 Method (java.lang.reflect.Method)2 Bus (org.apache.cxf.Bus)2 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)2 Fault (org.apache.cxf.interceptor.Fault)2 MessageHandlingTimeRecorder (org.apache.cxf.management.counters.MessageHandlingTimeRecorder)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 PhaseInterceptorChain (org.apache.cxf.phase.PhaseInterceptorChain)2 BindingFaultInfo (org.apache.cxf.service.model.BindingFaultInfo)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Locale (java.util.Locale)1 QName (javax.xml.namespace.QName)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 Schema (javax.xml.validation.Schema)1 WebFault (javax.xml.ws.WebFault)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 SoapFault (org.apache.cxf.binding.soap.SoapFault)1