View Javadoc

1   package com.atlassian.johnson.filters;
2   
3   import com.atlassian.johnson.JohnsonEventContainer;
4   import org.slf4j.Logger;
5   import org.slf4j.LoggerFactory;
6   
7   import javax.servlet.http.HttpServletResponse;
8   import javax.servlet.http.HttpServletRequest;
9   import java.io.IOException;
10  
11  /**
12   * A handler that returns a no-content temporarily unavailable response suitable for refusing responses when an
13   * application is unable to handle normal requests. This is especially useful for cases where the normal response
14   * is of an unknown, or dynamic content-type and sending actual content may confuse clients.
15   * <p>
16   * Example uses include AJAX requests, generated images, pdf, excel and word docs.
17   */
18  public class Johnson503Filter extends AbstractJohnsonFilter
19  {
20      private static final Logger log = LoggerFactory.getLogger(Johnson503Filter.class);
21  
22      protected void handleError(JohnsonEventContainer appEventContainer, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
23      {
24          log.info("The application is unavailable, or there are errors.  Returing a temporarily unavailable status.");
25          servletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
26          // flushing the writer stops the app server from putting its html message into the otherwise empty response
27          servletResponse.getWriter().flush();
28      }
29  
30      protected void handleNotSetup(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
31      {
32          log.info("The application is not setup.  Returing a temporarily unavailable status.");
33          servletResponse.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
34          // flushing the writer stops the app server from putting its html message into the otherwise empty response
35          servletResponse.getWriter().flush();
36      }
37  }