use of org.wso2.transport.http.netty.contract.HttpClientConnector 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.HttpClientConnector in project ballerina by ballerina-lang.
the class GetPromisedResponse method execute.
@Override
public void execute(Context context, CallableUnitCallback callback) {
DataContext dataContext = new DataContext(context, callback);
BStruct pushPromiseStruct = (BStruct) context.getRefArgument(1);
Http2PushPromise http2PushPromise = HttpUtil.getPushPromise(pushPromiseStruct, null);
if (http2PushPromise == null) {
throw new BallerinaException("invalid push promise");
}
BStruct bConnector = (BStruct) context.getRefArgument(0);
HttpClientConnector clientConnector = (HttpClientConnector) bConnector.getNativeData(HttpConstants.HTTP_CLIENT);
clientConnector.getPushResponse(http2PushPromise).setPushResponseListener(new PushResponseListener(dataContext), http2PushPromise.getPromisedStreamId());
}
use of org.wso2.transport.http.netty.contract.HttpClientConnector in project ballerina by ballerina-lang.
the class GetResponse method execute.
@Override
public void execute(Context context, CallableUnitCallback callback) {
DataContext dataContext = new DataContext(context, callback);
BStruct handleStruct = ((BStruct) context.getRefArgument(1));
ResponseHandle responseHandle = (ResponseHandle) handleStruct.getNativeData(HttpConstants.TRANSPORT_HANDLE);
if (responseHandle == null) {
throw new BallerinaException("invalid http handle");
}
BStruct bConnector = (BStruct) context.getRefArgument(0);
HttpClientConnector clientConnector = (HttpClientConnector) bConnector.getNativeData(HttpConstants.HTTP_CLIENT);
clientConnector.getResponse(responseHandle).setHttpConnectorListener(new ResponseListener(dataContext));
}
use of org.wso2.transport.http.netty.contract.HttpClientConnector in project ballerina by ballerina-lang.
the class HasPromise method execute.
@Override
public void execute(Context context, CallableUnitCallback callback) {
BStruct handleStruct = ((BStruct) context.getRefArgument(1));
ResponseHandle responseHandle = (ResponseHandle) handleStruct.getNativeData(HttpConstants.TRANSPORT_HANDLE);
if (responseHandle == null) {
throw new BallerinaException("invalid http handle");
}
BStruct bConnector = (BStruct) context.getRefArgument(0);
HttpClientConnector clientConnector = (HttpClientConnector) bConnector.getNativeData(HttpConstants.HTTP_CLIENT);
clientConnector.hasPushPromise(responseHandle).setPromiseAvailabilityListener(new PromiseAvailabilityCheckListener(context, callback));
}
use of org.wso2.transport.http.netty.contract.HttpClientConnector in project ballerina by ballerina-lang.
the class GetNextPromise method execute.
@Override
public void execute(Context context, CallableUnitCallback callback) {
DataContext dataContext = new DataContext(context, callback);
BStruct handleStruct = ((BStruct) context.getRefArgument(1));
ResponseHandle responseHandle = (ResponseHandle) handleStruct.getNativeData(HttpConstants.TRANSPORT_HANDLE);
if (responseHandle == null) {
throw new BallerinaException("invalid http handle");
}
BStruct bConnector = (BStruct) context.getRefArgument(0);
HttpClientConnector clientConnector = (HttpClientConnector) bConnector.getNativeData(HttpConstants.HTTP_CLIENT);
clientConnector.getNextPushPromise(responseHandle).setPushPromiseListener(new PromiseListener(dataContext));
}
Aggregations