use of org.wso2.transport.http.netty.contract.HttpClientConnector in project ballerina by ballerina-lang.
the class CreateHttpClient method execute.
@Override
public void execute(Context context) {
BStruct configBStruct = (BStruct) context.getRefArgument(0);
Struct clientEndpointConfig = BLangConnectorSPIUtil.toStruct(configBStruct);
String url = context.getStringArgument(0);
HttpConnectionManager connectionManager = HttpConnectionManager.getInstance();
String scheme;
if (url.startsWith("http://")) {
scheme = HttpConstants.PROTOCOL_HTTP;
} else if (url.startsWith("https://")) {
scheme = HttpConstants.PROTOCOL_HTTPS;
} else {
throw new BallerinaException("malformed URL: " + url);
}
Map<String, Object> properties = HTTPConnectorUtil.getTransportProperties(connectionManager.getTransportConfig());
SenderConfiguration senderConfiguration = HTTPConnectorUtil.getSenderConfiguration(connectionManager.getTransportConfig(), scheme);
if (connectionManager.isHTTPTraceLoggerEnabled()) {
senderConfiguration.setHttpTraceLogEnabled(true);
}
senderConfiguration.setTLSStoreType(HttpConstants.PKCS_STORE_TYPE);
populateSenderConfigurationOptions(senderConfiguration, clientEndpointConfig);
Struct connectionThrottling = clientEndpointConfig.getStructField(HttpConstants.CONNECTION_THROTTLING_STRUCT_REFERENCE);
if (connectionThrottling != null) {
long maxActiveConnections = connectionThrottling.getIntField(HttpConstants.CONNECTION_THROTTLING_MAX_ACTIVE_CONNECTIONS);
if (!isInteger(maxActiveConnections)) {
throw new BallerinaConnectorException("invalid maxActiveConnections value: " + maxActiveConnections);
}
senderConfiguration.getPoolConfiguration().setMaxActivePerPool((int) maxActiveConnections);
long waitTime = connectionThrottling.getIntField(HttpConstants.CONNECTION_THROTTLING_WAIT_TIME);
senderConfiguration.getPoolConfiguration().setMaxWaitTime(waitTime);
}
HttpClientConnector httpClientConnector = httpConnectorFactory.createHttpClientConnector(properties, senderConfiguration);
BStruct httpClient = BLangConnectorSPIUtil.createBStruct(context.getProgramFile(), HTTP_PACKAGE_PATH, HTTP_CLIENT, url, clientEndpointConfig);
httpClient.addNativeData(HttpConstants.HTTP_CLIENT, httpClientConnector);
httpClient.addNativeData(HttpConstants.CLIENT_ENDPOINT_CONFIG, clientEndpointConfig);
context.setReturnValues(httpClient);
}
use of org.wso2.transport.http.netty.contract.HttpClientConnector in project ballerina by ballerina-lang.
the class RejectPromise method execute.
@Override
public void execute(Context context, CallableUnitCallback 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.rejectPushResponse(http2PushPromise);
// TODO: Implement a listener to see the progress
context.setReturnValues(new BBoolean(true));
callback.notifySuccess();
}
Aggregations