Search in sources :

Example 1 with HttpVersion

use of org.apache.commons.httpclient.HttpVersion in project zm-mailbox by Zimbra.

the class SoapServlet method sendResponse.

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 {
            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();
}
Also used : ProtocolException(org.apache.commons.httpclient.ProtocolException) ZimbraServletOutputStream(com.zimbra.common.util.ZimbraServletOutputStream) SoapProtocol(com.zimbra.common.soap.SoapProtocol) HttpVersion(org.apache.commons.httpclient.HttpVersion)

Aggregations

SoapProtocol (com.zimbra.common.soap.SoapProtocol)1 ZimbraServletOutputStream (com.zimbra.common.util.ZimbraServletOutputStream)1 HttpVersion (org.apache.commons.httpclient.HttpVersion)1 ProtocolException (org.apache.commons.httpclient.ProtocolException)1