Package org.apache.coyote.tomcat4

Examples of org.apache.coyote.tomcat4.CoyoteRequest


        return sess;
    }
   
    private void resetSession(HttpServletRequest servletReq,
            Session sess) {
        CoyoteRequest coyoteRequest = this.getCoyoteRequest(servletReq);
        coyoteRequest.setSession(sess);
    }
View Full Code Here


     *
     * (Doing instanceof in a loop will impact performance)
     */
    private CoyoteRequest getCoyoteRequest(ServletRequest request) {

        CoyoteRequest coyoteRequest = null;
        Object current = request;
        while (current != null) {
            // When we run into the original request object, return it
            if (current instanceof CoyoteRequestFacade) {
                coyoteRequest = ((CoyoteRequestFacade)current).getUnwrappedCoyoteRequest();
View Full Code Here

        if ( fileCache == null && handlerCode != Handler.RESPONSE_PROCEEDED){
             return Handler.CONTINUE; 
        }
   
        if ( handlerCode == Handler.RESPONSE_PROCEEDED ){           
            CoyoteRequest cr =
                (CoyoteRequest)request.getNote(CoyoteAdapter.ADAPTER_NOTES);
           
            if ( cr != null && cr.getWrapper() != null){

                String mappedServlet = cr.getWrapper().getName();
               
                if ( !mappedServlet.equals(FileCache.DEFAULT_SERVLET_NAME) )
                    return Handler.CONTINUE;
               
                if ( cr.getContext().findConstraints().length == 0 ){
                   
                    if (!fileCache.isEnabled()) return Handler.CONTINUE;
                   
                    String docroot;
                    if ( cr.getContextPath().equals("") ){
                        docroot = cr.getContext().getDocBase();
                    } else {
                        docroot = SelectorThread.getWebAppRootPath();
                    }               
                    String requestURI = cr.getRequestURI();
                    Response response = cr.getCoyoteRequest().getResponse()
                    MimeHeaders headers = response.getMimeHeaders();
                    boolean xPoweredBy = (
                            (CoyoteConnector)cr.getConnector()).isXpoweredBy();

                    fileCache.add(mappedServlet,docroot,requestURI,headers,
                            xPoweredBy);
                }
            }      
View Full Code Here

        if ( fileCache == null && handlerCode != Handler.RESPONSE_PROCEEDED){
             return Handler.CONTINUE; 
        }
       
        if ( handlerCode == Handler.RESPONSE_PROCEEDED ){
            CoyoteRequest cr =
                (CoyoteRequest)request.getNote(CoyoteAdapter.ADAPTER_NOTES);
            // We can cache it only if no security constraint and no
            // filter have been defined.
            if ( cr != null && cr.getWrapper() != null){

                String mappedServlet = cr.getWrapper().getName();
               
                if ( !mappedServlet.equals(FileCache.DEFAULT_SERVLET_NAME) )
                    return Handler.CONTINUE;
               
                if ( cr.getContext().findConstraints().length == 0 ){

                    if (!fileCache.isEnabled()) return Handler.CONTINUE; 
                   
                    String docroot;
                    if ( cr.getContextPath().equals("") ){
                        docroot = cr.getContext().getDocBase();
                    } else {
                        docroot = SelectorThread.getWebAppRootPath();
                    }
                    String requestURI = cr.getRequestURI();
                    Response response = cr.getCoyoteRequest().getResponse()
                    MimeHeaders headers = response.getMimeHeaders();
                    boolean xPoweredBy = (
                            (CoyoteConnector)cr.getConnector()).isXpoweredBy();

                    fileCache.add(mappedServlet,docroot,requestURI,headers,
                            xPoweredBy);
                }
            }      
View Full Code Here

        if (!context.getCookies()) {
            // cookies have been disabled
            return;
        }

        CoyoteRequest request = (CoyoteRequest) response.getRequest();
        if (request == null) {
            return;
        }

        Session sess = request.getSessionInternal(false);
        if (sess == null) {
            // No active session
            return;
        }

        Cookie cookie = null;
        String value = request.getHeader(Constants.PROXY_BEROUTE_HEADER);
        if (value != null) {
            cookie = new Cookie(Constants.BEROUTE, value);
        } else {
            value = request.getHeader(Constants.PROXY_BEKEY_HEADER);
            if (value != null) {
                cookie = new Cookie(Constants.BEKEY, value);
            }
        }

        if (cookie != null) {
            request.configureSessionCookie(cookie);
            response.addCookie(cookie);
        }
    }
View Full Code Here

        // Obtain a connection from the connection pool for this host.
        HttpConnection connection = getConnection(host);

        // GLASSFISH Request/Response does not extend HttpServletRequest/Respose
        // Therefore we need to cast to CoyoteRequest/Response
        CoyoteRequest cRequest = (CoyoteRequest) request;

        if (connection == null) {
            // No connection could be obtained, so respond with 503 Service
            // Unavailable
            if (log.isLoggable(Level.FINE)) {
                log.log(Level.FINE,
                    "No connection could be obtained within the " +
                    "configured time limit when proxying the request '" +
                    cRequest.getRequestURL() + "' to '" + host + "'.");
            }

            ((CoyoteResponse) response).sendError(CoyoteResponse.SC_SERVICE_UNAVAILABLE);

            return;
        }

        if (log.isLoggable(Level.FINER)) {
            log.log(Level.FINER, "The proxy obtained a connection: " +
                connection);
        }

        try {
            // Proxy the request and retry if necessary.
            if (log.isLoggable(Level.FINE)) {
                log.log(Level.FINE,
                    "Proxying the request '" + cRequest.getMethod() + " " +
                    cRequest.getRequestURI() + "' to '" + host +
                    "' over the connection '" + connection + "'.");
            }

            do {
                try {
                    proxyInternal(connection, request, response, host);

                    if (log.isLoggable(Level.FINE)) {
                        log.log(Level.FINE,
                            "Successfully proxied the request '" +
                            cRequest.getMethod() + " " +
                            cRequest.getRequestURI() + "' to '" + host +
                            "' over the connection '" + connection + "'.");
                    }

                    return;
                } catch (IOException e) {
                    // Try again
                    if (log.isLoggable(Level.FINE)) {
                        log.log(Level.FINE,
                            "Failed to proxy the request'" +
                            cRequest.getRequestURI() + "' to '" + host +
                            "' over the connection '" + connection +
                            "'. Retries left: " + retries, e);
                    }

                    // Make sure this connection is closed!
                    connection.close();

                    retries--;
                } catch (Exception e) {
                    // Make sure this connection is closed!
                    connection.close();

                    log.log(Level.SEVERE,
                        "Failed to proxy the request'" +
                        cRequest.getRequestURI() + "' to '" + host +
                        "' over the connection '" + connection +
                        "'. Will not retry!", e);

                    // Do not retry!
                    break;
View Full Code Here

     *           The request.
     */
    public static void updateRequest(Request request) {
        // GLASSFISH Request/Response does not extend HttpRequest/Response so
        // we need to cast to Coyote Request/Response
        CoyoteRequest cRequest = (CoyoteRequest) request;

        String exists = cRequest.getHeader(EAS_HEADER_FRONTEND_IS_SECURE);

        if (exists == null) {
            return;
        }

        org.apache.coyote.Request coyoteRequest = cRequest.getCoyoteRequest();
        MimeHeaders mimeHeaders = coyoteRequest.getMimeHeaders();

        String isSecure = cRequest.getHeader(EAS_HEADER_FRONTEND_IS_SECURE);
        String localAddress = cRequest.getHeader(EAS_HEADER_FRONTEND_LOCAL_ADDRESS);
        String localPort = cRequest.getHeader(EAS_HEADER_FRONTEND_LOCAL_PORT);

        mimeHeaders.removeHeader(EAS_HEADER_FRONTEND_IS_SECURE);
        mimeHeaders.removeHeader(EAS_HEADER_FRONTEND_LOCAL_ADDRESS);
        mimeHeaders.removeHeader(EAS_HEADER_FRONTEND_LOCAL_PORT);

View Full Code Here

     */
    private static void proxyRequest(HttpConnection connection, Request request)
        throws IOException {
        // GLASSFISH Request/Response does not extend HttpRequest/Response so
        // we need to cast to Coyote Request/Response
        CoyoteRequest cRequest = (CoyoteRequest) request;

        // CoyoteResponse cResponse = (CoyoteResponse) response;
        String contentType = null;
        int contentLength = 0;

        // Emit the request line
        connection.printLine(createRequestLine(request));

        ArrayList<String> connectionToken = checkConnectionsToken(cRequest.getHeader(
                    "Connection"));

        // Emit some of the headers from the original request.
        Enumeration hdrNames = cRequest.getHeaderNames();

        while (hdrNames.hasMoreElements()) {
            String headerName = (String) hdrNames.nextElement();
            String headerValue = cRequest.getHeader(headerName);

            // Check for message content
            if ("Content-Type".equalsIgnoreCase(headerName)) {
                contentType = headerValue;
            }
View Full Code Here

     */
    private static InputStream getRequestInputStream(Request request,
        String contentType, int contentLength) throws IOException {
        // GLASSFISH Request/Response does not extend HttpRequest/Response so
        // we need to cast to Coyote Request/Response
        CoyoteRequest cRequest = (CoyoteRequest) request;

        InputStream in;

        // If this is a POST request with posted parameters we
        // read the message body directly from the request since
        // this data may have already been consumed by Tomcat.
        if ((contentType != null) &&
                contentType.toLowerCase()
                               .startsWith("application/x-www-form-urlencoded") &&
                cRequest.getMethod().equalsIgnoreCase("POST")) {
            // Wrapping the already read POST data in a bounded InputStream.
            HttpFormData data = new HttpFormData(request);
            in = new ContentLengthInputStream(new ByteArrayInputStream(
                        data.getData()), data.getLength());
        } else {
            // Using the standard InputStream of the request.
            in = new ContentLengthInputStream(cRequest.getInputStream(),
                    contentLength);
        }

        return in;
    }
View Full Code Here

     * @return The request line.
     */
    private static String createRequestLine(Request request) {
        // GLASSFISH Request/Response does not extend HttpRequest/Response so
        // we need to cast to Coyote Request/Response
        CoyoteRequest cRequest = (CoyoteRequest) request;

        StringBuilder requestLine = new StringBuilder(cRequest.getMethod());
        requestLine.append(" ").append(cRequest.getRequestURI());

        if (cRequest.getQueryString() != null) {
            requestLine.append("?");
            requestLine.append(cRequest.getQueryString());
        }

        requestLine.append(" HTTP/1.1");

        return requestLine.toString();
View Full Code Here

TOP

Related Classes of org.apache.coyote.tomcat4.CoyoteRequest

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.