public void sendResponseWithStatusAndHeaders(
            final AbstractBody respBody,
            final int httpStatus,
            final Map<String,String> headers)
            throws IOException {
        HttpResponseHeader respHead = new HttpResponseHeader(httpStatus);
        if (headers != null) {
            for (Map.Entry<String,String> entry : headers.entrySet()) {
                respHead.setHeader(entry.getKey(), entry.getValue());
            }
        }
        
        String bodyStr = respBody.toXML();
        byte[] data = bodyStr.getBytes("UTF-8");
        try {
            String acceptStr = req.getHeader("Accept-Encoding");
            AttrAccept accept = AttrAccept.createFromString(acceptStr);
            if (accept != null) {
                String encoding = null;
                if (accept.isAccepted(ZLIBCodec.getID())) {
                    encoding = ZLIBCodec.getID();
                    data = ZLIBCodec.encode(data);
                } else if (accept.isAccepted(GZIPCodec.getID())) {
                    encoding = GZIPCodec.getID();
                    data = GZIPCodec.encode(data);
                }
                if (encoding != null) {
                    LOG.fine("Encoding: " + encoding);
                    respHead.setHeader("Content-Encoding", encoding);
                }
            }
        } catch (BOSHException boshx) {
            LOG.log(Level.WARNING,
                    "Could not respond to Accept-Encoding", boshx);
        }
        respHead.setContentLength(data.length);

        HttpResponse response = new HttpResponse(respHead, data);
        if (!httpResp.compareAndSet(null, response)) {
            throw(new IllegalStateException("HTTP Response already sent"));
        }

        if (!resp.compareAndSet(null,
                new StubResponse(respHead, respBody))) {
            throw(new IllegalStateException("Response already sent"));
        }

        synchronized(this) {
            notifyAll();
        }
    }