Search in sources :

Example 11 with ListenerConfiguration

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;
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

Example 12 with 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;
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) ArrayList(java.util.ArrayList) Parameter(org.apache.axis2.description.Parameter) OMElement(org.apache.axiom.om.OMElement)

Aggregations

BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)6 ListenerConfiguration (org.wso2.transport.http.netty.config.ListenerConfiguration)6 ArrayList (java.util.ArrayList)3 Struct (org.ballerinalang.connector.api.Struct)3 BStruct (org.ballerinalang.model.values.BStruct)3 AnnAttrValue (org.ballerinalang.connector.api.AnnAttrValue)2 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)2 Parameter (org.wso2.transport.http.netty.config.Parameter)2 RequestSizeValidationConfig (org.wso2.transport.http.netty.config.RequestSizeValidationConfig)2 ServerConnector (org.wso2.transport.http.netty.contract.ServerConnector)2 ListenerConfiguration (org.wso2.transport.http.netty.contract.config.ListenerConfiguration)2 HashSet (java.util.HashSet)1 OMElement (org.apache.axiom.om.OMElement)1 AxisFault (org.apache.axis2.AxisFault)1 Parameter (org.apache.axis2.description.Parameter)1 Scheme (org.apache.synapse.transport.http.conn.Scheme)1 NettyConfiguration (org.apache.synapse.transport.netty.config.NettyConfiguration)1 SourceConfiguration (org.apache.synapse.transport.netty.config.SourceConfiguration)1 HTTPServicesRegistry (org.ballerinalang.net.http.HTTPServicesRegistry)1 WebSocketServicesRegistry (org.ballerinalang.net.http.WebSocketServicesRegistry)1