Search in sources :

Example 6 with SuspendedInvocationException

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());
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) HTTPSession(org.apache.cxf.transport.http.HTTPSession) Fault(org.apache.cxf.interceptor.Fault) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 7 with SuspendedInvocationException

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
        }
    }
}
Also used : ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException)

Example 8 with SuspendedInvocationException

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

Example 9 with SuspendedInvocationException

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());
        }
    }
}
Also used : Message(org.apache.cxf.message.Message) Fault(org.apache.cxf.interceptor.Fault) SuspendedInvocationException(org.apache.cxf.continuations.SuspendedInvocationException) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

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