Search in sources :

Example 1 with ListenerConfiguration

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);
}
Also used : Scheme(org.apache.synapse.transport.http.conn.Scheme) DefaultHttpWsConnectorFactory(org.wso2.transport.http.netty.contractimpl.DefaultHttpWsConnectorFactory) ListenerConfiguration(org.wso2.transport.http.netty.contract.config.ListenerConfiguration) SourceConfiguration(org.apache.synapse.transport.netty.config.SourceConfiguration) ServerBootstrapConfiguration(org.wso2.transport.http.netty.contract.config.ServerBootstrapConfiguration)

Example 2 with 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;
}
Also used : AxisFault(org.apache.axis2.AxisFault) ListenerConfiguration(org.wso2.transport.http.netty.contract.config.ListenerConfiguration) NettyConfiguration(org.apache.synapse.transport.netty.config.NettyConfiguration)

Example 3 with 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);
        }
    }
}
Also used : BallerinaConnectorException(org.ballerinalang.connector.api.BallerinaConnectorException) RequestSizeValidationConfig(org.wso2.transport.http.netty.config.RequestSizeValidationConfig)

Example 4 with ListenerConfiguration

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

Example 5 with 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);
    }
}
Also used : ServerConnector(org.wso2.transport.http.netty.contract.ServerConnector) BStruct(org.ballerinalang.model.values.BStruct) HTTPServicesRegistry(org.ballerinalang.net.http.HTTPServicesRegistry) WebSocketServicesRegistry(org.ballerinalang.net.http.WebSocketServicesRegistry) ListenerConfiguration(org.wso2.transport.http.netty.config.ListenerConfiguration) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct)

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