|
32 | 32 | import eu.openanalytics.shinyproxy.runtimevalues.AppInstanceKey;
|
33 | 33 | import eu.openanalytics.shinyproxy.runtimevalues.PublicPathKey;
|
34 | 34 | import eu.openanalytics.shinyproxy.runtimevalues.WebSocketReconnectionModeKey;
|
| 35 | +import io.undertow.server.HttpServerExchange; |
| 36 | +import io.undertow.servlet.handlers.ServletRequestContext; |
35 | 37 | import org.springframework.stereotype.Controller;
|
36 | 38 | import org.springframework.ui.ModelMap;
|
37 | 39 | import org.springframework.web.bind.annotation.RequestMapping;
|
|
40 | 42 | import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
41 | 43 |
|
42 | 44 | import javax.inject.Inject;
|
| 45 | +import javax.servlet.AsyncContext; |
| 46 | +import javax.servlet.ServletResponse; |
43 | 47 | import javax.servlet.http.HttpServletRequest;
|
44 | 48 | import javax.servlet.http.HttpServletResponse;
|
45 | 49 | import java.io.IOException;
|
@@ -114,6 +118,21 @@ public void appDirect(HttpServletRequest request, HttpServletResponse response)
|
114 | 118 | response.setStatus(410);
|
115 | 119 | response.getWriter().write("{\"status\":\"error\", \"message\":\"app_stopped_or_non_existent\"}");
|
116 | 120 | return;
|
| 121 | + } else if (proxy == null && (appRequestInfo.isCssOrJsResource() || request.getHeader("Upgrade") != null)) { |
| 122 | + // No proxy found and the request is for a CSS or JS file or a websocket connection. |
| 123 | + // We do not start a new proxy instance, because this is most probably a background request by an old, stopped app |
| 124 | + // We reply to the request after 10 seconds. This way the app should detect that it has been stopped before the resource is loaded. |
| 125 | + // (simply returning an error code could trigger the error handling logic of the app) |
| 126 | + response.setStatus(200); |
| 127 | + final AsyncContext acontext = request.startAsync(); |
| 128 | + acontext.start(() -> { |
| 129 | + try { |
| 130 | + Thread.sleep(10000); |
| 131 | + } catch (InterruptedException ignored) { |
| 132 | + } |
| 133 | + acontext.complete(); |
| 134 | + }); |
| 135 | + return; |
117 | 136 | } else if (proxy != null && appRequestInfo.getProxyIdHint() != null && !proxy.getId().equals(appRequestInfo.getProxyIdHint())) {
|
118 | 137 | // the proxy was restarted by the client before the client was aware that the app was stopped externally
|
119 | 138 | // therefore the proxy_id_hints are different.
|
|
0 commit comments