Package org.mortbay.util.ajax

Examples of org.mortbay.util.ajax.Continuation


            if (consumer == null) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }

            final Continuation continuation = ContinuationSupport.getContinuation(request, null);
            if (continuation.isNew()) {

                // Have the camel process the HTTP exchange.
                final HttpExchange exchange = new HttpExchange(consumer.getEndpoint(), request, response);
                boolean sync = consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
                    public void done(boolean sync) {
                        if (sync) {
                            return;
                        }
                        continuation.setObject(exchange);
                        continuation.resume();
                    }
                });

                if (!sync) {
                    // Wait for the exchange to get processed.
                    // This might block until it completes or it might return via an exception and
                    // then this method is re-invoked once the the exchange has finished processing
                    continuation.suspend(0);
                }

                // HC: The getBinding() is interesting because it illustrates the
                // impedance miss-match between HTTP's stream oriented protocol, and
                // Camels more message oriented protocol exchanges.

                // now lets output to the response
                consumer.getBinding().writeResponse(exchange, response);
                return;
            }

            if (continuation.isResumed()) {
                HttpExchange exchange = (HttpExchange)continuation.getObject();
                // now lets output to the response
                consumer.getBinding().writeResponse(exchange, response);
                return;
            }
View Full Code Here


            if (consumer == null) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }

            final Continuation continuation = ContinuationSupport.getContinuation(request, null);
            if (continuation.isNew()) {

                // Have the camel process the HTTP exchange.
                final HttpExchange exchange = new HttpExchange(consumer.getEndpoint(), request, response);
               
                boolean sync = consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
                    public void done(boolean sync) {
                        if (sync) {
                            return;
                        }
                        continuation.setObject(exchange);
                        continuation.resume();
                    }
                });

                if (!sync) {
                    // Wait for the exchange to get processed.
                    // This might block until it completes or it might return via an exception and
                    // then this method is re-invoked once the the exchange has finished processing
                    continuation.suspend(0);
                }

                // HC: The getBinding() is interesting because it illustrates the
                // impedance miss-match between HTTP's stream oriented protocol, and
                // Camels more message oriented protocol exchanges.
               
                // set the header value from endpoint
                if (exchange.getOut().getHeader(Exchange.HTTP_CHUNKED) == null) {
                    exchange.getOut().setHeader(Exchange.HTTP_CHUNKED, consumer.getEndpoint().isChunked());
                }
               
                // now lets output to the response
                consumer.getBinding().writeResponse(exchange, response);
                return;
            }

            if (continuation.isResumed()) {
                HttpExchange exchange = (HttpExchange)continuation.getObject();
                // now lets output to the response
                consumer.getBinding().writeResponse(exchange, response);
                return;
            }
