Package org.apache.felix.httplite.servlet

Examples of org.apache.felix.httplite.servlet.HttpServletResponseImpl


     * @throws ServletException on servlet errors
    **/
    public void process() throws IOException, ServletException
    {
        HttpServletRequestImpl request = m_resolver.getServletRequest(m_socket);
        HttpServletResponseImpl response = m_resolver.getServletResponse(m_os);

        try
        {
            // Loop until we close the connection.
            boolean close = false;
            while (!close)
            {
                // Read the next request.
                try
                {
                    request.parseRequestLine(m_is);
                }
                catch (IOException e)
                {
                    m_logger.log(
                        Logger.LOG_ERROR,
                        "Error with request: " + request.toString() + ": "
                            + e.getMessage());
                    throw e;
                }
                m_requestCount++;

                // Keep track of whether we have failed or not,
                // because we still want to read the bytes to clear
                // the input stream so we can service more requests.
                boolean error = false;

                m_logger.log(Logger.LOG_DEBUG,
                    "Processing " + request.getRequestURI() + " (" + (m_requestLimit - m_requestCount)
                        + " remaining)");

                // If client is HTTP/1.1, then send continue message.
                if (request.getProtocol().equals(HttpConstants.HTTP11_VERSION))
                {
                    response.sendContinueResponse();
                }

                // Read the header lines of the request.
                request.parseHeader(m_is);

                // If we have an HTTP/1.0 request without the connection set to
                // keep-alive or we explicitly have a request to close the connection,
                // then set close flag to exit the loop rather than trying to read
                // more requests.
                String v = request.getHeader(HttpConstants.HEADER_CONNECTION);
                if ((request.getProtocol().equals(HttpConstants.HTTP10_VERSION) && ((v == null) || (!v.equalsIgnoreCase(HttpConstants.KEEPALIVE_CONNECTION))))
                    || ((v != null) && v.equalsIgnoreCase(HttpConstants.CLOSE_CONNECTION)))
                {
                    close = true;
                    response.setConnectionType("close");
                }
                // If we have serviced the maximum number of requests for
                // this connection, then set close flag so we exit the loop
                // and close the connection.
                else if (m_requestCount >= m_requestLimit)
                {
                    close = true;
                    response.setConnectionType("close");
                }

                // We do not support OPTIONS method so send
                // a "not implemented" error in that case.
                if (!HttpServletRequestImpl.isSupportedMethod(request.getMethod()))
                {
                    error = true;
                    response.setConnectionType(HttpConstants.CLOSE_CONNECTION);
                    response.sendNotImplementedResponse();
                }

                // Ignore if we have already failed, otherwise send error message
                // if an HTTP/1.1 client did not include HOST header.
                if (!error && request.getProtocol().equals(HttpConstants.HTTP11_VERSION)
                    && (request.getHeader(HttpConstants.HOST_HEADER) == null))
                {
                    error = true;
                    response.setConnectionType(HttpConstants.CLOSE_CONNECTION);
                    response.sendMissingHostResponse();
                }

                // Read in the request body.
                request.parseBody(m_is);

                // Only process the request if there was no error.
                if (!error)
                {
                    ServiceRegistrationHandler processor = m_resolver.getProcessor(
                        request, response, request.getRequestURI());

                    if (processor != null)
                    {
                        processor.handle(close);

                        m_logger.log(Logger.LOG_DEBUG, "Processed " + request.toString());

                        // TODO: Adding next line to make test cases pass, but not sure if it is correct
                        // and needs further investigation.
                        close = true;
                        continue;
                    }

                    close = true;
                    response.setConnectionType(HttpConstants.CLOSE_CONNECTION);
                    response.sendNotFoundResponse();
                }
            }
        }
        finally
        {
View Full Code Here


     * getServletResponse(org.apache.felix.http.lightweight.servlet.HttpRequest,
     * java.io.OutputStream)
     */
    public HttpServletResponseImpl getServletResponse(final OutputStream output)
    {
        return new HttpServletResponseImpl(output);
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.httplite.servlet.HttpServletResponseImpl

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.