I have a web-item in a confluence-plugin which I only want to be displayed when a certain session attribute is set. However I cannot manage to access the HttpServletRequest or HttpSession from within the condition class.
I tried
HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
but that gives me:
java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
Since I cannot do as the exception message suggests from my plugin perspective, what is the preferred way to access the request in this context?
Community moderators have prevented the ability to post new answers.
Try this:
HttpServletRequest request = ServletActionContext.getRequest();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.