AttributeContainer sessionWrapper = (AttributeContainer) HttpSessionWrapper.wrapItIfNecessary(req.getSession());
if (!Config.getInstance().isEnabled() || !NavigationManagerFactory.existsInstance(sessionWrapper)) {
filterChain.doFilter(servletRequest, servletResponse);
} else {
NavigationManager navigationManager = NavigationManagerFactory.getInstance(sessionWrapper);
Object lock = navigationManager.getLock();
boolean isFirst = (lock == null);
try {
if (isFirst) {
synchronized (req.getSession()) {
lock = navigationManager.getLock();
isFirst = (lock == null);
if (isFirst) {
lock = new Object();
navigationManager.setLock(lock);
filterChain.doFilter(servletRequest, servletResponse);
}
}
}
} finally {
if (isFirst) {
synchronized (req.getSession()) {
synchronized (lock) {
navigationManager.setLock(null);
lock.notifyAll();
}
}
} else {
synchronized (lock) {
Object currentLock = navigationManager.getLock();
if (currentLock == lock) {
try {
lock.wait();
} catch (InterruptedException ie) {
log.warn("Interrupted exception");
}
}
}
synchronized (req.getSession()) {
String url = navigationManager.getCurrentPage();
String rewrittenUrl = ((urlRewriter != null) ? urlRewriter.rewriteUrl(url) : url);
String fullUrl = req.getContextPath() + rewrittenUrl;
HttpServletResponse res = (HttpServletResponse) servletResponse;
res.sendRedirect(fullUrl);
}