Search in sources :

Example 6 with ListenerConfiguration

use of org.wso2.transport.http.netty.contract.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);
    }
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) AnnAttrValue(org.ballerinalang.connector.api.AnnAttrValue) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) ChunkConfig(org.wso2.transport.http.netty.config.ChunkConfig) RequestSizeValidationConfig(org.wso2.transport.http.netty.config.RequestSizeValidationConfig) KeepAliveConfig(org.wso2.transport.http.netty.config.KeepAliveConfig)

Example 7 with ListenerConfiguration

use of org.wso2.transport.http.netty.contract.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;
}
Also used : ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException)

Example 8 with ListenerConfiguration

use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project carbon-apimgt by wso2.

the class RestApiUtil method getHost.

public static String getHost(String protocol) {
    TransportsConfiguration transportsConfiguration = YAMLTransportConfigurationBuilder.build();
    Set<ListenerConfiguration> listenerConfigurationSet = transportsConfiguration.getListenerConfigurations();
    String host = apimConfigurations.getHostname();
    if (!apimConfigurations.isReverseProxyEnabled()) {
        if (HTTP.equals(protocol)) {
            for (ListenerConfiguration listenerConfiguration : listenerConfigurationSet) {
                if (HTTP.equals(listenerConfiguration.getScheme())) {
                    host = host.concat(":").concat(String.valueOf(listenerConfiguration.getPort()));
                    break;
                }
            }
        } else {
            for (ListenerConfiguration listenerConfiguration : listenerConfigurationSet) {
                if (HTTPS.equals(listenerConfiguration.getScheme())) {
                    host = host.concat(":").concat(String.valueOf(listenerConfiguration.getPort()));
                }
            }
        }
    }
    return host;
}
Also used : ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) TransportsConfiguration(org.wso2.transport.http.netty.config.TransportsConfiguration)

Example 9 with ListenerConfiguration

use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project ballerina by ballerina-lang.

the class HttpUtil method extractHttpsConfig.