View Full Code Here

        return;
      }

      synchronized (queue.getActivationLock()) {
        if (wait) {
          final Continuation cont = ContinuationSupport.getContinuation(httpServletRequest, queue);
          if (!cont.isResumed() && !queue.messagesWaiting()) {
            queue.setActivationCallback(new JettyQueueActivationCallback(cont));
            cont.suspend(45 * 1000);
            return;
          }
        }

        pollQueue(queue, stream, httpServletResponse);
View Full Code Here

                }
               
                setCurrentConnection(this);
                long io=0;
               
                Continuation continuation = _request.getContinuation();
                if (continuation != null && continuation.isPending())
                {
                    Log.debug("resume continuation {}",continuation);
                    if (_request.getMethod()==null)
                        throw new IllegalStateException();
                    handleRequest();
                }
                else
                {
                    // If we are not ended then parse available
                    if (!_parser.isComplete())
                        io=_parser.parseAvailable();
                   
                    // Do we have more generating to do?
                    // Loop here because some writes may take multiple steps and
                    // we need to flush them all before potentially blocking in the
                    // next loop.
                    while (_generator.isCommitted() && !_generator.isComplete())
                    {
                        long written=_generator.flush();
                        io+=written;
                        if (written<=0)
                            break;
                        else if (_endp.isBufferingOutput())
                            _endp.flush();
                    }
                   
                    // Flush buffers
                    if (_endp.isBufferingOutput())
                    {
                        _endp.flush();
                        if (!_endp.isBufferingOutput())
                            no_progress=0;
                    }
                   
                    if (io>0)
                        no_progress=0;
                    else if (no_progress++>=2)
                        return;
                }
            }
            catch (HttpException e)
            {
                if (Log.isDebugEnabled())
                {
                    Log.debug("uri="+_uri);
                    Log.debug("fields="+_requestFields);
                    Log.debug(e);
                }
                _generator.sendError(e.getStatus(), e.getReason(), null, true);
               
                _parser.reset(true);
                _endp.close();
                throw e;
            }
            finally
            {
                setCurrentConnection(null);
               
                more_in_buffer = _parser.isMoreInBuffer() || _endp.isBufferingInput()
               
                synchronized(this)
                {
                    _handling=false;
                   
                    if (_destroy)
                    {
                        destroy();
                        return;
                    }
                }
               
                if (_parser.isComplete() && _generator.isComplete() && !_endp.isBufferingOutput())
                { 
                    if (!_generator.isPersistent())
                    {
                        _parser.reset(true);
                        more_in_buffer=false;
                    }
                   
                    reset(!more_in_buffer);
                    no_progress=0;
                }
               
                Continuation continuation = _request.getContinuation();
                if (continuation != null && continuation.isPending())
                {
                    break;
                }
                else if (_generator.isCommitted() && !_generator.isComplete() && _endp instanceof SelectChannelEndPoint) // TODO remove SelectChannel dependency
                    ((SelectChannelEndPoint)_endp).setWritable(false);
View Full Code Here

            if (consumer == null) {
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }

            final Continuation continuation = ContinuationSupport.getContinuation(request, null);
            if (continuation.isNew()) {

                // Have the camel process the HTTP exchange.
                final HttpExchange exchange = new HttpExchange(consumer.getEndpoint(), request, response);
                boolean sync = consumer.getAsyncProcessor().process(exchange, new AsyncCallback() {
                    public void done(boolean sync) {
                        if (sync) {
                            return;
                        }
                        continuation.setObject(exchange);
                        continuation.resume();
                    }
                });

                if (!sync) {
                    // Wait for the exchange to get processed.
                    // This might block until it completes or it might return via an exception and
                    // then this method is re-invoked once the the exchange has finished processing
                    continuation.suspend(0);
                }

                // HC: The getBinding() is interesting because it illustrates the
                // impedance miss-match between HTTP's stream oriented protocol, and
                // Camels more message oriented protocol exchanges.

                // now lets output to the response
                consumer.getBinding().writeResponse(exchange, response);
                return;
            }

            if (continuation.isResumed()) {
                HttpExchange exchange = (HttpExchange)continuation.getObject();
                // now lets output to the response
                consumer.getBinding().writeResponse(exchange, response);
                return;
            }
View Full Code Here

        httpContext = null;
        super.stop();
    }

    public void process(MessageExchange exchange) throws Exception {
        Continuation cont = locks.remove(exchange.getExchangeId());
        if (cont == null) {
            throw new Exception("HTTP request has timed out");
        }
        synchronized (cont) {
            if (logger.isDebugEnabled()) {
                logger.debug("Resuming continuation for exchange: " + exchange.getExchangeId());
            }
            exchanges.put(exchange.getExchangeId(), exchange);
            cont.resume();
        }
    }
