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


##########
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:
   Just a thought, can we specify in the error message that the topology is 
inactive? This will be helpful in cases where we are debugging and knox the 
request failed because topology was inactive and not due to 500 error.
   



-- 
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