This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting request object outside of DispatchServlet.

 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where are you putting this code? In a Spring MVC Controller, a Servlet, a Struts Action. We need a little more context.

Mark
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I should have attached this earlier.

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next question, how is that code being called. If is comes from a request already and goes first into the Controller or Action, then just get the data out of the request there and pass that down.

I think there is a design/architecture design flaw where you would need the HttpServletRequest passing into a non-controller/action class.

Mark
 
Jay Abrahm
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Spring container (if I can use that work here) calls this class since I have AbstractRoutingDataSource defined.

I basically need the HttpServletRequest so that I can get the URL to decide the datasource to connect to. If I can get the URL parameters in any other way that should do just fine.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I think personally I would use a standard filter to do this as it will have to be set for each request. That way you get the request passed in anyway to do your logic.

Sean
 
MarK sujoKi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Jay Abrahm

Were you able to get the request object outside of DispatchServlet? If yes, could you please share how?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark. I think it would be best to create a new thread with any question that you might have. Basically, putting your question into better context.

Thanks

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic