You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2017/03/13 10:55:26 UTC

svn commit: r1786657 - /qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/filter/ExceptionHandlingFilter.java

Author: kwall
Date: Mon Mar 13 10:55:26 2017
New Revision: 1786657

URL: http://svn.apache.org/viewvc?rev=1786657&view=rev
Log:
QPID-7682: Address review comments from lquack@apache.org

Modified:
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/filter/ExceptionHandlingFilter.java

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/filter/ExceptionHandlingFilter.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/filter/ExceptionHandlingFilter.java?rev=1786657&r1=1786656&r2=1786657&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/filter/ExceptionHandlingFilter.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/filter/ExceptionHandlingFilter.java Mon Mar 13 10:55:26 2017
@@ -28,11 +28,14 @@ import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.qpid.server.util.ConnectionScopedRuntimeException;
+import org.apache.qpid.server.util.ExternalServiceException;
+import org.apache.qpid.server.util.ExternalServiceTimeoutException;
 import org.apache.qpid.server.util.ServerScopedRuntimeException;
 
 public class ExceptionHandlingFilter implements Filter
@@ -63,6 +66,16 @@ public class ExceptionHandlingFilter imp
             }
             _uncaughtExceptionHandler.uncaughtException(Thread.currentThread(), e);
         }
+        catch (ExternalServiceTimeoutException e)
+        {
+            LOGGER.warn("External request timeout ", e);
+            sendError(e, servletResponse, HttpServletResponse.SC_GATEWAY_TIMEOUT);
+        }
+        catch (ExternalServiceException e)
+        {
+            LOGGER.warn("External request failed ", e);
+            sendError(e, servletResponse, HttpServletResponse.SC_BAD_GATEWAY);
+        }
         catch (IOException | ServletException e)
         {
             LOGGER.debug("Exception in servlet '{}': ", requestURI, e);
@@ -92,4 +105,18 @@ public class ExceptionHandlingFilter imp
     {
         // noop
     }
+
+    private void sendError(final RuntimeException underlyingException,
+                           final ServletResponse servletResponse,
+                           final int responseCode) throws IOException
+    {
+        if (servletResponse instanceof HttpServletResponse && !servletResponse.isCommitted())
+        {
+            ((HttpServletResponse) servletResponse).sendError(responseCode);
+        }
+        else
+        {
+            throw underlyingException;
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org