*/
public void sendResponse(Response response) throws IOException {
if (response != null) {
// Get the connector service to callback
Representation responseEntity = response.getEntity();
ConnectorService connectorService = ConnectorHelper
.getConnectorService();
if (connectorService != null) {
connectorService.beforeSend(responseEntity);
}
try {
writeResponseHead(response);
if (responseEntity != null) {
OutputStream responseEntityStream = getResponseEntityStream();
writeResponseBody(responseEntity, responseEntityStream);
if (responseEntityStream != null) {
try {
responseEntityStream.flush();
responseEntityStream.close();
} catch (IOException ioe) {
// The stream was probably already closed by the
// connector. Probably OK, low message priority.
getLogger()
.log(Level.FINE,
"Exception while flushing and closing the entity stream.",
ioe);
}
}
}
} finally {
if (responseEntity != null) {
responseEntity.release();
}
if (connectorService != null) {
connectorService.afterSend(responseEntity);
}
}
}
}