java - infinite loop while accessing resource folder -
in spring project have written filter handle requests.it works fine, while accessing resource infinite loop happening.
i defined resource folder under class extends webmvcconfigureradapter code used define resource folder:-
this request url:
@override public void addresourcehandlers(resourcehandlerregistry registry) { registry.addresourcehandler("/resources/**").addresourcelocations("/resources/"); } http://localhost:8080/abc/resources/images/chart/receivableaccounts.png
while accessing url through browser request proceesing number of times in console(eclipse).
i can't identify what's real problem is.
here requestfilter:
package org.abc.app.config; 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 javax.servlet.http.httpservletresponse; import org.apache.log4j.logmanager; import org.apache.log4j.logger; import org.businesscognizance.app.util.session; /** * <b>custom filter created handling incoming,outgoing requests</b> * * @author jishnu * */ public class requestfilter implements filter { private static logger logger = logmanager.getlogger(requestfilter.class); @override public void init(filterconfig filterconfig) throws servletexception { } @override public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception { httpservletresponse httpservletresponse = (httpservletresponse) response; httpservletrequest httpservletrequest = (httpservletrequest) request; string context = httpservletrequest.getcontextpath(); string requesturi = httpservletrequest.getrequesturi(); int status = httpservletresponse.getstatus(); system.out.println("hey there>>>>" + requesturi + "check this" + context + "/resources"); if (isauthenticated(httpservletrequest) || requesturi.equals(context + "/login") || requesturi.startswith(context + "/resources")) { logger.info("access granted device ip address" + " '" + httpservletrequest.getremoteaddr() + "' " + "for requested url" + " '" + httpservletrequest.getrequesturl() + "'"); if (isauthorized()) { } else { httpservletresponse.reset(); httpservletresponse.setstatus(httpservletresponse.sc_forbidden); return; } chain.dofilter(request, response); } else { httpservletresponse.reset(); if (status == httpservletresponse.sc_accepted || status == httpservletresponse.sc_ok) { httpservletresponse.setstatus(httpservletresponse.sc_bad_request); } else { httpservletresponse.setstatus(status); } httpservletresponse.getwriter().println("server rejected request"); return; } } @override public void destroy() { } public boolean isauthorized() { return true; } public boolean isauthenticated(httpservletrequest request) { string accesstoken = request.getheader("access_token"); boolean result = false; if (accesstoken != null) { if (session.iftokenexists(accesstoken)) { result = true; } } return result; }
}
if need further please let me know.
any suggestion useful.
thank you
it seems hokey implementation of:
- a pre-authenticated request.
- request static resources.
this looks straight outta 2003 codebase; suggest start extending onceperrequestfilter
, make filter @component
. since isauthorized
method nothing, can straightaway bypass filter urls overriding shouldnotfilter method. , have read javadoc httpservletresponse
? calling reset resets status code, kinda code useless status == httpservletresponse.sc_accepted || status == httpservletresponse.sc_ok
.
i know doesn't address so-called infinite loop problem, once clean up, may not have such issue. last not least, debugger; you've code, don't.
Comments
Post a Comment