Package com.sun.grizzly.util.http

Examples of com.sun.grizzly.util.http.MimeHeaders


    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.
View Full Code Here


    }
   
    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();
View Full Code Here

         * which will fail because we are still executing in a 1.0  worker.
         * So, as of now the best way to send a response is from here.
         */
        SSLOutputBuffer outputBuffer = (SSLOutputBuffer) response.getOutputBuffer();
        sslErrorBuffer.clear();
        MimeHeaders headers = response.getMimeHeaders();
        Enumeration names = headers.names();
        write(LoadBalancerProxyConstants.HTTP_11, sslErrorBuffer);
        write(response.getStatus() + " ", sslErrorBuffer);
        write(response.getMessage(), sslErrorBuffer);
        write(LoadBalancerProxyConstants.CRLF, sslErrorBuffer);
        while (names.hasMoreElements()) {
            String headername = (String) names.nextElement();
            String headervalue = headers.getHeader(headername);
            write(headername + ": " + headervalue, sslErrorBuffer);
            write(LoadBalancerProxyConstants.CRLF, sslErrorBuffer);
        }
        write(LoadBalancerProxyConstants.CRLF, sslErrorBuffer);
        sslErrorBuffer.flip();
View Full Code Here

                _logger.log(Level.FINE, "clb.proxy.requesthandler.set_error_response");
            }
            response.setStatus(505);
        }
       
        MimeHeaders headers = request.getMimeHeaders();
        // Check connection header
        MessageBytes connectionValueMB = headers.getValue(
                LoadBalancerProxyConstants.HTTP_CONNECTION_HEADER);
        if (connectionValueMB != null) {
            ByteChunk connectionValueBC = connectionValueMB.getByteChunk();
            if (findBytes(connectionValueBC, Constants.CLOSE_BYTES) != -1) {
                keepAlive = false;
View Full Code Here

    public void dumpHeaders() {
        _logger.log(Level.FINEST, "clb.proxy.http.request_uri", requestURI());

        try {
            MimeHeaders headers = getMimeHeaders();
            Enumeration names = getMimeHeaders().names();

            while (names.hasMoreElements()) {
                String headername = (String) names.nextElement();
                _logger.log(Level.FINEST, "clb.proxy.http_header_name", headername);
                _logger.log(Level.FINEST,
                        "clb.proxy.http_header_value", headers.getHeader(headername));
            }
            _logger.log(Level.FINEST, "clb.proxy.http.request_remote_addr",
                    remoteAddr().toString());
            _logger.log(Level.FINEST, "clb.proxy.http.request_remote_port",
                    getRemotePort());
View Full Code Here

        String name = cookie.getName();
        final String headername = "Set-Cookie";
        final String startsWith = name + "=";
        final String cookieString = getCookieString(cookie);
        boolean set = false;
        MimeHeaders headers = coyoteResponse.getMimeHeaders();
        int n = headers.size();
        for (int i = 0; i < n; i++) {
            if (headers.getName(i).toString().equals(headername)) {
                if (headers.getValue(i).toString().startsWith(startsWith)) {
                    headers.getValue(i).setString(cookieString);
                    set = true;
                }
            }
        }
        if (!set) {
View Full Code Here

    }
   
    private void decodeHeaders( MsgContext ep, Msg msg, Request req,
                                MessageBytes tmpMB ) {
        // Decode headers
        MimeHeaders headers = req.getMimeHeaders();

        int hCount = msg.getInt();
        for(int i = 0 ; i < hCount ; i++) {
            String hName = null;

            // Header names are encoded as either an integer code starting
            // with 0xA0, or as a normal string (in which case the first
            // two bytes are the length).
            int isc = msg.peekInt();
            int hId = isc & 0xFF;

            MessageBytes vMB=null;
            isc &= 0xFF00;
            if(0xA000 == isc) {
                msg.getInt(); // To advance the read position
                hName = AjpConstants.headerTransArray[hId - 1];
                vMB=headers.addValue( hName );
            } else {
                // reset hId -- if the header currently being read
                // happens to be 7 or 8 bytes long, the code below
                // will think it's the content-type header or the
                // content-length header - SC_REQ_CONTENT_TYPE=7,
                // SC_REQ_CONTENT_LENGTH=8 - leading to unexpected
                // behaviour.  see bug 5861 for more information.
                hId = -1;
                msg.getBytes( tmpMB );
                ByteChunk bc=tmpMB.getByteChunk();
                vMB=headers.addValue( bc.getBuffer(),
                                      bc.getStart(), bc.getLength() );
            }

            msg.getBytes(vMB);
View Full Code Here

        c2b.convert( tempMB );
        outputMsg.appendBytes(tempMB);

        // XXX add headers
       
        MimeHeaders headers=res.getMimeHeaders();
        String contentType = res.getContentType();
        if( contentType != null ) {
            headers.setValue("Content-Type").setString(contentType);
        }
        String contentLanguage = res.getContentLanguage();
        if( contentLanguage != null ) {
            headers.setValue("Content-Language").setString(contentLanguage);
        }
        long contentLength = res.getContentLengthLong();
        if( contentLength >= 0 ) {
            headers.setValue("Content-Length").setLong(contentLength);
        }
        int numHeaders = headers.size();
        outputMsg.appendInt(numHeaders);
        for( int i=0; i<numHeaders; i++ ) {
            MessageBytes hN=headers.getName(i);
            // no header to sc conversion - there's little benefit
            // on this direction
            c2b.convert ( hN );
            outputMsg.appendBytes( hN );
                       
            MessageBytes hV=headers.getValue(i);
            c2b.convert( hV );
            outputMsg.appendBytes( hV );
        }
        mc.getSource().send( outputMsg, mc );
    }
View Full Code Here

TOP

Related Classes of com.sun.grizzly.util.http.MimeHeaders

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.