示例#1
0
public abstract class BaseAction implements Action {
  private static Logger jgLog = LoggerFactory.getLogger(BaseAction.class);

  public BaseAction() {}

  public ActionURL handleRequest(HttpServletRequest request, HttpServletResponse response)
      throws ActionException {
    // Common request code here (e.g., logging, etc.)

    return execute(request, response);
  }

  protected abstract ActionURL execute(HttpServletRequest request, HttpServletResponse response)
      throws ActionException;
}
示例#2
0
/**
 * Application filter that manages the web session.
 *
 * @author Curtis
 * @since 2011
 */
public class SessionFilter extends HttpServletFilter {
  private static Logger jgLog = LoggerFactory.getLogger(SessionFilter.class);

  public void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (initSession(request, response)) {
      chain.doFilter(request, response);
      cleanUpSession(request);
    } else {
      displayNoCookiePage(request, response);
    }
  }

  private boolean initSession(HttpServletRequest request, HttpServletResponse response)
      throws ServletException {
    try {
      WebSessionService.getInstance().getSession(request, response);
    } catch (SessionException e) {
      jgLog.error("ERROR INITIALIZING SESSION: " + e.getMessage());
      throw new ServletException(e.getMessage());
    } catch (CookieException e) {
      return false;
    }
    return true;
  }

  private void cleanUpSession(HttpServletRequest request) {
    try {
      WebSessionService.getInstance().saveSession(request);
    } catch (SessionException e) {
      jgLog.error("ERROR SETTING SESSION ATTRIBUTES");
    }
  }

  private void displayNoCookiePage(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    filterConfig
        .getServletContext()
        .getRequestDispatcher(ActionURL.NO_COOKIE.getURL())
        .forward(request, response);
  }
}