Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How do I access the request (or session) from within the condition class of a web-item

pfahsel January 19, 2016

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?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Panos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2016

Try this:

HttpServletRequest request = ServletActionContext.getRequest();
pfahsel February 8, 2016

Works like a charm. Thank you smile

TAGS
AUG Leaders

Atlassian Community Events