private static void extractHttpsConfig(Annotation configInfo, Set<ListenerConfiguration> listenerConfSet) {
    // Retrieve secure port from either http of ws configuration annotation.
    AnnAttrValue httpsPortAttrVal;
    if (configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTPS_PORT) == null) {
        httpsPortAttrVal = configInfo.getAnnAttrValue(WebSocketConstants.ANN_CONFIG_ATTR_WSS_PORT);
    } else {
        httpsPortAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HTTPS_PORT);
    }
    AnnAttrValue keyStoreFileAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEY_STORE_FILE);
    AnnAttrValue keyStorePasswordAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_KEY_STORE_PASS);
    AnnAttrValue certPasswordAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CERT_PASS);
    AnnAttrValue trustStoreFileAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRUST_STORE_FILE);
    AnnAttrValue trustStorePasswordAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_TRUST_STORE_PASS);
    AnnAttrValue sslVerifyClientAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_SSL_VERIFY_CLIENT);
    AnnAttrValue sslEnabledProtocolsAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_SSL_ENABLED_PROTOCOLS);
    AnnAttrValue ciphersAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CIPHERS);
    AnnAttrValue sslProtocolAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_SSL_PROTOCOL);
    AnnAttrValue hostAttrVal = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_HOST);
    AnnAttrValue certificateValidationEnabledAttrValue = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_VALIDATE_CERT_ENABLED);
    AnnAttrValue cacheSizeAttrValue = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CACHE_SIZE);
    AnnAttrValue cacheValidityPeriodAttrValue = configInfo.getAnnAttrValue(HttpConstants.ANN_CONFIG_ATTR_CACHE_VALIDITY_PERIOD);
    ListenerConfiguration listenerConfiguration = new ListenerConfiguration();
    if (httpsPortAttrVal != null && httpsPortAttrVal.getIntValue() > 0) {
        listenerConfiguration.setPort(Math.toIntExact(httpsPortAttrVal.getIntValue()));
        listenerConfiguration.setScheme(HttpConstants.PROTOCOL_HTTPS);
        if (hostAttrVal != null && hostAttrVal.getStringValue() != null) {
            listenerConfiguration.setHost(hostAttrVal.getStringValue());
        } else {
            listenerConfiguration.setHost(HttpConstants.HTTP_DEFAULT_HOST);
        }
        if (keyStoreFileAttrVal == null || keyStoreFileAttrVal.getStringValue() == null) {
            // TODO get from language pack, and add location
            throw new BallerinaConnectorException("Keystore location must be provided for secure connection");
        }
        if (keyStorePasswordAttrVal == null || keyStorePasswordAttrVal.getStringValue() == null) {
            // TODO get from language pack, and add location
            throw new BallerinaConnectorException("Keystore password value must be provided for secure connection");
        }
        if (certPasswordAttrVal == null || certPasswordAttrVal.getStringValue() == null) {
            // TODO get from language pack, and add location
            throw new BallerinaConnectorException("Certificate password value must be provided for secure connection");
        }
        if ((trustStoreFileAttrVal == null || trustStoreFileAttrVal.getStringValue() == null) && sslVerifyClientAttrVal != null) {
            // TODO get from language pack, and add location
            throw new BallerinaException("Truststore location must be provided to enable Mutual SSL");
        }
        if ((trustStorePasswordAttrVal == null || trustStorePasswordAttrVal.getStringValue() == null) && sslVerifyClientAttrVal != null) {
            // TODO get from language pack, and add location
            throw new BallerinaException("Truststore password value must be provided to enable Mutual SSL");
        }
        listenerConfiguration.setTLSStoreType(HttpConstants.PKCS_STORE_TYPE);
        listenerConfiguration.setKeyStoreFile(keyStoreFileAttrVal.getStringValue());
        listenerConfiguration.setKeyStorePass(keyStorePasswordAttrVal.getStringValue());
        listenerConfiguration.setCertPass(certPasswordAttrVal.getStringValue());
        if (sslVerifyClientAttrVal != null) {
            listenerConfiguration.setVerifyClient(sslVerifyClientAttrVal.getStringValue());
        }
        if (trustStoreFileAttrVal != null) {
            listenerConfiguration.setTrustStoreFile(trustStoreFileAttrVal.getStringValue());
        }
        if (trustStorePasswordAttrVal != null) {
            listenerConfiguration.setTrustStorePass(trustStorePasswordAttrVal.getStringValue());
        }
        if (certificateValidationEnabledAttrValue != null && certificateValidationEnabledAttrValue.getBooleanValue()) {
            listenerConfiguration.setValidateCertEnabled(certificateValidationEnabledAttrValue.getBooleanValue());
            if (cacheSizeAttrValue != null) {
                listenerConfiguration.setCacheSize((int) cacheSizeAttrValue.getIntValue());
            }
            if (cacheValidityPeriodAttrValue != null) {
                listenerConfiguration.setCacheValidityPeriod((int) cacheValidityPeriodAttrValue.getIntValue());
            }
        }
        List<Parameter> serverParams = new ArrayList<>();
        Parameter serverCiphers;
        if (sslEnabledProtocolsAttrVal != null && sslEnabledProtocolsAttrVal.getStringValue() != null) {
            serverCiphers = new Parameter(HttpConstants.ANN_CONFIG_ATTR_SSL_ENABLED_PROTOCOLS, sslEnabledProtocolsAttrVal.getStringValue());
            serverParams.add(serverCiphers);
        }
        if (ciphersAttrVal != null && ciphersAttrVal.getStringValue() != null) {
            serverCiphers = new Parameter(HttpConstants.ANN_CONFIG_ATTR_CIPHERS, ciphersAttrVal.getStringValue());
            serverParams.add(serverCiphers);
        }
        if (!serverParams.isEmpty()) {
            listenerConfiguration.setParameters(serverParams);
        }
        if (sslProtocolAttrVal != null) {
            listenerConfiguration.setSSLProtocol(sslProtocolAttrVal.getStringValue());
        }
        listenerConfiguration.setId(getListenerInterface(listenerConfiguration.getHost(), listenerConfiguration.getPort()));
        listenerConfSet.add(listenerConfiguration);
    }
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) AnnAttrValue(org.ballerinalang.connector.api.AnnAttrValue) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) ArrayList(java.util.ArrayList) Parameter(org.wso2.transport.http.netty.config.Parameter) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException)

Example 10 with ListenerConfiguration

use of org.wso2.transport.http.netty.contract.config.ListenerConfiguration in project ballerina by ballerina-lang.

the class HttpConnectionManager method getDefaultListenerConfiugrationSet.

public Set<ListenerConfiguration> getDefaultListenerConfiugrationSet() {
    Set<ListenerConfiguration> listenerConfigurationSet = new HashSet<>();
    for (ListenerConfiguration listenerConfiguration : trpConfig.getListenerConfigurations()) {
        listenerConfiguration.setId(listenerConfiguration.getHost() == null ? "0.0.0.0" : listenerConfiguration.getHost() + ":" + listenerConfiguration.getPort());
        listenerConfigurationSet.add(listenerConfiguration);
    }
    return listenerConfigurationSet;
}
Also used : ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) HashSet(java.util.HashSet)

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