Package com.sun.grizzly.http

Examples of com.sun.grizzly.http.SocketChannelOutputBuffer


        proxy.expireKey(key);
        return true;   
    }
   
    protected void send503Response(Request request, Response response) {
        SocketChannelOutputBuffer outputBuffer = (SocketChannelOutputBuffer) response.getOutputBuffer();
        response.setStatus(503);
        response.setMessage(
                LoadBalancerProxyConstants.SERVICE_UNAVAILABLE);       
        MimeHeaders headers = response.getMimeHeaders();
        headers.setValue(LoadBalancerProxyConstants.HTTP_CONNECTION_HEADER).
                setString(LoadBalancerProxyConstants.HTTP_CONNECTION_CLOSE_VALUE);
        headers.setValue(LoadBalancerProxyConstants.SERVER_HEADER)
                .setString(SelectorThread.SERVER_NAME);
        headers.setValue(LoadBalancerProxyConstants.CONTENT_LENGTH_HEADER)
                .setInt(
                LoadBalancerProxyConstants.SERVICE_UNAVAILABLE_LENGTH);
        headers.setValue(LoadBalancerProxyConstants.CONTENT_TYPE_HEADER)
                .setString("text/html");
        outputBuffer.sendStatus();
        int size = headers.size();
        for (int i = 0; i < size; i++) {
            outputBuffer.sendHeader(headers.getName(i), headers.getValue(i));
        }
        outputBuffer.endHeaders();
        try {
            /**Browsers are not happy with the status alone, need to send
             * some html message so that it can be displayed to user.
             * Improvement could be to read the error message from a configured
             * error file. TODO see how we can combine this method &
             * sendresponse method.
             */
            outputBuffer.getOutputStream().write(
                LoadBalancerProxyConstants.SERVICE_UNAVAILABLE_BYTES);
            outputBuffer.endRequest();
            outputBuffer.flush();
            outputBuffer.commit();
        } catch (IOException ex) {
            _logger.log(Level.SEVERE, "clb.proxy.http.handler_error_response");                 
        }       
    }
View Full Code Here


            _logger.log(Level.SEVERE, "clb.proxy.http.handler_error_response");                 
        }       
    }
   
    protected void sendResponse(Request request, Response response) {
        SocketChannelOutputBuffer outputBuffer = (SocketChannelOutputBuffer) response.getOutputBuffer();

        MimeHeaders headers = response.getMimeHeaders();
        headers.setValue(LoadBalancerProxyConstants.HTTP_CONNECTION_HEADER).
                setString(LoadBalancerProxyConstants.HTTP_CONNECTION_CLOSE_VALUE);
        if (SelectorThread.SERVER_NAME != null &&
                !"".equals(SelectorThread.SERVER_NAME)) {
            headers.setValue(LoadBalancerProxyConstants.SERVER_HEADER)
                    .setString(SelectorThread.SERVER_NAME);
        }

        // Build the response header
        outputBuffer.sendStatus();

        int size = headers.size();

        for (int i = 0; i < size; i++) {
            outputBuffer.sendHeader(headers.getName(i), headers.getValue(i));
        }
        outputBuffer.endHeaders();
        try {
            outputBuffer.endRequest();
            outputBuffer.flush();
            outputBuffer.commit();
        } catch (IOException ex) {
            _logger.log(Level.SEVERE, "Exception in send response ", ex);
        }
    }
View Full Code Here

        request.setInputBuffer(inputBuffer);
        response = new Response();
        outputBuffer = secure ? new SSLOutputBuffer(response,
                LoadBalancerProxyConstants.DEFAULT_HTTP_HEADER_BUFFER_SIZE,
                false):
            new SocketChannelOutputBuffer
                (response,
                LoadBalancerProxyConstants.DEFAULT_HTTP_HEADER_BUFFER_SIZE,
                false);
        response.setOutputBuffer(outputBuffer);
        request.setResponse(response);
View Full Code Here

TOP

Related Classes of com.sun.grizzly.http.SocketChannelOutputBuffer

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.