Created
September 8, 2012 00:14
-
-
Save fabrizioc1/3670877 to your computer and use it in GitHub Desktop.
Servlet filter to skip cache in WebSphere Commerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fct.wcs.cache; | |
import java.io.IOException; | |
import javax.servlet.Filter; | |
import javax.servlet.FilterChain; | |
import javax.servlet.FilterConfig; | |
import javax.servlet.ServletException; | |
import javax.servlet.ServletRequest; | |
import javax.servlet.ServletResponse; | |
import javax.servlet.http.HttpServletRequest; | |
import org.apache.commons.lang.StringUtils; | |
import com.ibm.commerce.server.JSPHelper; | |
public class NoCacheFilter implements Filter | |
{ | |
public static String NOCACHE_PARAMETER_NAME = "nocache"; | |
public static String NOCACHE_PARAMETER_VALUE = "true"; | |
@Override | |
public void destroy() { | |
} | |
@Override | |
public void doFilter( | |
ServletRequest request, ServletResponse response, | |
FilterChain chain) throws IOException, ServletException | |
{ | |
String noCache = request.getParameter(NOCACHE_PARAMETER_NAME); | |
if (!StringUtils.isEmpty(noCache) && noCache.equalsIgnoreCase(NOCACHE_PARAMETER_VALUE)) { | |
request.setAttribute(NOCACHE_PARAMETER_NAME, NOCACHE_PARAMETER_VALUE); | |
JSPHelper.setUncacheable(((HttpServletRequest)request), true); | |
} | |
chain.doFilter(request, response); | |
} | |
@Override | |
public void init(FilterConfig filterConfig) throws ServletException { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment