use of org.apache.cxf.transport.jms.continuations.JMSContinuationProvider 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();
}
}
}
Aggregations