Package com.ramforth.webserver.http.parsers

Examples of com.ramforth.webserver.http.parsers.ContentLengthInputStream


        socket = null;
        //}
    }

    private void handleClient() throws IOException, SocketTimeoutException {
        InputStream is = new ContentLengthInputStream(new BufferedInputStream(socket.getInputStream()), maximumRequestLengthInBytes);
        OutputStream os = new BufferedOutputStream(socket.getOutputStream());

        /*
         * we will only block in read for this many milliseconds before we fail with
         * java.io.InterruptedIOException, at which point we will abandon the
         * connection.
         */
        socket.setSoTimeout(1000000/* WebServer.timeout */);
        socket.setTcpNoDelay(true);
       
        clearBuffer();

        try {
            IHttpContext context = establishContext(is, socket.getInetAddress(), os);

            handleContext(context);
        }
        catch (ResourceNotFoundException rnfex) {
            IHttpResponse httpResponse = createHttpResponseForStatusCode(HttpStatusCode.STATUS_404_NOT_FOUND);

            IHttpResponseWriter responseWriter = new HttpResponseWriter(os);
            responseWriter.writeResponse(httpResponse);
        }
        catch (HttpException he) {
            IHttpResponse httpResponse = createHttpResponseForStatusCode(he.getStatusCode());

            IHttpResponseWriter responseWriter = new HttpResponseWriter(os);
            responseWriter.writeResponse(httpResponse);
        }
        catch (SocketTimeoutException ste) {
            IHttpResponse httpResponse = createHttpResponseForStatusCode(HttpStatusCode.STATUS_408_REQUEST_TIMEOUT);

            IHttpResponseWriter responseWriter = new HttpResponseWriter(os);
            responseWriter.writeResponse(httpResponse);
        }
        finally {
            if (!socket.isClosed()) {
                try {
                    os.flush();

                    is.close();
                    os.close();

                    socket.close();
                }
                catch (IOException ex) {
View Full Code Here

TOP

Related Classes of com.ramforth.webserver.http.parsers.ContentLengthInputStream

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.