worker.getConn().getContext().getAttribute("http.request");
req.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
}
// pass ClientConnectionDebug to the Server side
ServerConnectionDebug scd = (ServerConnectionDebug)
worker.getConn().getContext().getAttribute(ServerHandler.SERVER_CONNECTION_DEBUG);
ClientConnectionDebug ccd = (ClientConnectionDebug)
msgContext.getProperty(ClientHandler.CLIENT_CONNECTION_DEBUG);
if (scd != null && ccd != null) {
scd.setClientConnectionDebug(ccd);
} else if (scd == null && ccd != null) {
scd = ccd.getServerConnectionDebug();
scd.setClientConnectionDebug(ccd);
}
if (scd != null) {
scd.recordResponseStartTime();
}
MetricsCollector lstMetrics = worker.getServiceHandler().getMetrics();
try {
worker.getServiceHandler().commitResponse(worker.getConn(), response);
lstMetrics.reportResponseCode(response.getStatusLine().getStatusCode());
OutputStream out = worker.getOutputStream();
/*
* if this is a dummy message to handle http 202 case with non-blocking IO
* write an empty byte array as body
*/
if (msgContext.isPropertyTrue(NhttpConstants.SC_ACCEPTED)
|| Boolean.TRUE == noEntityBody) {
out.write(new byte[0]);
} else {
messageFormatter.writeTo(msgContext, format, out, false);
}
out.close();
lstMetrics.incrementMessagesSent();
} catch (HttpException e) {
if (lstMetrics != null) {
lstMetrics.incrementFaultsSending();
}
handleException("Unexpected HTTP protocol error sending response to : " +
worker.getRemoteAddress() + "\n" + scd.dump(), e);
} catch (ConnectionClosedException e) {
if (lstMetrics != null) {
lstMetrics.incrementFaultsSending();
}
log.warn("Connection closed by client : "
+ worker.getRemoteAddress() + "\n" + scd.dump());
} catch (IllegalStateException e) {
if (lstMetrics != null) {
lstMetrics.incrementFaultsSending();
}
log.warn("Connection closed by client : "
+ worker.getRemoteAddress() + "\n" + scd.dump());
} catch (IOException e) {
if (lstMetrics != null) {
lstMetrics.incrementFaultsSending();
}
handleException("IO Error sending response message to : " +
worker.getRemoteAddress() + "\n" + scd.dump(), e);
} catch (Exception e) {
if (lstMetrics != null) {
lstMetrics.incrementFaultsSending();
}
handleException("General Error sending response message to : " +
worker.getRemoteAddress() + "\n" + scd.dump(), e);
}
InputStream is = worker.getIs();
if (is != null) {
try {