Java tutorial
/** * * Copyright (C) 2002-2012 "SYSNET International, Inc." * support@sysnetint.com [http://www.sysnetint.com] * * This file is part of OpenEMPI. * * OpenEMPI is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.openhie.openempi.webapp.filter; import java.io.IOException; import javax.servlet.FilterChain; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Borrowed from the Display Tag project: * http://displaytag.sourceforge.net/xref-test/org/displaytag/filter/MockFilterSupport.html * * Todo: look into using Spring's MockFilterChain: * http://www.springframework.org/docs/api/org/springframework/mock/web/MockFilterChain.html */ public class MockFilterChain implements FilterChain { private final Log log = LogFactory.getLog(MockFilterChain.class); private String forwardURL; public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException { String uri = ((HttpServletRequest) request).getRequestURI(); String requestContext = ((HttpServletRequest) request).getContextPath(); if (StringUtils.isNotEmpty(requestContext) && uri.startsWith(requestContext)) { uri = uri.substring(requestContext.length()); } this.forwardURL = uri; log.debug("Forwarding to: " + uri); RequestDispatcher dispatcher = request.getRequestDispatcher(uri); dispatcher.forward(request, response); } public String getForwardURL() { return this.forwardURL; } }