HttpservletRequest and response in Spring JMS listener
-
14-11-2019 - |
Question
Can someone tell whether is there a way to get HttpServletRequest and HttpServletResponse in Spring JMS listener class? My JMS listener is defined in springContext.xml file.
Solution 2
I ended up using JAXDispatcher
to invoke my service, from my JMS listener.
jaxbDispatcher.doGET(null, url, null, "application/xml", true);
OTHER TIPS
First of all you don't have access to HTTP servlet request and response within JMS listeners. These are completely independent modules that can even reside on different physical servers.
You can use MockHttpServletRequest
and MockHttpServletResponse
from spring-test.jar
- but they are meant to be used within unit/integration tests, not in production code.
I would really like to see your code that requires MockHttpServletRequest
and response. My guess is that it can be refactored or redesigned to use only relevant fields from the above, like request URL or user name.