@Override public HttpHandler wrap(HttpHandler handler) { final LoadBalancingProxyClient loadBalancingProxyClient = new LoadBalancingProxyClient(); for (URI url : uris) { loadBalancingProxyClient.addHost(url); } return new ProxyHandler(loadBalancingProxyClient, -1, handler, rewriteHostHeader, false); } }
/** * Returns a handler that can act as a load balancing reverse proxy. * * @param proxyClient The proxy client to use to connect to the remote server * @return The proxy handler */ public static ProxyHandler proxyHandler(ProxyClient proxyClient) { return ProxyHandler.builder().setProxyClient(proxyClient).build(); }
/** * Returns a handler that can act as a load balancing reverse proxy. * * @param proxyClient The proxy client to use to connect to the remote server * @param maxRequestTime The maximum amount of time a request can be in progress before it is forcibly closed * @param next The next handler to invoke if the proxy client does not know how to proxy the request * @return The proxy handler */ public static ProxyHandler proxyHandler(ProxyClient proxyClient, int maxRequestTime, HttpHandler next) { return ProxyHandler.builder().setProxyClient(proxyClient).setNext(next).setMaxRequestTime(maxRequestTime).build(); } /**
public ProxyHandler build() { return new ProxyHandler(this); } }
@Override public void failed(IOException e) { if (!exclusive) { data.connections--; } UndertowLogger.REQUEST_LOGGER.debug("Failed to connect", e); if (!connectionPoolManager.handleError()) { redistributeQueued(getData()); scheduleFailedHostRetry(exchange); } callback.failed(exchange); } }, bindAddress, getUri(), exchange.getIoThread(), ssl, exchange.getConnection().getByteBufferPool(), options);
@Override public void run() { cancelled = true; callback.failed(exchange); }
@Override public void couldNotResolveBackend(HttpServerExchange exchange) { callback.couldNotResolveBackend(exchange); } }, timeout, timeUnit, true);
@Override public void queuedRequestFailed(HttpServerExchange exchange) { callback.queuedRequestFailed(exchange); }
@Override public void run() { clientHandler.cancel(exchange); } }, maxRequestTime, TimeUnit.MILLISECONDS);
@Override public void queuedRequestFailed(HttpServerExchange exchange) { failed(exchange); }
@Override public void failed(IOException e) { handleFailure(exchange, proxyClientHandler, idempotentPredicate, e); } });
/** * Should only be used for tests * * DO NOT CALL THIS METHOD WHEN REQUESTS ARE IN PROGRESS * * It is not thread safe so internal state can get messed up. */ public void closeCurrentConnections() { for(Host host : hosts) { host.closeCurrentConnections(); } }
private Host(String jvmRoute, InetSocketAddress bindAddress, URI uri, XnioSsl ssl, OptionMap options) { this.connectionPool = new ProxyConnectionPool(this, bindAddress, uri, ssl, client, options); this.jvmRoute = jvmRoute; this.uri = uri; this.ssl = ssl; }
@Override public boolean isAvailable() { return delegate.isAvailable(); }
/** * Returns a handler that can act as a load balancing reverse proxy. * * @param proxyClient The proxy client to use to connect to the remote server * @param next The next handler to invoke if the proxy client does not know how to proxy the request * @return The proxy handler */ public static ProxyHandler proxyHandler(ProxyClient proxyClient, HttpHandler next) { return ProxyHandler.builder().setProxyClient(proxyClient).setNext(next).build(); }
@Override public void failed(IOException e) { callback.failed(exchange); } }
@Override public void couldNotResolveBackend(HttpServerExchange exchange) { callback.couldNotResolveBackend(exchange); } };
@Override public void queuedRequestFailed(HttpServerExchange exchange) { callback.queuedRequestFailed(exchange); }
@Override public void failed(IOException e) { handleFailure(exchange, proxyClientHandler, idempotentPredicate, e); } }
@Override public void failed(HttpServerExchange exchange) { callback.failed(exchange); }