Search in sources :

Example 1 with ConfigurationException

use of com.predic8.membrane.core.config.ConfigurationException in project service-proxy by membrane.

the class RuleManager method openPorts.

public synchronized void openPorts() throws IOException {
    HashMap<IpPort, SSLProvider> sslProviders;
    try {
        HashMap<IpPort, SSLContextCollection.Builder> sslContexts = new HashMap<IpPort, SSLContextCollection.Builder>();
        for (Rule rule : rules) {
            SSLContext sslContext = rule.getSslInboundContext();
            if (sslContext != null) {
                IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
                SSLContextCollection.Builder builder = sslContexts.get(ipPort);
                if (builder == null) {
                    builder = new SSLContextCollection.Builder();
                    sslContexts.put(ipPort, builder);
                }
                builder.add(sslContext);
            }
        }
        sslProviders = new HashMap<IpPort, SSLProvider>();
        for (Map.Entry<IpPort, SSLContextCollection.Builder> entry : sslContexts.entrySet()) sslProviders.put(entry.getKey(), entry.getValue().build());
    } catch (ConfigurationException e) {
        throw new IOException(e);
    }
    for (Rule rule : rules) {
        IpPort ipPort = new IpPort(rule.getKey().getIp(), rule.getKey().getPort());
        router.getTransport().openPort(rule.getKey().getIp(), rule.getKey().getPort(), sslProviders.get(ipPort));
    }
}
Also used : SSLContextCollection(com.predic8.membrane.core.transport.ssl.SSLContextCollection) HashMap(java.util.HashMap) IpPort(com.predic8.membrane.core.transport.http.IpPort) SSLContext(com.predic8.membrane.core.transport.ssl.SSLContext) IOException(java.io.IOException) ConfigurationException(com.predic8.membrane.core.config.ConfigurationException) SSLProvider(com.predic8.membrane.core.transport.ssl.SSLProvider) Rule(com.predic8.membrane.core.rules.Rule) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ConfigurationException (com.predic8.membrane.core.config.ConfigurationException)1 Rule (com.predic8.membrane.core.rules.Rule)1 IpPort (com.predic8.membrane.core.transport.http.IpPort)1 SSLContext (com.predic8.membrane.core.transport.ssl.SSLContext)1 SSLContextCollection (com.predic8.membrane.core.transport.ssl.SSLContextCollection)1 SSLProvider (com.predic8.membrane.core.transport.ssl.SSLProvider)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1