Search in sources :

Example 1 with ServerConnectorException

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);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) HttpCarbonMessage(org.wso2.transport.http.netty.message.HttpCarbonMessage) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) OutputStream(java.io.OutputStream) ServerConnectorException(org.wso2.transport.http.netty.contract.exceptions.ServerConnectorException) IOException(java.io.IOException) HttpCarbonRequest(org.wso2.transport.http.netty.message.HttpCarbonRequest)

Aggregations

DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 AxisFault (org.apache.axis2.AxisFault)1 ServerConnectorException (org.wso2.transport.http.netty.contract.exceptions.ServerConnectorException)1 HttpCarbonMessage (org.wso2.transport.http.netty.message.HttpCarbonMessage)1 HttpCarbonRequest (org.wso2.transport.http.netty.message.HttpCarbonRequest)1