Package org.eclipse.jetty.server

Examples of org.eclipse.jetty.server.Request


    protected void serviceRequest(final ServletContext context,
                                  final HttpServletRequest req,
                                  final HttpServletResponse resp)
        throws IOException {
        Request baseRequest = (req instanceof Request)
            ? (Request)req : getCurrentRequest();
       
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Service http request on thread: " + Thread.currentThread());
        }
        Message inMessage = retrieveFromContinuation(req);
       
        if (inMessage == null) {
           
            inMessage = new MessageImpl();
            setupMessage(inMessage, context, req, resp);
           
            ((MessageImpl)inMessage).setDestination(this);
   
            ExchangeImpl exchange = new ExchangeImpl();
            exchange.setInMessage(inMessage);
            exchange.setSession(new HTTPSession(req));
        }
       
        try {   
            incomingObserver.onMessage(inMessage);
            resp.flushBuffer();
            baseRequest.setHandled(true);
        } catch (SuspendedInvocationException ex) {
            if (ex.getRuntimeException() != null) {
                throw ex.getRuntimeException();
            }
            //else nothing to do
View Full Code Here


        // get the current, previously active connection if one exists
        AbstractHttpConnection conn = AbstractHttpConnection
                .getCurrentConnection();

        // Identify the effective server name for this request
        Request parentRequest = (conn == null ? null : conn.getRequest());
        String host = (parentRequest == null ? "localhost:" + port //
                : parentRequest.getHeader("Host"));

        // construct an HTTP request for this data
        StringBuilder requestHeader = new StringBuilder();
        requestHeader.append("GET ").append(uri).append(" HTTP/1.0\r\n")
                .append("Host: ").append(host).append("\r\n")
View Full Code Here

            LocalEndPoint endPoint = new LocalEndPoint(_requestsBuffer,
                    _parentRequest);

            HttpConnection connection = new HttpConnection(endPoint,
                    getServer());
            Request request = connection.getRequest();
            request.setAttribute(PARENT_REQUEST_KEY, _parentRequest);
            request.setAttribute(EXTRA_ENVIRONMENT_KEY, _extraEnv);
            endPoint.setConnection(connection);
            connectionOpened(connection);

            boolean leaveOpen = _keepOpen;
            try {
                while (endPoint.getIn().length() > 0 && endPoint.isOpen()) {
                    while (true) {
                        final Connection con = endPoint.getConnection();
                        final Connection next = con.handle();
                        if (next != con) {
                            endPoint.setConnection(next);
                            continue;
                        }
                        break;
                    }
                }
            } catch (IOException x) {
                LOG.debug(x);
                leaveOpen = false;
            } catch (Exception x) {
                LOG.warn(x);
                leaveOpen = false;
            } finally {
                if (!leaveOpen)
                    connectionClosed(connection);
                if (_parentRequest != null)
                    connection.resetCurrentConnection(_parentRequest
                            .getConnection());
                _responsesBuffer = endPoint.getOut();
            }


            Throwable t = (Throwable) request
                    .getAttribute(RequestDispatcher.ERROR_EXCEPTION);
            int status = connection.getResponse().getStatus();
            if (t instanceof IOException) {
                _exception = (IOException) t;
            } else if (t != null) {
                _exception = new IOException(t);
            } else if (status == 404) {
                _exception = new FileNotFoundException(request.getRequestURI());
            } else if ((status / 100) != 2) {
                _exception = new IOException("HTTP response code " + status
                        + ": \"" + connection.getResponse().getReason() + "\"");
            }
View Full Code Here

                .getAttribute(LocalConnector.EXTRA_ENVIRONMENT_KEY);
        if (extraEnv != null)
            env.putAll(extraEnv);

        // store all values from the server default environment.
        Request baseRequest = Request.getRequest(req);
        Map defaultEnv = (Map) baseRequest.getConnection().getServer()
                .getAttribute(WebServer.DEFAULT_ENV_KEY);
        env.putAll(defaultEnv);

        // store the method, and protocol from the original request
        env.put("REQUEST_METHOD", req.getMethod());
        env.put("SERVER_PROTOCOL", req.getProtocol());

        // store the portion of the request URI that names the target resource
        String scriptName = req.getServletPath();
        if (req.getPathInfo() != null)
            scriptName += req.getPathInfo();
        env.put("SCRIPT_NAME", scriptName);
        env.put("SCRIPT_PATH", req.getRequestURI());

        // store information about the hierarchy prefix used on the request
        PDashContext dash = getContext(req);
        String uriPrefix = dash.getUriPrefix();
        if (uriPrefix != null && uriPrefix.endsWith("/")) {
            env.put("PATH_INFO", uriPrefix.substring(0, uriPrefix.length() - 1));
        } else {
            env.put("PATH_INFO", "");
        }
        env.put("PATH_TRANSLATED", dash.getProjectPath());
        env.put("REQUEST_URI", uriPrefix + baseRequest.getUri());

        // store the query string, if one was present
        String queryString = req.getQueryString();
        if (queryString != null && queryString.length() > 0)
            env.put("QUERY_STRING", queryString);
View Full Code Here

        String prefix = getPrefix(request);
        if (prefix == null) {
            chain.doFilter(request, response);

        } else {
            Request req = Request.getRequest((HttpServletRequest) request);
            String origRequestURI = req.getRequestURI();
            String origContextPath = req.getContextPath();

            String fullRequestURI = prefix + origRequestURI;
            String fullContextPath = prefix + origContextPath;
            try {
                req.setRequestURI(fullRequestURI);
                req.setContextPath(fullContextPath);
                chain.doFilter(request, response);
            } finally {
                req.setRequestURI(origRequestURI);
                req.setContextPath(origContextPath);
            }
        }
    }
