View Javadoc

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