I am trying to get the request object so that I could get the application URL outside of the dispatch servlet. I tried all three methods below and it returned null.
Is there any other way to get the request object from the RequestContextListener
My web.xml has the following code.Code:ServletRequestAttributes r = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes(); HttpServletRequest req = r.getRequest(); HttpServletRequest req = FlexContext.getHttpRequest(); @Autowired private HttpServletRequest req; String completeURL = req.getRequestURL().toString() + "?" + req.getQueryString();
Code:<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <servlet> <servlet-name>springflex</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springflex</servlet-name> <url-pattern>/messagebroker/*</url-pattern> </servlet-mapping>Code:Caused by: 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. at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:123)


Reply With Quote
