use of org.wso2.transport.http.netty.config.ListenerConfiguration in project ballerina by ballerina-lang.
the class InitEndpoint method setRequestSizeValidationConfig.
private void setRequestSizeValidationConfig(Struct requestLimits, ListenerConfiguration listenerConfiguration) {
long maxUriLength = requestLimits.getIntField(HttpConstants.REQUEST_LIMITS_MAXIMUM_URL_LENGTH);
long maxHeaderSize = requestLimits.getIntField(HttpConstants.REQUEST_LIMITS_MAXIMUM_HEADER_SIZE);
long maxEntityBodySize = requestLimits.getIntField(HttpConstants.REQUEST_LIMITS_MAXIMUM_ENTITY_BODY_SIZE);
RequestSizeValidationConfig requestSizeValidationConfig = listenerConfiguration.getRequestSizeValidationConfig();
if (maxUriLength != -1) {
if (maxUriLength >= 0) {
requestSizeValidationConfig.setMaxUriLength(Math.toIntExact(maxUriLength));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxUriLength : " + maxUriLength);
}
}
if (maxHeaderSize != -1) {
if (maxHeaderSize >= 0) {
requestSizeValidationConfig.setMaxHeaderSize(Math.toIntExact(maxHeaderSize));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxHeaderSize : " + maxHeaderSize);
}
}
if (maxEntityBodySize != -1) {
if (maxEntityBodySize >= 0) {
requestSizeValidationConfig.setMaxEntityBodySize(Math.toIntExact(maxEntityBodySize));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxEntityBodySize : " + maxEntityBodySize);
}
}
}
use of org.wso2.transport.http.netty.config.ListenerConfiguration in project ballerina by ballerina-lang.
the class InitEndpoint method setSslConfig.
private ListenerConfiguration setSslConfig(Struct sslConfig, ListenerConfiguration listenerConfiguration) {
listenerConfiguration.setScheme(HttpConstants.PROTOCOL_HTTPS);
Struct trustStore = sslConfig.getStructField(HttpConstants.ENDPOINT_CONFIG_TRUST_STORE);
Struct keyStore = sslConfig.getStructField(HttpConstants.ENDPOINT_CONFIG_KEY_STORE);
Struct protocols = sslConfig.getStructField(HttpConstants.ENDPOINT_CONFIG_PROTOCOLS);
Struct validateCert = sslConfig.getStructField(HttpConstants.ENDPOINT_CONFIG_VALIDATE_CERT);
if (keyStore != null) {
String keyStoreFile = keyStore.getStringField(HttpConstants.FILE_PATH);
String keyStorePassword = keyStore.getStringField(HttpConstants.PASSWORD);
if (StringUtils.isBlank(keyStoreFile)) {
// TODO get from language pack, and add location
throw new BallerinaConnectorException("Keystore location must be provided for secure connection");
}
if (StringUtils.isBlank(keyStorePassword)) {
// TODO get from language pack, and add location
throw new BallerinaConnectorException("Keystore password value must be provided for secure connection");
}
listenerConfiguration.setKeyStoreFile(keyStoreFile);
listenerConfiguration.setKeyStorePass(keyStorePassword);
}
String sslVerifyClient = sslConfig.getStringField(HttpConstants.SSL_CONFIG_SSL_VERIFY_CLIENT);
listenerConfiguration.setVerifyClient(sslVerifyClient);
if (trustStore != null) {
String trustStoreFile = trustStore.getStringField(HttpConstants.FILE_PATH);
String trustStorePassword = trustStore.getStringField(HttpConstants.PASSWORD);
if (StringUtils.isBlank(trustStoreFile) && StringUtils.isNotBlank(sslVerifyClient)) {
// TODO get from language pack, and add location
throw new BallerinaException("Truststore location must be provided to enable Mutual SSL");
}
if (StringUtils.isBlank(trustStorePassword) && StringUtils.isNotBlank(sslVerifyClient)) {
// TODO get from language pack, and add location
throw new BallerinaException("Truststore password value must be provided to enable Mutual SSL");
}
listenerConfiguration.setTrustStoreFile(trustStoreFile);
listenerConfiguration.setTrustStorePass(trustStorePassword);
}
List<Parameter> serverParamList = new ArrayList<>();
Parameter serverParameters;
if (protocols != null) {
String sslEnabledProtocols = protocols.getStringField(HttpConstants.ENABLED_PROTOCOLS);
String sslProtocol = protocols.getStringField(HttpConstants.PROTOCOL_VERSION);
if (StringUtils.isNotBlank(sslEnabledProtocols)) {
serverParameters = new Parameter(HttpConstants.ANN_CONFIG_ATTR_SSL_ENABLED_PROTOCOLS, sslEnabledProtocols);
serverParamList.add(serverParameters);
}
if (StringUtils.isNotBlank(sslProtocol)) {
listenerConfiguration.setSSLProtocol(sslProtocol);
}
}
String cipher = sslConfig.getStringField(HttpConstants.SSL_CONFIG_CIPHERS);
if (StringUtils.isNotBlank(cipher)) {
serverParameters = new Parameter(HttpConstants.ANN_CONFIG_ATTR_CIPHERS, cipher);
serverParamList.add(serverParameters);
}
if (validateCert != null) {
boolean validateCertificateEnabled = validateCert.getBooleanField(HttpConstants.ENABLE);
long cacheSize = validateCert.getIntField(HttpConstants.SSL_CONFIG_CACHE_SIZE);
long cacheValidationPeriod = validateCert.getIntField(HttpConstants.SSL_CONFIG_CACHE_VALIDITY_PERIOD);
listenerConfiguration.setValidateCertEnabled(validateCertificateEnabled);
if (validateCertificateEnabled) {
if (cacheSize != 0) {
listenerConfiguration.setCacheSize(Math.toIntExact(cacheSize));
}
if (cacheValidationPeriod != 0) {
listenerConfiguration.setCacheValidityPeriod(Math.toIntExact(cacheValidationPeriod));
}
}
}
listenerConfiguration.setTLSStoreType(HttpConstants.PKCS_STORE_TYPE);
String serverEnableSessionCreation = String.valueOf(sslConfig.getBooleanField(HttpConstants.SSL_CONFIG_ENABLE_SESSION_CREATION));
Parameter enableSessionCreationParam = new Parameter(HttpConstants.SSL_CONFIG_ENABLE_SESSION_CREATION, serverEnableSessionCreation);
serverParamList.add(enableSessionCreationParam);
if (!serverParamList.isEmpty()) {
listenerConfiguration.setParameters(serverParamList);
}
listenerConfiguration.setId(HttpUtil.getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
return listenerConfiguration;
}
use of org.wso2.transport.http.netty.config.ListenerConfiguration in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
try {
Struct serviceEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
// Creating server connector
Struct serviceEndpointConfig = serviceEndpoint.getStructField(HttpConstants.SERVICE_ENDPOINT_CONFIG);
ListenerConfiguration listenerConfiguration = getListerConfig(serviceEndpointConfig);
ServerConnector httpServerConnector = HttpConnectionManager.getInstance().createHttpServerConnector(listenerConfiguration);
serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVER_CONNECTOR, httpServerConnector);
// Adding service registries to native data
WebSocketServicesRegistry webSocketServicesRegistry = new WebSocketServicesRegistry();
HTTPServicesRegistry httpServicesRegistry = new HTTPServicesRegistry(webSocketServicesRegistry);
serviceEndpoint.addNativeData(HttpConstants.HTTP_SERVICE_REGISTRY, httpServicesRegistry);
serviceEndpoint.addNativeData(HttpConstants.WS_SERVICE_REGISTRY, webSocketServicesRegistry);
// set filters
setFilters(serviceEndpointConfig, serviceEndpoint);
context.setReturnValues((BValue) null);
} catch (Throwable throwable) {
BStruct errorStruct = HttpUtil.getHttpConnectorError(context, throwable);
context.setReturnValues(errorStruct);
}
}
use of org.wso2.transport.http.netty.config.ListenerConfiguration in project ballerina by ballerina-lang.
the class HttpUtil method extractBasicConfig.
@Deprecated
private static void extractBasicConfig(Annotation configInfo, Set<ListenerConfiguration> listenerConfSet) {
AnnAttrValue hostAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HOST);
AnnAttrValue portAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_PORT);
AnnAttrValue keepAliveAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEEP_ALIVE);
AnnAttrValue transferEncoding = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRANSFER_ENCODING);
AnnAttrValue chunking = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CHUNKING);
AnnAttrValue maxUriLength = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_URL_LENGTH);
AnnAttrValue maxHeaderSize = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_HEADER_SIZE);
AnnAttrValue maxEntityBodySize = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_MAXIMUM_ENTITY_BODY_SIZE);
AnnAttrValue versionAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTP_VERSION);
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
if (portAttrVal != null && portAttrVal.getIntValue() > 0) {
listenerConfiguration.setPort(Math.toIntExact(portAttrVal.getIntValue()));
listenerConfiguration.setScheme(HttpConstants.PROTOCOL_HTTP);
if (hostAttrVal != null && hostAttrVal.getStringValue() != null) {
listenerConfiguration.setHost(hostAttrVal.getStringValue());
} else {
listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
}
// chunking. Once we start supporting gzip, deflate, etc, we need to parse down the config.
if (transferEncoding != null && !HttpConstants.ANN_CONFIG_ATTR_CHUNKING.equalsIgnoreCase(transferEncoding.getStringValue())) {
throw new BallerinaConnectorException("Unsupported configuration found for Transfer-Encoding : " + transferEncoding.getStringValue());
}
if (chunking != null) {
ChunkConfig chunkConfig = getChunkConfig(chunking.getStringValue());
listenerConfiguration.setChunkConfig(chunkConfig);
} else {
listenerConfiguration.setChunkConfig(ChunkConfig.AUTO);
}
if (keepAliveAttrVal != null) {
KeepAliveConfig keepAliveConfig = getKeepAliveConfig(keepAliveAttrVal.getStringValue());
listenerConfiguration.setKeepAliveConfig(keepAliveConfig);
} else {
listenerConfiguration.setKeepAliveConfig(KeepAliveConfig.AUTO);
}
RequestSizeValidationConfig requestSizeValidationConfig = listenerConfiguration.getRequestSizeValidationConfig();
if (maxUriLength != null) {
if (maxUriLength.getIntValue() > 0) {
requestSizeValidationConfig.setMaxUriLength(Math.toIntExact(maxUriLength.getIntValue()));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxUriLength : " + maxUriLength.getIntValue());
}
}
if (maxHeaderSize != null) {
if (maxHeaderSize.getIntValue() > 0) {
requestSizeValidationConfig.setMaxHeaderSize(Math.toIntExact(maxHeaderSize.getIntValue()));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxHeaderSize : " + maxHeaderSize.getIntValue());
}
}
if (maxEntityBodySize != null) {
if (maxEntityBodySize.getIntValue() > 0) {
requestSizeValidationConfig.setMaxEntityBodySize(Math.toIntExact(maxEntityBodySize.getIntValue()));
} else {
throw new BallerinaConnectorException("Invalid configuration found for maxEntityBodySize : " + maxEntityBodySize.getIntValue());
}
}
if (versionAttrVal != null) {
listenerConfiguration.setVersion(versionAttrVal.getStringValue());
}
listenerConfiguration.setId(getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
listenerConfSet.add(listenerConfiguration);
}
}
use of org.wso2.transport.http.netty.config.ListenerConfiguration in project ballerina by ballerina-lang.
the class HttpConnectionManager method createHttpServerConnector.
public ServerConnector createHttpServerConnector(ListenerConfiguration listenerConfig) {
String listenerInterface = listenerConfig.getHost() + ":" + listenerConfig.getPort();
HttpServerConnectorContext httpServerConnectorContext = serverConnectorPool.get(listenerInterface);
if (httpServerConnectorContext != null) {
if (checkForConflicts(listenerConfig, httpServerConnectorContext)) {
throw new BallerinaConnectorException("Conflicting configuration detected for listener " + "configuration id " + listenerConfig.getId());
}
httpServerConnectorContext.incrementReferenceCount();
return httpServerConnectorContext.getServerConnector();
}
if (isHTTPTraceLoggerEnabled()) {
listenerConfig.setHttpTraceLogEnabled(true);
}
serverBootstrapConfiguration = HTTPConnectorUtil.getServerBootstrapConfiguration(trpConfig.getTransportProperties());
ServerConnector serverConnector = httpConnectorFactory.createServerConnector(serverBootstrapConfiguration, listenerConfig);
httpServerConnectorContext = new HttpServerConnectorContext(serverConnector, listenerConfig);
serverConnectorPool.put(serverConnector.getConnectorID(), httpServerConnectorContext);
httpServerConnectorContext.incrementReferenceCount();
addStartupDelayedHTTPServerConnector(listenerInterface, serverConnector);
return serverConnector;
}
Aggregations