View Full Code Here

                             HttpServletRequest req,
                             HttpServletResponse resp) throws IOException {
        if (context == null) {
            context = servletContext;
        }
        Request baseRequest = (req instanceof Request)
            ? (Request)req : getCurrentRequest();
           
        if (!"HEAD".equals(req.getMethod())) {
            //bug in Jetty with persistent connections that if a HEAD is
            //sent, a _head flag is never reset
            AbstractConnection c = getConnectionForRequest(baseRequest);
            if (c != null) {
                setHeadFalse(c);
            }
        }
        if (getServer().isSetRedirectURL()) {
            resp.sendRedirect(getServer().getRedirectURL());
            resp.flushBuffer();
            baseRequest.setHandled(true);
            return;
        }
        QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);
       
        if (null != req.getQueryString() && queryHandlerRegistry != null) {  
            String reqAddr = req.getRequestURL().toString();
            String requestURL =  reqAddr + "?" + req.getQueryString();
            String pathInfo = req.getPathInfo();                    
            for (QueryHandler qh : queryHandlerRegistry.getHandlers()) {
                boolean recognized =
                    qh instanceof StemMatchingQueryHandler
                    ? ((StemMatchingQueryHandler)qh).isRecognizedQuery(requestURL,
                                                                       pathInfo,
                                                                       endpointInfo,
                                                                       contextMatchOnExact())
                    : qh.isRecognizedQuery(requestURL, pathInfo, endpointInfo);
                if (recognized) {
                    //replace the endpointInfo address with request url only for get wsdl
                    String errorMsg = null;
                    CachedOutputStream out = new CachedOutputStream();
                    try {
                        synchronized (endpointInfo) {
                            String oldAddress = updateEndpointAddress(reqAddr);  
                            resp.setContentType(qh.getResponseContentType(requestURL, pathInfo));
                            try {
                                qh.writeResponse(requestURL, pathInfo, endpointInfo, out);
                            } catch (Exception ex) {
                                LOG.log(Level.WARNING, "writeResponse failed: ", ex);
                                errorMsg = ex.getMessage();
                            }
                            endpointInfo.setAddress(oldAddress);
                        }
                        if (errorMsg != null) {
                            resp.sendError(500, errorMsg);
                        } else {
                            out.writeCacheTo(resp.getOutputStream());
                            resp.getOutputStream().flush();                    
                        }
                    } finally {
                        out.close();
                    }
                    baseRequest.setHandled(true);
                    return;
                }
            }
        }
