Search in sources :

Example 1 with FaultMode

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

the class AbstractFaultChainInitiatorObserver method onMessage.

public void onMessage(Message message) {
    assert null != message;
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    ClassLoaderHolder origLoader = null;
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        Exchange exchange = message.getExchange();
        Message faultMessage;
        if (isOutboundObserver()) {
            Exception ex = message.getContent(Exception.class);
            if (!(ex instanceof Fault)) {
                ex = new Fault(ex);
            }
            FaultMode mode = message.get(FaultMode.class);
            faultMessage = exchange.getOutMessage();
            if (null == faultMessage) {
                faultMessage = new MessageImpl();
                faultMessage.setExchange(exchange);
                faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
            }
            faultMessage.setContent(Exception.class, ex);
            if (null != mode) {
                faultMessage.put(FaultMode.class, mode);
            }
            // CXF-3981
            if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
                faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
            }
            exchange.setOutMessage(null);
            exchange.setOutFaultMessage(faultMessage);
            if (message.get(BindingFaultInfo.class) != null) {
                faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
            }
        } else {
            faultMessage = message;
            exchange.setInMessage(null);
            exchange.setInFaultMessage(faultMessage);
        }
        // setup chain
        PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
        initializeInterceptors(faultMessage.getExchange(), chain);
        faultMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(faultMessage);
        } catch (RuntimeException exc) {
            LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
            throw exc;
        } catch (Exception exc) {
            LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
            throw new RuntimeException(exc);
        }
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) FaultMode(org.apache.cxf.message.FaultMode) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) MessageImpl(org.apache.cxf.message.MessageImpl) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 2 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 3 with FaultMode

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

the class ResponseTimeMessageInInterceptorTest method testClientFaultMessageIn.

public void testClientFaultMessageIn(FaultMode faultMode) {
    // need to increase the counter and is a client
    setupCounterRepository(true, true);
    setupExchangeForMessage();
    setupOperationForMessage();
    EasyMock.expect(message.getExchange()).andReturn(exchange);
    EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE).anyTimes();
    EasyMock.expect(exchange.isOneWay()).andReturn(false);
    EasyMock.expect(exchange.get("org.apache.cxf.management.counter.enabled")).andReturn(true);
    exchange.put(FaultMode.class, faultMode);
    EasyMock.expectLastCall();
    EasyMock.expect(message.get(FaultMode.class)).andReturn(faultMode).anyTimes();
    EasyMock.expect(exchange.get(FaultMode.class)).andReturn(faultMode).anyTimes();
    EasyMock.expect(exchange.getOutMessage()).andReturn(message);
    MessageHandlingTimeRecorder mhtr = EasyMock.createMock(MessageHandlingTimeRecorder.class);
    mhtr.endHandling();
    EasyMock.expectLastCall();
    mhtr.setFaultMode(faultMode);
    EasyMock.expectLastCall();
    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 4 with FaultMode

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

the class AbstractFaultChainInitiatorObserver method onMessage.

public void onMessage(Message message) {
    assert null != message;
    Bus origBus = BusFactory.getAndSetThreadDefaultBus(bus);
    ClassLoaderHolder origLoader = null;
    try {
        if (loader != null) {
            origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
        }
        Exchange exchange = message.getExchange();
        Message faultMessage;
        if (isOutboundObserver()) {
            Exception ex = message.getContent(Exception.class);
            if (!(ex instanceof Fault)) {
                ex = new Fault(ex);
            }
            FaultMode mode = message.get(FaultMode.class);
            faultMessage = exchange.getOutMessage();
            if (null == faultMessage) {
                faultMessage = new MessageImpl();
                faultMessage.setExchange(exchange);
                faultMessage = exchange.getEndpoint().getBinding().createMessage(faultMessage);
            }
            faultMessage.setContent(Exception.class, ex);
            if (null != mode) {
                faultMessage.put(FaultMode.class, mode);
            }
            // CXF-3981
            if (message.get("javax.xml.ws.addressing.context.inbound") != null) {
                faultMessage.put("javax.xml.ws.addressing.context.inbound", message.get("javax.xml.ws.addressing.context.inbound"));
            }
            exchange.setOutMessage(null);
            exchange.setOutFaultMessage(faultMessage);
            if (message.get(BindingFaultInfo.class) != null) {
                faultMessage.put(BindingFaultInfo.class, message.get(BindingFaultInfo.class));
            }
        } else {
            faultMessage = message;
            exchange.setInMessage(null);
            exchange.setInFaultMessage(faultMessage);
        }
        // setup chain
        PhaseInterceptorChain chain = new PhaseInterceptorChain(getPhases());
        initializeInterceptors(faultMessage.getExchange(), chain);
        faultMessage.setInterceptorChain(chain);
        try {
            chain.doIntercept(faultMessage);
        } catch (RuntimeException exc) {
            LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
            throw exc;
        } catch (Exception exc) {
            LOG.log(Level.SEVERE, "ERROR_DURING_ERROR_PROCESSING", exc);
            throw new RuntimeException(exc);
        }
    } finally {
        if (origBus != bus) {
            BusFactory.setThreadDefaultBus(origBus);
        }
        if (origLoader != null) {
            origLoader.reset();
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) FaultMode(org.apache.cxf.message.FaultMode) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Message(org.apache.cxf.message.Message) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) MessageImpl(org.apache.cxf.message.MessageImpl) BindingFaultInfo(org.apache.cxf.service.model.BindingFaultInfo)

Example 5 with FaultMode

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

the class ClientFaultConverter method handleMessage.

public void handleMessage(Message msg) {
    Fault fault = (Fault) msg.getContent(Exception.class);
    if (fault.getDetail() != null && !MessageUtils.getContextualBoolean(msg, DISABLE_FAULT_MAPPING, false)) {
        processFaultDetail(fault, msg);
        setStackTrace(fault, msg);
    }
    FaultMode faultMode = FaultMode.UNCHECKED_APPLICATION_FAULT;
    // Check if the raised exception is declared in the WSDL or by the JAX-RS resource
    Method m = msg.getExchange().get(Method.class);
    if (m != null) {
        Exception e = msg.getContent(Exception.class);
        for (Class<?> cl : m.getExceptionTypes()) {
            if (cl.isInstance(e)) {
                faultMode = FaultMode.CHECKED_APPLICATION_FAULT;
                break;
            }
        }
    }
    msg.getExchange().put(FaultMode.class, faultMode);
}
Also used : FaultMode(org.apache.cxf.message.FaultMode) Method(java.lang.reflect.Method) XMLStreamException(javax.xml.stream.XMLStreamException)

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