public static void respond(HttpSession session, AsyncContext context, String content, boolean async) throws IOException
    {
        final HttpServletResponse response = ((HttpServletResponse) context.getResponse());
        final HttpServletRequest request = ((HttpServletRequest) context.getRequest());

        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("GET".equals(request.getMethod()) ? "text/javascript" : "text/xml");
        response.setCharacterEncoding("UTF-8");

        if ("GET".equals(request.getMethod())) {
            if (JiveGlobals.getBooleanProperty("xmpp.httpbind.client.no-cache.enabled", true)) {
                // Prevent caching of responses
                response.setHeader("Cache-Control", "no-store");
                response.addHeader("Cache-Control", "no-cache");
                response.setHeader("Pragma", "no-cache");
            }
            content = "_BOSH_(\"" + StringEscapeUtils.escapeEcmaScript(content) + "\")";
        }
        
        if (HttpBindManager.LOG_HTTPBIND_ENABLED.getValue()) {
            Log.info("HTTP SENT({}): {}", session.getStreamID().getID(), content);
        }

        final byte[] byteContent = content.getBytes(StandardCharsets.UTF_8);
        // BOSH communication should not use Chunked encoding.
        // This is prevented by explicitly setting the Content-Length header.
        response.setContentLength(byteContent.length);

        if (async) {
            response.getOutputStream().setWriteListener(new WriteListenerImpl(context, byteContent));
        } else {
            context.getResponse().getOutputStream().write(byteContent);
            context.getResponse().getOutputStream().flush();
            context.complete();
        }
    }
Servlet which handles requests to the HTTP binding service. It determines if there is currently
an {@link HttpSession} related to the connection or if one needs to be created and then passes it
off to the {@link HttpBindManager} for processing of the client request and formulating of the
response.

@author Alexander Wenckus
xmppserver/src/main/java/org/jivesoftware/openfire/http/HttpBindServlet.java