View Full Code Here

    protected void serviceRequest(final ServletContext context,
                                  final HttpServletRequest req,
                                  final HttpServletResponse resp)
        throws IOException {
        Request baseRequest = (req instanceof Request)
            ? (Request)req : getCurrentRequest();
       
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Service http request on thread: " + Thread.currentThread());
        }
        Message inMessage = retrieveFromContinuation(req);
       
        if (inMessage == null) {
           
            inMessage = new MessageImpl();
            setupMessage(inMessage, context, req, resp);
           
            ((MessageImpl)inMessage).setDestination(this);
   
            ExchangeImpl exchange = new ExchangeImpl();
            exchange.setInMessage(inMessage);
            exchange.setSession(new HTTPSession(req));
        }
       
        try {   
            incomingObserver.onMessage(inMessage);
            resp.flushBuffer();
            baseRequest.setHandled(true);
        } catch (SuspendedInvocationException ex) {
            if (ex.getRuntimeException() != null) {
                throw ex.getRuntimeException();
            }
            //else nothing to do
View Full Code Here

                             HttpServletRequest req,
                             HttpServletResponse resp) throws IOException {
        if (context == null) {
            context = servletContext;
        }
        Request baseRequest = (req instanceof Request)
            ? (Request)req : HttpConnection.getCurrentConnection().getRequest();
           
        if (!"HEAD".equals(req.getMethod())) {
            //bug in Jetty with persistent connections that if a HEAD is
            //sent, a _head flag is never reset
            HttpConnection c = baseRequest.getConnection();
            if (c != null) {
                c.getGenerator().setHead(false);
            }
        }
        if (getServer().isSetRedirectURL()) {
            resp.sendRedirect(getServer().getRedirectURL());
            resp.flushBuffer();
            baseRequest.setHandled(true);
            return;
        }
        QueryHandlerRegistry queryHandlerRegistry = bus.getExtension(QueryHandlerRegistry.class);
       
        if (null != req.getQueryString() && queryHandlerRegistry != null) {  
            String reqAddr = req.getRequestURL().toString();
            String requestURL =  reqAddr + "?" + req.getQueryString();
            String pathInfo = req.getPathInfo();                    
            for (QueryHandler qh : queryHandlerRegistry.getHandlers()) {
                boolean recognized =
                    qh instanceof StemMatchingQueryHandler
                    ? ((StemMatchingQueryHandler)qh).isRecognizedQuery(requestURL,
                                                                       pathInfo,
                                                                       endpointInfo,
                                                                       contextMatchOnExact())
                    : qh.isRecognizedQuery(requestURL, pathInfo, endpointInfo);
                if (recognized) {
                    //replace the endpointInfo address with request url only for get wsdl
                    String errorMsg = null;
                    CachedOutputStream out = new CachedOutputStream();
                    try {
                        synchronized (endpointInfo) {
                            String oldAddress = updateEndpointAddress(reqAddr);  
                            resp.setContentType(qh.getResponseContentType(requestURL, pathInfo));
                            try {
                                qh.writeResponse(requestURL, pathInfo, endpointInfo, out);
                            } catch (Exception ex) {
                                LOG.log(Level.WARNING, "writeResponse failed: ", ex);
                                errorMsg = ex.getMessage();
                            }
                            endpointInfo.setAddress(oldAddress);
                        }
                        if (errorMsg != null) {
                            resp.sendError(500, errorMsg);
                        } else {
                            out.writeCacheTo(resp.getOutputStream());
                            resp.getOutputStream().flush();                    
                        }
                    } finally {
                        out.close();
                    }
                    baseRequest.setHandled(true);
                    return;
                }
            }
        }
View Full Code Here

    protected void serviceRequest(final ServletContext context,
                                  final HttpServletRequest req,
                                  final HttpServletResponse resp)
        throws IOException {
        Request baseRequest = (req instanceof Request)
            ? (Request)req : HttpConnection.getCurrentConnection().getRequest();
       
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Service http request on thread: " + Thread.currentThread());
        }
        Message inMessage = retrieveFromContinuation(req);
       
        if (inMessage == null) {
           
            inMessage = new MessageImpl();
            setupMessage(inMessage, context, req, resp);
           
            ((MessageImpl)inMessage).setDestination(this);
   
            ExchangeImpl exchange = new ExchangeImpl();
            exchange.setInMessage(inMessage);
            exchange.setSession(new HTTPSession(req));
        }
       
        try {   
            incomingObserver.onMessage(inMessage);
            resp.flushBuffer();
            baseRequest.setHandled(true);
        } catch (SuspendedInvocationException ex) {
            if (ex.getRuntimeException() != null) {
                throw ex.getRuntimeException();
            }
            //else nothing to do
View Full Code Here

     */
    public void handle(String target, Request arg1,
            HttpServletRequest servletRequest,
            HttpServletResponse servletResponse) throws IOException,
            ServletException {
        final Request baseRequest = (servletRequest instanceof Request) ? (Request) servletRequest
                : HttpConnection.getCurrentConnection().getRequest();
        this.helper.handle(new JettyCall(this.helper.getHelped(),
                HttpConnection.getCurrentConnection()));
        baseRequest.setHandled(true);
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jetty.server.Request

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.