Example usage for org.apache.commons.httpclient HttpVersion lessEquals

List of usage examples for org.apache.commons.httpclient HttpVersion lessEquals

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpVersion lessEquals.

Prototype

public boolean lessEquals(HttpVersion paramHttpVersion) 

Source Link

Usage

From source file:com.zimbra.soap.SoapServlet.java

private void sendResponse(HttpServletRequest req, HttpServletResponse resp, Element envelope)
        throws IOException {
    SoapProtocol soapProto = SoapProtocol.determineProtocol(envelope);
    int statusCode = soapProto.hasFault(envelope) ? HttpServletResponse.SC_INTERNAL_SERVER_ERROR
            : HttpServletResponse.SC_OK;

    boolean chunkingEnabled = LC.soap_response_chunked_transfer_encoding_enabled.booleanValue();

    if (chunkingEnabled) {
        // disable chunking if proto < HTTP 1.1
        String proto = req.getProtocol();
        try {/*from w  w w  .j a v a 2s.  co  m*/
            HttpVersion httpVer = HttpVersion.parse(proto);
            chunkingEnabled = !httpVer.lessEquals(HttpVersion.HTTP_1_0);
        } catch (ProtocolException e) {
            ZimbraLog.soap.warn(
                    "cannot parse http version in request: %s, http chunked transfer encoding disabled", proto,
                    e);
            chunkingEnabled = false;
        }
    }

    // use jetty default if the LC key is not set
    int responseBufferSize = soapResponseBufferSize();
    if (responseBufferSize != -1)
        resp.setBufferSize(responseBufferSize);

    resp.setContentType(soapProto.getContentType());
    resp.setStatus(statusCode);
    resp.setHeader("Cache-Control", "no-store, no-cache");

    if (chunkingEnabled) {
        // Let jetty chunk the response if applicable.
        ZimbraServletOutputStream out = new ZimbraServletOutputStream(resp.getOutputStream());
        envelope.output(out);
        out.flush();
    } else {
        // serialize the envelope to a byte array and send the response with Content-Length header.
        byte[] soapBytes = envelope.toUTF8();
        resp.setContentLength(soapBytes.length);
        resp.getOutputStream().write(soapBytes);
        resp.getOutputStream().flush();
    }
    envelope.destroy();
}