use of org.wso2.transport.http.netty.contract.HttpResponseFuture in project ballerina by ballerina-lang.
the class AbstractHTTPAction method send.
/**
* Send outbound request through the client connector. If the Content-Type is multipart, check whether the boundary
* exist. If not get a new boundary string and add it as a parameter to Content-Type, just before sending header
* info through wire. If a boundary string exist at this point, serialize multipart entity body, else serialize
* entity body which can either be a message data source or a byte channel.
*
* @param dataContext holds the ballerina context and callback
* @param outboundRequestMsg Outbound request that needs to be sent across the wire
* @param async whether a handle should be return
* @return connector future for this particular request
* @throws Exception When an error occurs while sending the outbound request via client connector
*/
private void send(DataContext dataContext, HTTPCarbonMessage outboundRequestMsg, boolean async) throws Exception {
BStruct bConnector = (BStruct) dataContext.context.getRefArgument(0);
Struct httpClient = BLangConnectorSPIUtil.toStruct(bConnector);
HttpClientConnector clientConnector = (HttpClientConnector) httpClient.getNativeData(HttpConstants.HTTP_CLIENT);
String contentType = HttpUtil.getContentTypeFromTransportMessage(outboundRequestMsg);
String boundaryString = null;
if (HeaderUtil.isMultipart(contentType)) {
boundaryString = HttpUtil.addBoundaryIfNotExist(outboundRequestMsg, contentType);
}
HttpMessageDataStreamer outboundMsgDataStreamer = new HttpMessageDataStreamer(outboundRequestMsg);
OutputStream messageOutputStream = outboundMsgDataStreamer.getOutputStream();
RetryConfig retryConfig = getRetryConfiguration(httpClient);
HTTPClientConnectorListener httpClientConnectorLister = new HTTPClientConnectorListener(dataContext, retryConfig, outboundRequestMsg, outboundMsgDataStreamer);
HttpResponseFuture future = clientConnector.send(outboundRequestMsg);
if (async) {
future.setResponseHandleListener(httpClientConnectorLister);
} else {
future.setHttpConnectorListener(httpClientConnectorLister);
}
try {
if (boundaryString != null) {
serializeMultiparts(dataContext.context, messageOutputStream, boundaryString);
} else {
serializeDataSource(dataContext.context, messageOutputStream);
}
} catch (IOException | EncoderException serializerException) {
// We don't have to do anything here as the client connector will notify
// the error though the listener
logger.warn("couldn't serialize the message", serializerException);
}
}
use of org.wso2.transport.http.netty.contract.HttpResponseFuture in project ballerina by ballerina-lang.
the class ConnectionAction method sendOutboundResponseRobust.
private BValue[] sendOutboundResponseRobust(Context context, HTTPCarbonMessage requestMessage, BStruct outboundResponseStruct, HTTPCarbonMessage responseMessage) {
String contentType = HttpUtil.getContentTypeFromTransportMessage(responseMessage);
String boundaryString = null;
if (HeaderUtil.isMultipart(contentType)) {
boundaryString = HttpUtil.addBoundaryIfNotExist(responseMessage, contentType);
}
HttpResponseFuture outboundRespStatusFuture = HttpUtil.sendOutboundResponse(requestMessage, responseMessage);
BStruct entityStruct = MimeUtil.extractEntity(outboundResponseStruct);
if (entityStruct != null) {
if (boundaryString != null) {
serializeMultiparts(responseMessage, boundaryString, outboundRespStatusFuture, entityStruct);
} else {
MessageDataSource outboundMessageSource = EntityBodyHandler.getMessageDataSource(entityStruct);
serializeMsgDataSource(responseMessage, outboundMessageSource, outboundRespStatusFuture, entityStruct);
}
}
return handleResponseStatus(context, outboundRespStatusFuture);
}
use of org.wso2.transport.http.netty.contract.HttpResponseFuture in project ballerina by ballerina-lang.
the class Promise method execute.
@Override
public void execute(Context context) {
BStruct connectionStruct = (BStruct) context.getRefArgument(0);
HTTPCarbonMessage inboundRequestMsg = HttpUtil.getCarbonMsg(connectionStruct, null);
HttpUtil.serverConnectionStructCheck(inboundRequestMsg);
BStruct pushPromiseStruct = (BStruct) context.getRefArgument(1);
Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, HttpUtil.createHttpPushPromise(pushPromiseStruct));
HttpResponseFuture outboundRespStatusFuture = HttpUtil.pushPromise(inboundRequestMsg, http2PushPromise);
BValue[] outboundResponseStatus = handleResponseStatus(context, outboundRespStatusFuture);
context.setReturnValues(outboundResponseStatus);
}
use of org.wso2.transport.http.netty.contract.HttpResponseFuture in project ballerina by ballerina-lang.
the class PushPromisedResponse method pushResponseRobust.
private BValue[] pushResponseRobust(Context context, HTTPCarbonMessage requestMessage, BStruct outboundResponseStruct, HTTPCarbonMessage responseMessage, Http2PushPromise http2PushPromise) {
BStruct entityStruct = MimeUtil.extractEntity(outboundResponseStruct);
HttpResponseFuture outboundRespStatusFuture = HttpUtil.pushResponse(requestMessage, responseMessage, http2PushPromise);
if (entityStruct != null) {
MessageDataSource outboundMessageSource = EntityBodyHandler.getMessageDataSource(entityStruct);
serializeMsgDataSource(responseMessage, outboundMessageSource, outboundRespStatusFuture, entityStruct);
}
return handleResponseStatus(context, outboundRespStatusFuture);
}
use of org.wso2.transport.http.netty.contract.HttpResponseFuture in project ballerina by ballerina-lang.
the class ConnectionAction method getOutputStream.
private OutputStream getOutputStream(HTTPCarbonMessage responseMessage, HttpResponseFuture outboundResponseStatusFuture) {
HttpMessageDataStreamer outboundMsgDataStreamer = new HttpMessageDataStreamer(responseMessage);
HttpConnectorListener outboundResStatusConnectorListener = new HttpResponseConnectorListener(outboundMsgDataStreamer);
outboundResponseStatusFuture.setHttpConnectorListener(outboundResStatusConnectorListener);
return outboundMsgDataStreamer.getOutputStream();
}
Aggregations