View Javadoc

1   /**
2    * Atlassian Source Code Template.
3    * User: Bobby
4    * Date: Apr 8, 2003
5    * Time: 9:07:18 AM
6    * CVS Revision: $Revision: 1.5 $
7    * Last CVS Commit: $Date: 2006/10/09 01:01:38 $
8    * Author of last CVS Commit: $Author: bkuo $
9    */
10  
11  package com.atlassian.johnson.filters;
12  
13  import com.atlassian.johnson.JohnsonEventContainer;
14  import org.apache.log4j.Category;
15  
16  import javax.servlet.http.HttpServletRequest;
17  import javax.servlet.http.HttpServletResponse;
18  import java.io.IOException;
19  
20  /**
21   * A filter that handles cases where the application is unable to handle a normal request and redirects to the
22   * configured error path so that a nice error page can be provided.
23   */
24  public class JohnsonFilter extends AbstractJohnsonFilter
25  {
26      public static final Category log = Category.getInstance(JohnsonFilter.class);
27  
28      public static final String ALREADY_FILTERED = JohnsonFilter.class.getName() + "_already_filtered";
29      public static final String URL_SETUP = "/secure/Setup!default.jspa";
30  
31      protected void handleError(JohnsonEventContainer appEventContainer, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
32      {
33          String servletPath = getServletPath(servletRequest);
34          String contextPath = servletRequest.getContextPath();
35          log.info("The application is still starting up, or there are errors.  Redirecting request from '" + servletPath + "' to '" + config.getErrorPath() + "'");
36          servletResponse.sendRedirect(contextPath + config.getErrorPath());
37      }
38  
39      protected void handleNotSetup(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
40      {
41          String servletPath = getServletPath(servletRequest);
42          String contextPath = servletRequest.getContextPath();
43          log.info("The application is not yet setup.  Redirecting request from '" + servletPath + "' to '" + config.getSetupPath() + "'");
44          servletResponse.sendRedirect(contextPath + config.getSetupPath());
45      }
46  }