Package winstone

Examples of winstone.WinstoneRequest


     * packets.
     */
    public void allocateRequestResponse(Socket socket, InputStream inSocket,
            OutputStream outSocket, RequestHandlerThread handler,
            boolean iAmFirst) throws SocketException, IOException {
        WinstoneRequest req = this.objectPool.getRequestFromPool();
        WinstoneResponse rsp = this.objectPool.getResponseFromPool();
        rsp.setRequest(req);
        req.setHostGroup(this.hostGroup);
        // rsp.updateContentTypeHeader("text/html");

        if (iAmFirst || (KEEP_ALIVE_TIMEOUT == -1))
            socket.setSoTimeout(CONNECTION_TIMEOUT);
        else
            socket.setSoTimeout(KEEP_ALIVE_TIMEOUT);
        Ajp13IncomingPacket headers = null;
        try {
            headers = new Ajp13IncomingPacket(inSocket, handler);
        } catch (InterruptedIOException err) {
            // keep alive timeout ? ignore if not first
            if (iAmFirst) {
                throw err;
            } else {
                deallocateRequestResponse(handler, req, rsp, null, null);
                return;
            }
        } finally {
            try {socket.setSoTimeout(CONNECTION_TIMEOUT);} catch (Throwable err) {}
        }

        if (headers.getPacketLength() > 0) {
            headers.parsePacket("8859_1");
            parseSocketInfo(headers, req);
            req.parseHeaders(Arrays.asList(headers.getHeaders()));
            String servletURI = parseURILine(headers, req, rsp);
            req.setAttribute(TEMPORARY_URL_STASH, servletURI);

            // If content-length present and non-zero, download the other
            // packets
            WinstoneInputStream inData = null;
            int contentLength = req.getContentLength();
            if (contentLength > 0) {
                byte bodyContent[] = new byte[contentLength];
                int position = 0;
                while (position < contentLength) {
                    outSocket.write(getBodyRequestPacket(Math.min(contentLength
                            - position, 8184)));
                    position = getBodyResponsePacket(inSocket, bodyContent,
                            position);
                    Logger.log(Logger.FULL_DEBUG, AJP_RESOURCES,
                            "Ajp13Listener.ReadBodyProgress", new String[] {
                                    "" + position, "" + contentLength });

                }
                inData = new WinstoneInputStream(bodyContent);
                inData.setContentLength(contentLength);
            } else
                inData = new WinstoneInputStream(new byte[0]);
            req.setInputStream(inData);

            // Build input/output streams, plus request/response
            WinstoneOutputStream outData = new Ajp13OutputStream(socket
                    .getOutputStream(), "8859_1");
            outData.setResponse(rsp);
View Full Code Here


                while (wrapperCheck instanceof HttpServletRequestWrapper) {
                    wrapperCheck = ((HttpServletRequestWrapper) wrapperCheck).getRequest();
                }
               
                // Get the stashed request
                WinstoneRequest actualRequest = null;
                if (wrapperCheck instanceof WinstoneRequest) {
                    actualRequest = (WinstoneRequest) wrapperCheck;
                    actualRequest.setRemoteUser(principal);
                } else {
                    Logger.log(Logger.WARNING, AUTH_RESOURCES,
                            "FormAuthenticationHandler.CantSetUser",
                            wrapperCheck.getClass().getName());
                }
                HttpSession session = request.getSession(true);
                String previousLocation = this.loginPage;
                RetryRequestParams cachedRequest = (RetryRequestParams)
                        session.getAttribute(CACHED_REQUEST);
                if ((cachedRequest != null) && (actualRequest != null)) {
                    // Repopulate this request from the params we saved
                    request = new RetryRequestWrapper(request, cachedRequest);
                    previousLocation =
                        (request.getServletPath() == null ? "" : request.getServletPath()) +
                        (request.getPathInfo() == null ? "" : request.getPathInfo());
                } else {
                    Logger.log(Logger.DEBUG, AUTH_RESOURCES,
                            "FormAuthenticationHandler.NoCachedRequest");
                }
               
                // do role check, since we don't know that this user has permission
                if (doRoleCheck(request, response, previousLocation)) {
                    principal.setAuthType(HttpServletRequest.FORM_AUTH);
                    session.setAttribute(AUTHENTICATED_USER, principal);
                    javax.servlet.RequestDispatcher rdPrevious = request
                            .getRequestDispatcher(previousLocation);
                    rdPrevious.forward(request, response);
                } else {
                    javax.servlet.RequestDispatcher rdError = request
                            .getRequestDispatcher(this.errorPage);
                    rdError.forward(request, response);
                }
            }
            return false;
        }
        // If it's not a login, get the session, and look up the auth user variable
        else {
            WinstoneRequest actualRequest = null;
            if (request instanceof WinstoneRequest) {
                actualRequest = (WinstoneRequest) request;
            } else if (request instanceof HttpServletRequestWrapper) {
                HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
                if (wrapper.getRequest() instanceof WinstoneRequest) {
                    actualRequest = (WinstoneRequest) wrapper.getRequest();
                } else {
                    Logger.log(Logger.WARNING, AUTH_RESOURCES,
                            "FormAuthenticationHandler.CantSetUser", wrapper
                                    .getRequest().getClass().getName());
                }
            } else {
                Logger.log(Logger.WARNING, AUTH_RESOURCES,
                        "FormAuthenticationHandler.CantSetUser", request
                                .getClass().getName());
            }

            HttpSession session = actualRequest.getSession(false);
            if (session != null) {
                AuthenticationPrincipal authenticatedUser = (AuthenticationPrincipal)
                        session.getAttribute(AUTHENTICATED_USER);
                if (authenticatedUser != null) {
                    actualRequest.setRemoteUser(authenticatedUser);
                    Logger.log(Logger.FULL_DEBUG, AUTH_RESOURCES,
                            "FormAuthenticationHandler.GotUserFromSession");
                }
            }
            return true;
View Full Code Here

TOP

Related Classes of winstone.WinstoneRequest

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.