Search in sources :

Example 1 with JMSContinuationProvider

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();
        }
    }
}
Also used : Bus(org.apache.cxf.Bus) JMSContinuationProvider(org.apache.cxf.transport.jms.continuations.JMSContinuationProvider) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) Message(org.apache.cxf.message.Message) SecurityContext(org.apache.cxf.security.SecurityContext) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JMSContinuationProvider(org.apache.cxf.transport.jms.continuations.JMSContinuationProvider) JMSException(javax.jms.JMSException) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) MessageImpl(org.apache.cxf.message.MessageImpl)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 JMSException (javax.jms.JMSException)1 Bus (org.apache.cxf.Bus)1 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)1 ContinuationProvider (org.apache.cxf.continuations.ContinuationProvider)1 SuspendedInvocationException (org.apache.cxf.continuations.SuspendedInvocationException)1 Message (org.apache.cxf.message.Message)1 MessageImpl (org.apache.cxf.message.MessageImpl)1 SecurityContext (org.apache.cxf.security.SecurityContext)1 JMSContinuationProvider (org.apache.cxf.transport.jms.continuations.JMSContinuationProvider)1