ServerWorker worker = (ServerWorker) msgContext.getProperty(Constants.OUT_TRANSPORT_INFO);
HttpResponse response = worker.getResponse();
OMOutputFormat format = NhttpUtil.getOMOutputFormat(msgContext);
MessageFormatter messageFormatter =
MessageFormatterDecoratorFactory.createMessageFormatterDecorator(msgContext);
Boolean noEntityBody = (Boolean) msgContext.getProperty(NhttpConstants.NO_ENTITY_BODY);
if (noEntityBody == null || Boolean.FALSE == noEntityBody) {
response.setHeader(
HTTP.CONTENT_TYPE,
messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));
}
response.setStatusCode(determineHttpStatusCode(msgContext, response));
// set any transport headers
Map<?,?> transportHeaders = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
if (transportHeaders != null && !transportHeaders.values().isEmpty()) {
for (Map.Entry entry : transportHeaders.entrySet()) {
Object header = entry.getKey();
Object value = entry.getValue();
if (value != null && header instanceof String && value instanceof String) {
response.setHeader((String) header, (String) value);
}
}
}
if (JavaUtils.isTrueExplicitly(worker.getConn().getContext().getAttribute("forceClosing"))) {
HttpRequest req = (HttpRequest)
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) {