java - Access a HttpSession in a ClientHttpRequestInterceptor in Spring MVC -


i access sessions in spring mvc controllers @autowired this:

@autowired private httpsession session; 

the problem is, have access session within clienthttprequestinterceptor.

i tried requestcontextholder.getrequestattributes() result (sometimes - , real problem) null. tried requestcontextholder.currentrequestattributes() illegalstateexception thrown following message:

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.

the requestcontextlistener registered in web.xml.

<listener>     <listener-class>org.springframework.web.context.request.requestcontextlistener</listener-class> </listener> 

the same problem when inject session in clienthttprequestinterceptor directly.

@autowired private httpsession session; 

my question is: how can access current httpsession in clienthttprequestinterceptor?

thanks!

i think usage of clienthttpinterceptor class not in right place, because see in doc

intercepts client-side http requests. implementations of interface can registered resttemplate

means can use interceptor if server behaves likes client , example want modify every request send resttemplate. sample usage clienthttpinterceptor here.

you should use handlerinterceptor . see article here.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -