Announcement Announcement Module
No announcement yet.
HTTP invoker and http request in bean Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTTP invoker and http request in bean


    I have this question: is it possible to access HTTP request by encapsulated class with HttpInvokerServiceExporter?

    Sample code:
    <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.

  • #2

    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).



    • #3

      Will this work correctly in multiuser application where is necessary to keep session for each user?



      • #4

        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().

        best rgds
        Last edited by Lyserg; Sep 25th, 2007, 01:25 PM.


        • #5
          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.


          • #6
            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?

            Help please.