Search in sources :

Example 1 with SuspendedInvocationException

use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.

the class PhaseInterceptorChain method doIntercept.

/**
 * Intercept a message, invoking each phase's handlers in turn.
 *
 * @param message the message
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public synchronized boolean doIntercept(Message message) {
    updateIterator();
    Message oldMessage = CURRENT_MESSAGE.get();
    try {
        CURRENT_MESSAGE.set(message);
        if (oldMessage != null && !message.containsKey(PREVIOUS_MESSAGE) && message != oldMessage && message.getExchange() != oldMessage.getExchange()) {
            message.put(PREVIOUS_MESSAGE, new WeakReference<Message>(oldMessage));
        }
        while (state == State.EXECUTING && iterator.hasNext()) {
            try {
                Interceptor<Message> currentInterceptor = (Interceptor<Message>) iterator.next();
                if (isFineLogging) {
                    LOG.fine("Invoking handleMessage on interceptor " + currentInterceptor);
                }
                // System.out.println("-----------" + currentInterceptor);
                currentInterceptor.handleMessage(message);
                if (state == State.SUSPENDED) {
                    // throw the exception to make sure thread exit without interrupt
                    throw new SuspendedInvocationException();
                }
            } catch (SuspendedInvocationException ex) {
                // Moving the chain iterator to the previous interceptor is needed
                // for the invocation to be resumed from the same interceptor which
                // suspended the invocation.
                // If "suspend.chain.on.current.interceptor" is set to true then
                // the chain will be resumed from the interceptor which follows
                // the interceptor which suspended the invocation.
                Object suspendProp = message.remove("suspend.chain.on.current.interceptor");
                if ((suspendProp == null || PropertyUtils.isFalse(suspendProp)) && iterator.hasPrevious()) {
                    iterator.previous();
                }
                pause();
                throw ex;
            } catch (RuntimeException ex) {
                if (!faultOccurred) {
                    faultOccurred = true;
                    wrapExceptionAsFault(message, ex);
                }
                state = State.ABORTED;
            }
        }
        if (state == State.EXECUTING) {
            state = State.COMPLETE;
        }
        return state == State.COMPLETE;
    } finally {
        CURRENT_MESSAGE.set(oldMessage);
    }
}
Also used : Message(org.apache.cxf.message.Message) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) Interceptor(org.apache.cxf.interceptor.Interceptor) ServiceInvokerInterceptor(org.apache.cxf.interceptor.ServiceInvokerInterceptor)

Example 2 with SuspendedInvocationException

use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.

the class JAXWSMethodInvokerTest method testSuspendedException.

@Test
public void testSuspendedException() throws Throwable {
    Exception originalException = new RuntimeException();
    ContinuationService serviceObject = new ContinuationService(originalException);
    Method serviceMethod = ContinuationService.class.getMethod("invoke", new Class[] {});
    Exchange ex = new ExchangeImpl();
    Message inMessage = new MessageImpl();
    ex.setInMessage(inMessage);
    inMessage.setExchange(ex);
    inMessage.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
    JAXWSMethodInvoker jaxwsMethodInvoker = prepareJAXWSMethodInvoker(ex, serviceObject, serviceMethod);
    try {
        jaxwsMethodInvoker.invoke(ex, new MessageContentsList(new Object[] {}));
        fail("Suspended invocation swallowed");
    } catch (SuspendedInvocationException suspendedEx) {
        assertSame(suspendedEx, serviceObject.getSuspendedException());
        assertSame(originalException, suspendedEx.getRuntimeException());
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) MessageContentsList(org.apache.cxf.message.MessageContentsList) Method(java.lang.reflect.Method) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) MessageImpl(org.apache.cxf.message.MessageImpl) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 3 with SuspendedInvocationException

use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.

the class JettyHTTPDestinationTest method testSuspendedException.

@Test
public void testSuspendedException() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    final RuntimeException ex = new RuntimeException();
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            throw new SuspendedInvocationException(ex);
        }
    };
    destination.setMessageObserver(observer);
    try {
        destination.doService(request, response);
        fail("Suspended invocation swallowed");
    } catch (RuntimeException runtimeEx) {
        assertSame("Original exception is not preserved", ex, runtimeEx);
    }
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) Test(org.junit.Test)

Example 4 with SuspendedInvocationException

use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.

the class NettyHttpDestinationTest method testSuspendedException.

@Test
public void testSuspendedException() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    final RuntimeException ex = new RuntimeException();
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            throw new SuspendedInvocationException(ex);
        }
    };
    destination.setMessageObserver(observer);
    try {
        destination.doService(request, response);
        fail("Suspended invocation swallowed");
    } catch (RuntimeException runtimeEx) {
        assertSame("Original exception is not preserved", ex, runtimeEx);
    }
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) Test(org.junit.Test)

Example 5 with SuspendedInvocationException

use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.

the class UndertowHTTPDestinationTest method testSuspendedException.

@Test
public void testSuspendedException() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    final RuntimeException ex = new RuntimeException();
    observer = new MessageObserver() {

        public void onMessage(Message m) {
            throw new SuspendedInvocationException(ex);
        }
    };
    destination.setMessageObserver(observer);
    try {
        destination.doService(request, response);
        fail("Suspended invocation swallowed");
    } catch (RuntimeException runtimeEx) {
        assertSame("Original exception is not preserved", ex, runtimeEx);
    }
}
Also used : MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) Test(org.junit.Test)

Aggregations

SuspendedInvocationException (org.apache.cxf.continuations.SuspendedInvocationException)9 Message (org.apache.cxf.message.Message)8 MessageImpl (org.apache.cxf.message.MessageImpl)4 Test (org.junit.Test)4 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)3 MessageObserver (org.apache.cxf.transport.MessageObserver)3 ContinuationProvider (org.apache.cxf.continuations.ContinuationProvider)2 Fault (org.apache.cxf.interceptor.Fault)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Method (java.lang.reflect.Method)1 JMSException (javax.jms.JMSException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Bus (org.apache.cxf.Bus)1 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)1 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)1 Interceptor (org.apache.cxf.interceptor.Interceptor)1 ServiceInvokerInterceptor (org.apache.cxf.interceptor.ServiceInvokerInterceptor)1 Exchange (org.apache.cxf.message.Exchange)1 MessageContentsList (org.apache.cxf.message.MessageContentsList)1