use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project ballerina by ballerina-lang.
the class InitEndpoint method getListerConfig.
private ListenerConfiguration getListerConfig(Struct endpointConfig) {
String host = endpointConfig.getStringField(HttpConstants.ENDPOINT_CONFIG_HOST);
long port = endpointConfig.getIntField(HttpConstants.ENDPOINT_CONFIG_PORT);
String keepAlive = endpointConfig.getEnumField(HttpConstants.ENDPOINT_CONFIG_KEEP_ALIVE);
String transferEncoding = endpointConfig.getEnumField(HttpConstants.ENDPOINT_CONFIG_TRANSFER_ENCODING);
String chunking = endpointConfig.getEnumField(HttpConstants.ENDPOINT_CONFIG_CHUNKING);
Struct sslConfig = endpointConfig.getStructField(HttpConstants.ENDPOINT_CONFIG_SECURE_SOCKET);
String httpVersion = endpointConfig.getStringField(HttpConstants.ENDPOINT_CONFIG_VERSION);
Struct requestLimits = endpointConfig.getStructField(HttpConstants.ENDPOINT_REQUEST_LIMITS);
ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
if (host == null || host.isEmpty()) {
listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
} else {
listenerConfiguration.setHost(host);
}
listenerConfiguration.setPort(Math.toIntExact(port));
listenerConfiguration.setKeepAliveConfig(HttpUtil.getKeepAliveConfig(keepAlive));
// chunking. Once we start supporting gzip, deflate, etc, we need to parse down the config.
if ((!transferEncoding.isEmpty()) && !HttpConstants.ANN_CONFIG_ATTR_CHUNKING.equalsIgnoreCase(transferEncoding)) {
throw new BallerinaConnectorException("Unsupported configuration found for Transfer-Encoding : " + transferEncoding);
}
listenerConfiguration.setChunkConfig(HttpUtil.getChunkConfig(chunking));
// Set Request validation limits.
if (requestLimits != null) {
setRequestSizeValidationConfig(requestLimits, listenerConfiguration);
}
// Set HTTP version
if (httpVersion != null) {
listenerConfiguration.setVersion(httpVersion);
}
if (sslConfig != null) {
return setSslConfig(sslConfig, listenerConfiguration);
}
listenerConfiguration.setServerHeader(getServerName());
return listenerConfiguration;
}
use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project wso2-synapse by wso2.
the class RequestResponseUtils method setSslConfig.
public static ListenerConfiguration setSslConfig(TransportInDescription transportIn, ListenerConfiguration listenerConfiguration, BaseConfiguration sourceConfiguration) throws AxisFault {
List<org.wso2.transport.http.netty.contract.config.Parameter> serverParamList = new ArrayList<>();
listenerConfiguration.setScheme(BridgeConstants.PROTOCOL_HTTPS);
// evaluate keystore field
Parameter keyParam = transportIn.getParameter(BridgeConstants.KEY_STORE);
OMElement keyStoreEl = keyParam != null ? keyParam.getParameterElement() : null;
SecretResolver secretResolver = sourceConfiguration.getConfigurationContext().getAxisConfiguration().getSecretResolver();
populateKeyStoreConfigs(keyStoreEl, listenerConfiguration, secretResolver);
// evaluate truststore field
Parameter trustParam = transportIn.getParameter(BridgeConstants.TRUST_STORE);
OMElement trustStoreEl = trustParam != null ? trustParam.getParameterElement() : null;
populateTrustStoreConfigs(trustStoreEl, listenerConfiguration, secretResolver);
// evaluate SSLVerifyClient field
Parameter clientAuthParam = transportIn.getParameter(BridgeConstants.SSL_VERIFY_CLIENT);
OMElement clientAuthEl = clientAuthParam != null ? clientAuthParam.getParameterElement() : null;
final String s = clientAuthEl != null ? clientAuthEl.getText() : "";
listenerConfiguration.setVerifyClient(s);
// evaluate HttpsProtocols and SSLProtocol fields
Parameter httpsProtocolsParam = transportIn.getParameter(BridgeConstants.HTTPS_PROTOCOL);
OMElement httpsProtocolsEl = httpsProtocolsParam != null ? httpsProtocolsParam.getParameterElement() : null;
Parameter sslParameter = transportIn.getParameter(BridgeConstants.SSL_PROTOCOL);
String sslProtocol = sslParameter != null && sslParameter.getValue() != null ? sslParameter.getValue().toString() : BridgeConstants.TLS_PROTOCOL;
populateProtocolConfigs(httpsProtocolsEl, sslProtocol, listenerConfiguration, serverParamList);
// evaluate PreferredCiphers field
Parameter preferredCiphersParam = transportIn.getParameter(BridgeConstants.PREFERRED_CIPHERS);
OMElement preferredCiphersEl = preferredCiphersParam != null ? preferredCiphersParam.getParameterElement() : null;
populateCiphersConfigs(preferredCiphersEl, serverParamList);
// evaluate CertificateRevocationVerifier field
Parameter cvpParam = transportIn.getParameter(BridgeConstants.CLIENT_REVOCATION);
OMElement cvpEl = cvpParam != null ? cvpParam.getParameterElement() : null;
populateCertValidationConfigs(cvpEl, listenerConfiguration);
// evaluate common fields
Parameter sessionTimeoutParam = transportIn.getParameter(BridgeConstants.SSL_SESSION_TIMEOUT);
Parameter handshakeTimeoutParam = transportIn.getParameter(BridgeConstants.SSL_HANDSHAKE_TIMEOUT);
String sessionTimeoutEl = sessionTimeoutParam != null && sessionTimeoutParam.getValue() != null ? sessionTimeoutParam.getValue().toString() : null;
String handshakeTimeoutEl = handshakeTimeoutParam != null && handshakeTimeoutParam.getValue() != null ? handshakeTimeoutParam.getValue().toString() : null;
populateTimeoutConfigs(sessionTimeoutEl, handshakeTimeoutEl, listenerConfiguration);
if (!serverParamList.isEmpty()) {
listenerConfiguration.setParameters(serverParamList);
}
listenerConfiguration.setId(getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
return listenerConfiguration;
}
Aggregations