I've implemented a slingfilter that compiles without any issues but does not get invoked. Can't seem to figure out what the problem is, any ideas?
@SlingFilter(
generateComponent = true,
generateService = true,
order = -1000,
scope = SlingFilterScope.REQUEST)
public class GeoLocationFilter implements Filter {
private static final Logger log = LoggerFactory
.getLogger(GeoLocationFilter.class);
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
log.debug("filter init:");
try {
SlingHttpServletResponse slingResponse = (SlingHttpServletResponse)response;
SlingHttpServletRequest slingRequest = (SlingHttpServletRequest)request;
//proceed if current url is private wealth or domain contains nedbankprivatewealth
//else continue as normal
StringBuffer requestURL = slingRequest.getRequestURL();
if ( getUrlFilter( requestURL ) ) {
//check only for html
if (slingRequest.getResponseContentType().contains("html")) {
String currentUrl = slingRequest.getRequestURI();
//check if site contains cookie
String cookievalue = getCookie(request);
//if its a redirect or from selection
if (request.getParameter("npw_site") != null) {
//check if cookie present and its not a redirect
String url_parameter = "true";
if (!request.getParameter("npw_site").contains(url_parameter) ) {
if((cookievalue == null) || (cookievalue != request.getParameter("npw_site"))) {
Cookie cookie1 = new Cookie("npw_preferred_site", request.getParameter("npw_site"));
cookie1.setMaxAge(216000);
slingResponse.addCookie(cookie1);
}
}
chain.doFilter(request, response);
return;
}
} else {
chain.doFilter(request, response);
return;
}
} else {
chain.doFilter(request, response);
return;
}
} catch(Exception e){
log.error( e.getMessage());
}
}
@Override
public void init(FilterConfig filterConfig) throws ServletException {
// Usually, do nothing
}
@Override
public void destroy() {
// Usually, do nothing
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
I created a dummy filter which set cookies , working fine for me in AEM 6.3
aem63app-repo/DemoCookieFilter.java at master · arunpatidar02/aem63app-repo · GitHub
Thanks
Arun
Views
Replies
Total Likes
Hi,
I created a dummy filter which set cookies , working fine for me in AEM 6.3
aem63app-repo/DemoCookieFilter.java at master · arunpatidar02/aem63app-repo · GitHub
Thanks
Arun
Views
Replies
Total Likes
Nice answer!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies