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
Post a Comment