use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project wso2-synapse by wso2.
the class Axis2HttpTransportListener method init.
@Override
public void init(ConfigurationContext configurationContext, TransportInDescription transportInDescription) throws AxisFault {
Scheme scheme = initScheme();
this.transportInDescription = transportInDescription;
// build source configuration
sourceConfiguration = new SourceConfiguration(configurationContext, transportInDescription, scheme, messagingHandlers);
sourceConfiguration.build();
sourceConfiguration.getHttpGetRequestProcessor().init(sourceConfiguration.getConfigurationContext());
ListenerConfiguration listenerConfiguration = initListenerConfiguration();
httpWsConnectorFactory = new DefaultHttpWsConnectorFactory();
this.serverConnector = httpWsConnectorFactory.createServerConnector(new ServerBootstrapConfiguration(new HashMap<>()), listenerConfiguration);
}
use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project wso2-synapse by wso2.
the class RequestResponseUtils method getListenerConfig.
/**
* Returns Listener configuration instance populated with source configuration.
*
* @param sourceConfiguration source configuration
* @return transport listener configuration instance
*/
public static ListenerConfiguration getListenerConfig(SourceConfiguration sourceConfiguration, boolean sslEnabled) throws AxisFault {
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
listenerConfiguration.setPort(sourceConfiguration.getPort());
listenerConfiguration.setHost(sourceConfiguration.getHost());
listenerConfiguration.setVersion(sourceConfiguration.getProtocol());
NettyConfiguration globalConfig = NettyConfiguration.getInstance();
// Set Request validation limits.
boolean isRequestLimitsValidationEnabled = globalConfig.isRequestLimitsValidationEnabled();
if (isRequestLimitsValidationEnabled) {
setInboundMgsSizeValidationConfig(globalConfig.getMaxStatusLineLength(), globalConfig.getMaxHeaderSize(), globalConfig.getMaxEntityBodySize(), listenerConfiguration.getMsgSizeValidationConfig());
}
int idleTimeout = globalConfig.getSocketTimeout();
if (idleTimeout < 0) {
throw new AxisFault("Idle timeout cannot be negative. If you want to disable the " + "timeout please use value 0");
}
listenerConfiguration.setSocketIdleTimeout(idleTimeout);
// Pipelining is disabled all the time
listenerConfiguration.setPipeliningEnabled(false);
if (isHTTPTraceLoggerEnabled()) {
listenerConfiguration.setHttpTraceLogEnabled(true);
}
if (isHTTPAccessLoggerEnabled()) {
listenerConfiguration.setHttpAccessLogEnabled(true);
}
if (sslEnabled) {
return setSslConfig(sourceConfiguration.getInDescription(), listenerConfiguration, sourceConfiguration);
}
return listenerConfiguration;
}
use of org.wso2.transport.http.netty.contract.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.contract.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.contract.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);
}
}
Aggregations