Search in sources :

Example 6 with ProxyHandler

use of io.undertow.server.handlers.proxy.ProxyHandler in project wildfly-swarm by wildfly-swarm.

the class TopologyProxyService method updateProxyHosts.

private void updateProxyHosts(String serviceName, List<Topology.Entry> entries) {
    HttpHandler proxyHandler = proxyHandlerMap.get(serviceName).getOptionalValue();
    if (proxyHandler == null) {
        // Service has been shutdown
        proxyHandlerMap.remove(serviceName);
        return;
    }
    LoadBalancingProxyClient proxyClient = null;
    // which then wraps the next handler in the chain
    if (proxyHandler instanceof GlobalRequestControllerHandler) {
        // next in the chain of handlers
        ProxyHandler proxy = (ProxyHandler) ((GlobalRequestControllerHandler) proxyHandler).getNext();
        proxyClient = (LoadBalancingProxyClient) proxy.getProxyClient();
    } else {
        proxyClient = (LoadBalancingProxyClient) ((ProxyHandler) proxyHandler).getProxyClient();
    }
    List<Topology.Entry> oldEntries = proxyEntries.get(serviceName);
    List<Topology.Entry> entriesToRemove = new ArrayList<>();
    List<Topology.Entry> entriesToAdd = new ArrayList<>();
    if (oldEntries == null) {
        entriesToAdd.addAll(entries);
    } else {
        for (Topology.Entry oldEntry : oldEntries) {
            if (!entries.contains(oldEntry)) {
                entriesToRemove.add(oldEntry);
            }
        }
        for (Topology.Entry entry : entries) {
            if (!oldEntries.contains(entry)) {
                entriesToAdd.add(entry);
            }
        }
    }
    for (Topology.Entry entry : entriesToRemove) {
        try {
            proxyClient.removeHost(entryToURI(entry));
        } catch (URISyntaxException ex) {
            log.log(Level.WARNING, "Error converting topology entry to URI", ex);
        }
    }
    for (Topology.Entry entry : entriesToAdd) {
        try {
            proxyClient.addHost(entryToURI(entry));
        } catch (URISyntaxException ex) {
            log.log(Level.WARNING, "Error converting topology entry to URI", ex);
        }
    }
    proxyEntries.put(serviceName, entries);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) GlobalRequestControllerHandler(org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler) ProxyHandler(io.undertow.server.handlers.proxy.ProxyHandler) ArrayList(java.util.ArrayList) Topology(org.wildfly.swarm.topology.Topology) URISyntaxException(java.net.URISyntaxException) LoadBalancingProxyClient(io.undertow.server.handlers.proxy.LoadBalancingProxyClient)

Example 7 with ProxyHandler

use of io.undertow.server.handlers.proxy.ProxyHandler in project keycloak by keycloak.

the class AbstractAdapterClusteredTest method prepareReverseProxy.

@Before
public void prepareReverseProxy() throws Exception {
    loadBalancerToNodes = new LoadBalancingProxyClient().addHost(NODE_1_URI, NODE_1_NAME).setConnectionsPerThread(10);
    // 1 hour for proxy request timeout, so we can debug the backend keycloak servers
    int maxTime = 3600000;
    reverseProxyToNodes = Undertow.builder().addHttpListener(HTTP_PORT_NODE_REVPROXY, ServerURLs.APP_SERVER_HOST).setIoThreads(2).setHandler(new ProxyHandler(loadBalancerToNodes, maxTime, ResponseCodeHandler.HANDLE_404)).build();
    reverseProxyToNodes.start();
}
Also used : ProxyHandler(io.undertow.server.handlers.proxy.ProxyHandler) LoadBalancingProxyClient(io.undertow.server.handlers.proxy.LoadBalancingProxyClient) Before(org.junit.Before)

Aggregations

ProxyHandler (io.undertow.server.handlers.proxy.ProxyHandler)7 LoadBalancingProxyClient (io.undertow.server.handlers.proxy.LoadBalancingProxyClient)6 HttpHandler (io.undertow.server.HttpHandler)4 URI (java.net.URI)4 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)3 Http2UpgradeHandler (io.undertow.server.protocol.http2.Http2UpgradeHandler)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Undertow (io.undertow.Undertow)2 HttpServerExchange (io.undertow.server.HttpServerExchange)2 AjpOpenListener (io.undertow.server.protocol.ajp.AjpOpenListener)2 AlpnOpenListener (io.undertow.server.protocol.http.AlpnOpenListener)2 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)2 Http2OpenListener (io.undertow.server.protocol.http2.Http2OpenListener)2 InetSocketAddress (java.net.InetSocketAddress)2 KeyManagementException (java.security.KeyManagementException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 UnrecoverableKeyException (java.security.UnrecoverableKeyException)2 CertificateException (java.security.cert.CertificateException)2