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);
}
}
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());
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations