use of org.wso2.transport.http.netty.contract.exceptions.ServerConnectorException in project wso2-synapse by wso2.
the class HttpRequestWorker method sendResponse.
private void sendResponse(int statusCode, HttpResponseStatus responseStatus, boolean disableKeepAlive, boolean contentAvailable, String content, String contentType) {
HttpCarbonMessage clientRequest = (HttpCarbonRequest) this.msgContext.getProperty(BridgeConstants.HTTP_CLIENT_REQUEST_CARBON_MESSAGE);
HttpCarbonMessage outboundResponse;
try {
outboundResponse = new HttpCarbonMessage(new DefaultHttpResponse(HttpVersion.HTTP_1_1, responseStatus));
outboundResponse.setHttpStatusCode(statusCode);
if (disableKeepAlive) {
outboundResponse.setKeepAlive(false);
}
clientRequest.respond(outboundResponse);
} catch (ServerConnectorException e) {
LOG.error("Error occurred while submitting the Ack to the client", e);
return;
}
if (!contentAvailable) {
try {
OutputStream messageOutputStream = HttpUtils.getHttpMessageDataStreamer(outboundResponse).getOutputStream();
HttpUtils.writeEmptyBody(messageOutputStream);
} catch (AxisFault e) {
LOG.error("Error occurred while writing the Ack to the client", e);
}
return;
}
outboundResponse.setHeader(HTTP.CONTENT_TYPE, contentType);
try (OutputStream outputStream = HttpUtils.getHttpMessageDataStreamer(outboundResponse).getOutputStream()) {
outputStream.write(content.getBytes());
} catch (IOException ioException) {
LOG.error("Error occurred while writing the response body to the client", ioException);
}
}
Aggregations