use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.
the class JAXWSHttpSpiDestination method serviceRequest.
protected void serviceRequest(final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Service http request on thread: " + Thread.currentThread());
}
Message inMessage = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
exchange.setInMessage(inMessage);
setupMessage(inMessage, null, req.getServletContext(), req, resp);
((MessageImpl) inMessage).setDestination(this);
exchange.setSession(new HTTPSession(req));
try {
incomingObserver.onMessage(inMessage);
resp.flushBuffer();
} catch (SuspendedInvocationException ex) {
if (ex.getRuntimeException() != null) {
throw ex.getRuntimeException();
}
// else nothing to do
} catch (Fault ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
throw ex;
} catch (RuntimeException ex) {
throw ex;
} finally {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
}
}
}
use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.
the class DestinationSequence method waitInQueue.
synchronized boolean waitInQueue(long mn, boolean canSkip, Message message, Continuation continuation) {
while (true) {
// can process now if no other in process and this one is next
if (inProcessNumber == 0) {
long diff = mn - highNumberCompleted;
if (diff == 1 || (canSkip && diff > 0)) {
inProcessNumber = mn;
return true;
}
}
// can abort now if same message in process or already processed
if (mn == inProcessNumber || isAcknowledged(mn)) {
return false;
}
if (continuation == null) {
ContinuationProvider p = message.get(ContinuationProvider.class);
if (p != null) {
boolean isOneWay = message.getExchange().isOneWay();
message.getExchange().setOneWay(false);
continuation = p.getContinuation();
message.getExchange().setOneWay(isOneWay);
message.put(Continuation.class, continuation);
}
}
if (continuation != null) {
continuation.setObject(message);
if (continuation.suspend(-1)) {
continuations.put(mn, continuation);
throw new SuspendedInvocationException();
}
}
try {
// if we get here, there isn't a continuation available
// so we need to block/wait
wait();
} catch (InterruptedException ie) {
// ignore
}
}
}
use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.
the class JMSDestination method onMessage.
/**
* Convert JMS message received by ListenerThread to CXF message and inform incomingObserver that a
* message was received. The observer will call the service and then send the response CXF message by
* using the BackChannelConduit
*
* @param message
* @throws IOException
*/
public void onMessage(javax.jms.Message message) {
ClassLoaderHolder origLoader = null;
Bus origBus = null;
try {
if (loader != null) {
origLoader = ClassLoaderUtils.setThreadContextClassloader(loader);
}
getLogger().log(Level.FINE, "JMS destination received message " + message + " on " + jmsConfig.getTargetDestination());
Message inMessage = JMSMessageUtils.asCXFMessage(message, JMSConstants.JMS_SERVER_REQUEST_HEADERS);
if (jmsConfig.isCreateSecurityContext()) {
SecurityContext securityContext = SecurityContextFactory.buildSecurityContext(message, jmsConfig);
inMessage.put(SecurityContext.class, securityContext);
}
inMessage.put(JMSConstants.JMS_SERVER_RESPONSE_HEADERS, new JMSMessageHeadersType());
inMessage.put(JMSConstants.JMS_REQUEST_MESSAGE, message);
((MessageImpl) inMessage).setDestination(this);
if (jmsConfig.getMaxSuspendedContinuations() != 0) {
JMSContinuationProvider cp = new JMSContinuationProvider(bus, inMessage, incomingObserver, suspendedContinuations);
inMessage.put(ContinuationProvider.class.getName(), cp);
}
origBus = BusFactory.getAndSetThreadDefaultBus(bus);
// handle the incoming message
incomingObserver.onMessage(inMessage);
if (inMessage.getExchange() != null) {
processExceptions(inMessage.getExchange());
}
} catch (SuspendedInvocationException ex) {
getLogger().log(Level.FINE, "Request message has been suspended");
} catch (UnsupportedEncodingException ex) {
getLogger().log(Level.WARNING, "can't get the right encoding information. " + ex);
} catch (JMSException e) {
throw JMSUtil.convertJmsException(e);
} finally {
if (origBus != bus) {
BusFactory.setThreadDefaultBus(origBus);
}
if (origLoader != null) {
origLoader.reset();
}
}
}
use of org.apache.cxf.continuations.SuspendedInvocationException in project cxf by apache.
the class AbstractHTTPDestination method invoke.
public void invoke(final ServletConfig config, final ServletContext context, final HttpServletRequest req, final HttpServletResponse resp) throws IOException {
Message inMessage = retrieveFromContinuation(req);
if (inMessage == null) {
LOG.fine("Create a new message for processing");
inMessage = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
exchange.setInMessage(inMessage);
setupMessage(inMessage, config, context, req, resp);
exchange.setSession(new HTTPSession(req));
((MessageImpl) inMessage).setDestination(this);
} else {
LOG.fine("Get the message from the request for processing");
}
copyKnownRequestAttributes(req, inMessage);
try {
incomingObserver.onMessage(inMessage);
invokeComplete(context, req, resp, inMessage);
} catch (SuspendedInvocationException ex) {
if (ex.getRuntimeException() != null) {
throw ex.getRuntimeException();
}
// else nothing to do, just finishing the processing
} catch (Fault ex) {
Throwable cause = ex.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
}
throw ex;
} catch (RuntimeException ex) {
throw ex;
} finally {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Finished servicing http request on thread: " + Thread.currentThread());
}
}
}
Aggregations