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.slf4j.Logger;
15  import org.slf4j.LoggerFactory;
16  
17  import javax.servlet.http.HttpServletRequest;
18  import javax.servlet.http.HttpServletResponse;
19  import java.io.IOException;
20  
21  /**
22   * A filter that handles cases where the application is unable to handle a normal request and redirects to the
23   * configured error path so that a nice error page can be provided.
24   */
25  public class JohnsonFilter extends AbstractJohnsonFilter
26  {
27      private static final Logger LOG = LoggerFactory.getLogger(JohnsonFilter.class);
28  
29      protected void handleError(JohnsonEventContainer appEventContainer, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
30      {
31          String servletPath = getServletPath(servletRequest);
32          String contextPath = servletRequest.getContextPath();
33          LOG.info("The application is still starting up, or there are errors. Redirecting request from '{}' to '{}'",
34                  servletPath, config.getErrorPath());
35          servletResponse.sendRedirect(contextPath + config.getErrorPath());
36      }
37  
38      protected void handleNotSetup(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException
39      {
40          String servletPath = getServletPath(servletRequest);
41          String contextPath = servletRequest.getContextPath();
42          LOG.info("The application is not yet setup. Redirecting request from '{}' to '{}'",
43                  servletPath, config.getSetupPath());
44          servletResponse.sendRedirect(contextPath + config.getSetupPath());
45      }
46  }