Search in sources :

Example 1 with IpPort

use of com.predic8.membrane.core.transport.http.IpPort 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)

Example 2 with IpPort

use of com.predic8.membrane.core.transport.http.IpPort in project service-proxy by membrane.

the class HttpTransport method openPort.

/**
 * @param port
 * @throws IOException
 */
@Override
public synchronized void openPort(String ip, int port, SSLProvider sslProvider) throws IOException {
    if (isAnyThreadListeningAt(ip, port)) {
        return;
    }
    if (port == -1)
        throw new RuntimeException("The port-attribute is missing (probably on a <serviceProxy> element).");
    HttpEndpointListener portListenerThread = new HttpEndpointListener(ip, port, this, sslProvider);
    portListenerMapping.put(new IpPort(ip, port), portListenerThread);
    portListenerThread.start();
    for (IPortChangeListener listener : menuListeners) {
        listener.addPort(port);
    }
}
Also used : IPortChangeListener(com.predic8.membrane.core.model.IPortChangeListener)

Example 3 with IpPort

use of com.predic8.membrane.core.transport.http.IpPort in project service-proxy by membrane.

the class HttpTransport method closePort.

/**
 * Closes the corresponding server port. Note that connections might still be open and exchanges still running after
 * this method completes.
 */
public synchronized void closePort(String ip, int port) throws IOException {
    IpPort p = new IpPort(ip, port);
    log.debug("Closing server port: " + p);
    HttpEndpointListener plt = portListenerMapping.get(p);
    if (plt == null)
        return;
    plt.closePort();
    try {
        plt.join();
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    portListenerMapping.remove(p);
    stillRunning.add(new WeakReference<HttpEndpointListener>(plt));
    for (IPortChangeListener listener : menuListeners) {
        listener.removePort(port);
    }
}
Also used : IPortChangeListener(com.predic8.membrane.core.model.IPortChangeListener)

Aggregations

IPortChangeListener (com.predic8.membrane.core.model.IPortChangeListener)2 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