Package org.openqa.jetty.http

Examples of org.openqa.jetty.http.HttpRequest


    /* ------------------------------------------------------------ */
    public boolean handleNext()
    {
        AJP13RequestPacket packet=null;
        HttpRequest request=getRequest();
        HttpResponse response=getResponse();
        HttpContext context=null;
        boolean gotRequest=false;
        _persistent=true;
        _keepAlive=true;

        try
        {
            try
            {
                packet=null;
                packet=_ajpIn.nextPacket();
                if (packet==null)
                    return false;
                if (packet.getDataSize()==0)
                    return true;
            }
            catch (IOException e)
            {
                LogSupport.ignore(log,e);
                return false;
            }

            int type=packet.getByte();
            if (log.isDebugEnabled())
                log.debug("AJP13 type="+type+" size="+packet.unconsumedData());

            switch (type)
            {
                case AJP13Packet.__FORWARD_REQUEST:
                    request.setTimeStamp(System.currentTimeMillis());

                    request.setState(HttpMessage.__MSG_EDITABLE);
                    request.setMethod(packet.getMethod());
                    request.setVersion(packet.getString());
        String version=packet.getString();
        try
        {
      request.setVersion(version);
        }
        catch(Exception e)
        {
      log.warn("Bad version"+version,e);
      log.warn(packet.toString());
        }

                    String path=packet.getString();
                    int sc=path.lastIndexOf(";");
                    if (sc<0)
                        request.setPath(URI.encodePath(path));
                    else
                        request.setPath(URI.encodePath(path.substring(0,sc))+path.substring(sc));

                    _remoteAddr=packet.getString();
                    _remoteHost=packet.getString();
                    _serverName=packet.getString();
                    _serverPort=packet.getInt();
                    _isSSL=packet.getBoolean();

                    // Check keep alive
                    _keepAlive=request.getDotVersion()>=1;

                    // Headers
                    int h=packet.getInt();
                    for (int i=0; i<h; i++)
                    {
                        String hdr=packet.getHeader();
                        String val=packet.getString();
                        request.addField(hdr,val);
                        if (!_keepAlive&&hdr.equalsIgnoreCase(HttpFields.__Connection)&&val.equalsIgnoreCase(HttpFields.__KeepAlive))
                            _keepAlive=true;
                    }

                    // Handler other attributes
                    byte attr=packet.getByte();
                    while ((0xFF&attr)!=0xFF)
                    {
                        String value=(attr==11)?null:packet.getString();
                        switch (attr)
                        {
                            case 11: // key size
                                request.setAttribute("javax.servlet.request.key_size",new Integer(packet.getInt()));
                                break;
                            case 10: // request attribute
                                request.setAttribute(value,packet.getString());
                                break;
                            case 9: // SSL session
                                request.setAttribute("javax.servlet.request.ssl_session",value);
                                break;
                            case 8: // SSL cipher
                                request.setAttribute("javax.servlet.request.cipher_suite",value);
                                break;
                            case 7: // SSL cert
                                // request.setAttribute("javax.servlet.request.X509Certificate",value);
                                CertificateFactory cf=CertificateFactory.getInstance("X.509");
                                InputStream certstream=new ByteArrayInputStream(value.getBytes());
                                X509Certificate cert=(X509Certificate)cf.generateCertificate(certstream);
                                X509Certificate certs[]=
                                { cert };
                                request.setAttribute("javax.servlet.request.X509Certificate",certs);
                                break;
                            case 6: // JVM Route
                                request.setAttribute("org.openqa.jetty.http.ajp.JVMRoute",value);
                                break;
                            case 5: // Query String
                                request.setQuery(value);
                                break;
                            case 4: // AuthType
                                request.setAuthType(value);
                                break;
                            case 3: // Remote User
                                request.setAuthUser(value);
                                break;

                            case 2: // servlet path not implemented
                            case 1: // _context not implemented
                            default:
                                log.warn("Unknown attr: "+attr+"="+value);
                        }

                        attr=packet.getByte();
                    }

                    _listener.customizeRequest(this,request);

                    gotRequest=true;
                    statsRequestStart();
                    request.setState(HttpMessage.__MSG_RECEIVED);

                    // Complete response
                    if (request.getContentLength()==0&&request.getField(HttpFields.__TransferEncoding)==null)
                        _ajpIn.close();

                    // Prepare response
                    response.setState(HttpMessage.__MSG_EDITABLE);
                    response.setVersion(HttpMessage.__HTTP_1_1);
View Full Code Here


            throw new UnavailableException("Could not instantiate "+_class);

        // Service the request
        boolean servlet_error=true;
        Principal user=null;
        HttpRequest http_request=null;
        try
        {
            // Handle aliased path
            if (_forcedPath!=null)
                // TODO complain about poor naming to the Jasper folks
                request.setAttribute("org.apache.catalina.jsp_file",_forcedPath);

            // Handle run as
            if (_runAs!=null && _realm!=null)
            {
                http_request=getHttpContext().getHttpConnection().getRequest();
                user=_realm.pushRole(http_request.getUserPrincipal(),_runAs);
                http_request.setUserPrincipal(user);
            }
           
            servlet.service(request,response);
            servlet_error=false;
        }
        catch(UnavailableException e)
        {
            if (_servlets!=null && servlet!=null)
                stop();
            makeUnavailable(e);
        }
        finally
        {
            // pop run-as role
            if (_runAs!=null && _realm!=null && user!=null)
            {
                user=_realm.popRole(user);
                http_request.setUserPrincipal(user);
            }

            // Handle error params.
            if (servlet_error)
                request.setAttribute("javax.servlet.error.servlet_name",getName());
View Full Code Here

TOP

Related Classes of org.openqa.jetty.http.HttpRequest

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.