View Full Code Here

            // Handle WSDLs, XSDs
            if (handleStaticResource(request, response)) {
                return;
            }
            // Not giving a specific mutex will synchronize on the continuation itself
            Continuation cont = ContinuationSupport.getContinuation(request, null);
            // If the continuation is not a retry
            if (!cont.isPending()) {
                exchange = createExchange(request);
                locks.put(exchange.getExchangeId(), cont);
                request.setAttribute(MessageExchange.class.getName(), exchange.getExchangeId());
                synchronized (cont) {
                    send(exchange);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Suspending continuation for exchange: " + exchange.getExchangeId());
                    }
                    long to = this.timeout;
                    if (to == 0) {
                        to = ((HttpComponent) getServiceUnit().getComponent()).getConfiguration()
                                            .getConsumerProcessorSuspendTime();
                    }
                    boolean result = cont.suspend(to);
                    exchanges.remove(exchange.getExchangeId());
                    if (!result) {
                        locks.remove(exchange.getExchangeId());
                        throw new Exception("Exchange timed out");
                    }
                    request.removeAttribute(MessageExchange.class.getName());
                }
                return;
            } else {
                String id = (String) request.getAttribute(MessageExchange.class.getName());
                locks.remove(id);
                exchange = exchanges.remove(id);
                request.removeAttribute(MessageExchange.class.getName());
                boolean result = cont.suspend(0);
                // Check if this is a timeout
                if (exchange == null) {
                    throw new IllegalStateException("Exchange not found");
                }
                if (!result) {
View Full Code Here

    public String getAuthMethod() {
        return this.endpoint.getAuthMethod();
    }
   
    public void process(MessageExchange exchange) throws Exception {
        Continuation cont = locks.remove(exchange.getExchangeId());
        if (cont != null) {
            synchronized (cont) {
                if (log.isDebugEnabled()) {
                    log.debug("Resuming continuation for exchange: " + exchange.getExchangeId());
                }
                exchanges.put(exchange.getExchangeId(), exchange);
                cont.resume();
            }
        } else {
            throw new IllegalStateException("Exchange not found");
        }
    }
View Full Code Here

        if (!"POST".equals(request.getMethod())) {
            response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request.getMethod() + " not supported");
            return;
        }
        // Not giving a specific mutex will synchronize on the contination itself
        Continuation cont = ContinuationSupport.getContinuation(request, null);
        MessageExchange exchange;
        // If the continuation is not a retry
        if (!cont.isPending()) {
            try {
                SoapMessage message = soapHelper.getSoapMarshaler().createReader().read(
                                            request.getInputStream(),
                                            request.getHeader(HEADER_CONTENT_TYPE));
                Context ctx = soapHelper.createContext(message);
                if (request.getUserPrincipal() != null) {
                    if (request.getUserPrincipal() instanceof JaasJettyPrincipal) {
                        Subject subject = ((JaasJettyPrincipal) request.getUserPrincipal()).getSubject();
                        ctx.getInMessage().setSubject(subject);
                    } else {
                        ctx.getInMessage().addPrincipal(request.getUserPrincipal());
                    }
                }
                request.setAttribute(Context.class.getName(), ctx);
                exchange = soapHelper.onReceive(ctx);
                NormalizedMessage inMessage = exchange.getMessage("in");
                if (getConfiguration().isWantHeadersFromHttpIntoExchange()) {
                    inMessage.setProperty(JbiConstants.PROTOCOL_HEADERS, getHeaders(request));
                }
                locks.put(exchange.getExchangeId(), cont);
                request.setAttribute(MessageExchange.class.getName(), exchange.getExchangeId());
                synchronized (cont) {
                    channel.send(exchange);
                    if (log.isDebugEnabled()) {
                        log.debug("Suspending continuation for exchange: " + exchange.getExchangeId());
                    }
                    boolean result = cont.suspend(suspentionTime);
                    exchanges.remove(exchange.getExchangeId());
                    if (!result) {
                        throw new Exception("Error sending exchange: aborted");
                    }
                    request.removeAttribute(MessageExchange.class.getName());
                }
            } catch (RetryRequest retry) {
                throw retry;
            } catch (SoapFault fault) {
                sendFault(fault, request, response);
                return;
            } catch (Exception e) {
                SoapFault fault = new SoapFault(e);
                sendFault(fault, request, response);
                return;
            }
        } else {
            String id = (String) request.getAttribute(MessageExchange.class.getName());
            exchange = exchanges.remove(id);
            request.removeAttribute(MessageExchange.class.getName());
            boolean result = cont.suspend(0);
            // Check if this is a timeout
            if (exchange == null) {
                throw new IllegalStateException("Exchange not found");
            }
            if (!result) {
View Full Code Here

            {
                long timeout=client.getTimeout();
                if (timeout < 0)
                    timeout=_bayeux.getTimeout();

                Continuation continuation=ContinuationSupport.getContinuation(request,client);

                // Get messages or wait
                synchronized(client)
                {
                    if (timeout > 0 && !client.hasNonLazyMessages() && initial && received <= 1)
                    {
                        // save state and suspend
                        request.setAttribute(CLIENT_ATTR,client);
                        request.setAttribute(TRANSPORT_ATTR,transport);
                        client.setContinuation(continuation);
                        continuation.setObject(response);
                        continuation.suspend(timeout);
                    }

                    continuation.reset();
                }

                client.setContinuation(null);
                transport.setMetaConnectReply(null);
            }
View Full Code Here

TOP

Related Classes of org.mortbay.util.ajax.Continuation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.