java - Access Session attributes in aspect -


i'm trying access session attributes in aspectj @aspect. when have exception bellow.

java.lang.illegalstateexception: no thread-bound request found: referring request attributes outside of actual web request, or processing request outside of receiving thread? if operating within web request , still receive message, code running outside of dispatcherservlet/dispatcherportlet: in case, use requestcontextlistener or requestcontextfilter expose current request.

@aspect @component public class globalfilter {  @autowired private entitymanager entitymanager;  private static httpsession httpsession() {     servletrequestattributes attr = (servletrequestattributes) requestcontextholder.currentrequestattributes();     return attr.getrequest().getsession(true); }  @before("execution(public !void org.springframework.data.repository.repository+.find*(..))") public void beforefind() {     httpsession httpsession = httpsession();      long idclient = (long) httpsession.getattribute(sessionkeys.id_client);     long iduser = (long) httpsession.getattribute(sessionkeys.id_user);      if (idclient != null) {          enablefilter(databasefilter.id_user, databasefilter.id_user_param_name, iduser);         enablefilter(databasefilter.id_client, databasefilter.id_client_param_name, idclient);         enablefilter(databasefilter.id_client_by_user, databasefilter.id_client_param_name, idclient);     } }  private void enablefilter(string filtername, string filterparamname, long filtervalue) {     filter filteruser = entitymanager.unwrap(session.class).enablefilter(filtername);     filteruser.setparameter(filterparamname, filtervalue); } } 

i tried inject session :

@autowired private entitymanager entitymanager; 

it seems httpsession , aspect not executed in same thread causing problem.

so have 2 questions : - there way session information in aspect ? how ?

  • if ignore exception, problem if 2 users use application @ same time ? aspect thread safe or 2 sessions mixed in aspect ?

i using spring boot.

thank in advance.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -