|
20 | 20 | */
|
21 | 21 | package eu.openanalytics.containerproxy.util;
|
22 | 22 |
|
23 |
| -import java.io.IOException; |
24 |
| -import java.lang.reflect.Field; |
25 |
| -import java.net.URI; |
26 |
| -import java.nio.ByteBuffer; |
27 |
| -import java.util.HashMap; |
28 |
| -import java.util.Map; |
29 |
| -import java.util.Map.Entry; |
30 |
| -import java.util.concurrent.TimeUnit; |
31 |
| - |
32 |
| -import javax.inject.Inject; |
33 |
| -import javax.servlet.ServletException; |
34 |
| -import javax.servlet.http.HttpServletRequest; |
35 |
| -import javax.servlet.http.HttpServletResponse; |
36 |
| - |
37 |
| -import org.springframework.context.annotation.Lazy; |
38 |
| -import org.springframework.stereotype.Component; |
39 |
| - |
40 | 23 | import eu.openanalytics.containerproxy.service.hearbeat.HeartbeatService;
|
41 | 24 | import io.undertow.server.HttpHandler;
|
42 | 25 | import io.undertow.server.HttpServerExchange;
|
|
49 | 32 | import io.undertow.servlet.handlers.ServletRequestContext;
|
50 | 33 | import io.undertow.util.AttachmentKey;
|
51 | 34 | import io.undertow.util.PathMatcher;
|
| 35 | +import org.springframework.context.annotation.Lazy; |
| 36 | +import org.springframework.stereotype.Component; |
| 37 | + |
| 38 | +import javax.inject.Inject; |
| 39 | +import javax.servlet.ServletException; |
| 40 | +import javax.servlet.http.HttpServletRequest; |
| 41 | +import javax.servlet.http.HttpServletResponse; |
| 42 | +import java.io.IOException; |
| 43 | +import java.lang.reflect.Field; |
| 44 | +import java.net.URI; |
| 45 | +import java.nio.ByteBuffer; |
| 46 | +import java.util.HashMap; |
| 47 | +import java.util.Map; |
| 48 | +import java.util.Map.Entry; |
| 49 | +import java.util.concurrent.TimeUnit; |
| 50 | +import java.util.function.Consumer; |
52 | 51 |
|
53 | 52 | /**
|
54 | 53 | * This component keeps track of which proxy mappings (i.e. URL endpoints) are currently registered,
|
@@ -82,7 +81,7 @@ public synchronized void addMapping(String proxyId, String mapping, URI target)
|
82 | 81 | if (mappings.containsKey(mapping)) {
|
83 | 82 | return;
|
84 | 83 | }
|
85 |
| - |
| 84 | + |
86 | 85 | LoadBalancingProxyClient proxyClient = new LoadBalancingProxyClient() {
|
87 | 86 | @Override
|
88 | 87 | public void getConnection(ProxyTarget target, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, long timeout, TimeUnit timeUnit) {
|
@@ -132,17 +131,24 @@ public String getProxyId(String mapping) {
|
132 | 131 | * @throws ServletException If the dispatch fails for any other reason.
|
133 | 132 | */
|
134 | 133 | public void dispatchAsync(String mapping, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
|
| 134 | + dispatchAsync(mapping, request, response, null); |
| 135 | + } |
| 136 | + |
| 137 | + public void dispatchAsync(String mapping, HttpServletRequest request, HttpServletResponse response, Consumer<HttpServerExchange> exchangeCustomizer) throws IOException, ServletException { |
135 | 138 | HttpServerExchange exchange = ServletRequestContext.current().getExchange();
|
136 | 139 | exchange.putAttachment(ATTACHMENT_KEY_DISPATCHER, this);
|
137 |
| - |
| 140 | + |
138 | 141 | String queryString = request.getQueryString();
|
139 | 142 | queryString = (queryString == null) ? "" : "?" + queryString;
|
140 | 143 | String targetPath = PROXY_INTERNAL_ENDPOINT + "/" + mapping + queryString;
|
141 |
| - |
| 144 | + |
| 145 | + if (exchangeCustomizer != null) { |
| 146 | + exchangeCustomizer.accept(exchange); |
| 147 | + } |
142 | 148 | request.startAsync();
|
143 | 149 | request.getRequestDispatcher(targetPath).forward(request, response);
|
144 | 150 | }
|
145 |
| - |
| 151 | + |
146 | 152 | private static class ProxyPathHandler extends PathHandler {
|
147 | 153 |
|
148 | 154 | public ProxyPathHandler(HttpHandler defaultHandler) {
|
|
0 commit comments