java - How to avoid IllegalStateException when referring to request attributes outside of an actual web request -


i working on solution should if in middle of web request or else if not.

what doing

@autowired private httpservletrequest request; 

and trying access variable:

request.getrequesturi() 

but getting java.lang.illegalstateexception: no thread-bound request found: referring request attributes outside of actual web request...

i avoid exception , somehow ask httpservletrequest weather or not in web request or not.

is there way it?

example: additional info:

@override public void trace(string msg) {      if (loggerfactory.isregisteredurl(request.getrequesturi())){         loggerfactory.getcustomelogger(request.getrequesturi()).trace(msg);         return;     }     nativelogger.trace(msg); } 

you should (not tested) use requestcontextholder.getrequestattributes():

return requestattributes bound thread.

returns: requestattributes bound thread, or null if none bound

so, if method returns null, current thread not handling request. if returns non-null value, handling one.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -