Sep 18th, 2007, 05:30 AM
HTTP invoker and http request in bean
I have this question: is it possible to access HTTP request by encapsulated class with HttpInvokerServiceExporter?
<bean id="invokerService" class="invoker.InvokerServiceImpl"/>
<bean name="/InvokerService" class="org.springframework.remoting.httpinvoker.Ht tpInvokerServiceExporter">
<property name="service" ref="invokerService"/>
<property name="serviceInterface" value="invoker.InvokerService"/>
and I need to access the HTTP request from <code>invokerService</code> bean. Is there a way how to do this?
Why I need this? I need to check IP address on server side.
Thanks a lot.
Sep 20th, 2007, 11:59 AM
you can't by default accss the http request. you could use a filter to bind the current http request to a thread local variable and retrieve it then inside your service.
If you only need to check the ipadress of the caller (if it is a valid one), then i would do the check inside a filter (the filter will through an exception in case of an bad ip-adress of the requestor).
Sep 24th, 2007, 03:23 AM
Will this work correctly in multiuser application where is necessary to keep session for each user?
Sep 25th, 2007, 12:20 PM
if implemented correctly yes. The webcontainer uses one thread for each request at the same time, so you can use a threadlocal here.
You should take care to remove the value of the threadlocal after processing the request, otherwise you run into unpredictable situations. (This happens when the servlet container uses a thread pool and reuses the thread for a second request after the first request).
You can also use a Spring Implementation for this. Have a look at the class org.springframework.web.context.request.RequestCon textHolder, there you can retrieve an instance of the class org.springframework.web.context.request.ServletReq uestAttributes (you have to downcast it). The ServletRequestAttributes class offers you the http request through the method getRequest().
Last edited by Lyserg; Sep 25th, 2007 at 12:25 PM.
May 21st, 2008, 11:27 AM
I'm trying to get this to work as well. Is there an already existing spring filter class that exposes the http request useing RequestContextHolder? Can I just drop the "ExposeRequestFilter" into the filter chain? I saw that some spring classes already use the RequestContextHolder but could not figure if the ones I'm using already populate the thread-local varible.
Oct 11th, 2011, 01:28 AM
Getting Session id with spring
Hi, I have the same problem. I have an webapp where i have to store the username and the session id in every action the user does on the system.
So I got some way to do this, inthis way i have to create an HttpSession Object every time I want to get the session id.
So, now I want to know if there is another way to get the session id with an spring bean? How can I do it?