java - How to access session from async thread -


i need use session-scope data in asynchronous job. job run spring @async annotation. achieve goal, request attributes first remembered in request thread:

currentattributes = requestcontextholder.getrequestattributes(); 

then, in thread running async job, request attributes restored:

requestcontextholder.setrequestattributes(currentattributes); 

almost works - session beans available. however, cannot access httpsession object - check if session still valid. in session-scoped bean:

@autowired transient private httpsession session; //... private boolean issessioninvalid() {     try {         session.getcreationtime();         return false;     } catch (illegalstateexception e) {         return true;     } } 

the call session.getcreationtime() throws illegalstateexception, when session still valid:

java.lang.illegalstateexception: request object has been recycled , no longer associated facade     @ org.apache.catalina.connector.requestfacade.getsession(requestfacade.java:904)     @ javax.servlet.http.httpservletrequestwrapper.getsession(httpservletrequestwrapper.java:240)     @ javax.servlet.http.httpservletrequestwrapper.getsession(httpservletrequestwrapper.java:240)     @ javax.servlet.http.httpservletrequestwrapper.getsession(httpservletrequestwrapper.java:240)     @ org.springframework.web.context.support.webapplicationcontextutils$sessionobjectfactory.getobject(webapplicationcontextutils.java:366)     @ org.springframework.web.context.support.webapplicationcontextutils$sessionobjectfactory.getobject(webapplicationcontextutils.java:361)     @ org.springframework.beans.factory.support.autowireutils$objectfactorydelegatinginvocationhandler.invoke(autowireutils.java:307) 

what can make session available async job? or, alternatively, there other way check session still valid?


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -