pzampino commented on code in PR #929:
URL: https://github.com/apache/knox/pull/929#discussion_r1725029902


##########
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java:
##########
@@ -717,6 +723,21 @@ void createJetty() throws IOException, 
CertificateException, NoSuchAlgorithmExce
     jetty.setAttribute(ContextHandler.MAX_FORM_KEYS_KEY, 
config.getJettyMaxFormKeys());
     log.setMaxFormKeys(config.getJettyMaxFormKeys());
 
+    // Add a handler for the 404 responses when a topology is being redeployed 
(i.e., is inactive)
+    jetty.setErrorHandler(new ErrorHandler() {
+      @Override
+      public void doError(String target, Request baseRequest, 
HttpServletRequest request, HttpServletResponse response) throws IOException {
+        final int gatewayPrefixLength = ("/" + config.getGatewayPath() + 
"/").length();
+        String pathInfo = baseRequest.getPathInfo();
+        String topologyName = pathInfo.substring(gatewayPrefixLength, 
pathInfo.indexOf('/', gatewayPrefixLength));
+        if (isInactiveTopology(topologyName) && (response.getStatus() == 
HttpServletResponse.SC_NOT_FOUND)) {
+          request.setAttribute("javax.servlet.error.message", "Service 
Unavailable"); // The default ErrorHandler references this attribute
+          response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);

Review Comment:
   We could certainly log that fact, but I think the error messages (e.g., 
Service Unavailable) are pretty standard. Given the separation between status 
code and error message though, I could be persuaded otherwise.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@knox.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to