Results 1 to 3 of 3

Thread: Managed httpsession objects ?

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Posts
    7

    Default Managed httpsession objects ?

    Is it possible to have spring set objects from a http session on other objects ?

    For example in a simple shoppingcart system I'd like to have an action with a method like this

    setShoppingCart(Cart cart)

    where cart is stored in the http session

  2. #2
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Spring, and DI in general, can set objects/properties from accessible existing Objects or from objects that can be created using some bean instantication / objects factories.
    If i understood your question, you need to extract an object from the HttpSession and then inject it into an other object. Well, could you please elaborate more as of:
    1. when will this be done? at your application startup ? then there is no HttpSession started yet...
    2. will you configure the DI using an applicationContext? AFAIK there is no mean to reference HttpSession from within objects configured in applicationContext
    3. you can use a Filter/servlet that extract the cart and put it in a ThredLocal and configure a factory that will read the cart and reference this factory in the destination object. But, is this worth the effort?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  3. #3
    Join Date
    Aug 2004
    Posts
    7

    Default

    1. when will this be done? at your application startup ? then there is no HttpSession started yet...
    obviously

    2. will you configure the DI using an applicationContext? AFAIK there is no mean to reference HttpSession from within objects configured in applicationContext
    That was kind of the implicit question, and the reason I initially posted this message in the core container forum. I figured there might be some build-in way to handle these things. using ioc/dep injection for session objects seams like a nice clean way to handle dependancies on session objects

    3. you can use a Filter/servlet that extract the cart and put it in a ThredLocal and configure a factory that will read the cart and reference this factory in the destination object. But, is this worth the effort?
    I am using spring with webwork and it has a threadlocal action context from which you can retrieve among other things the session map
    So writing a filter isn't necessary. Making things a lot easier.

    Since I apperently have to come up with my own method I guess I could
    take two approaches


    1) create a “singleton” proxy bean for the session object that delegates calls to the real object it stores in the session and retrieves it using a threadlocal

    2) create the object using a static factory method that creates session objects

    Code:
    public static Object createInstance(String beanPrototypeName, String sessionkey)
    Code:
    <bean id="ShoppingCart" class="ShoppingCart" singleton="false" />
    
    <property name="shoppingCart">
      <bean class="SessionObjectFactory" factory-method="createInstance" singleton="false">
        <constructor-arg>
          <idref local="ShoppingCart" />
        </constructor-arg>
         ...
      </bean>
    </property>
    That seems like a cleaner approach
    That way I could prototype the session object in the application context
    and I wouldn't have to have seperate interface, implementation, proxy classes

    Let me know what you think

Similar Threads

  1. Replies: 1
    Last Post: Jun 24th, 2007, 10:58 AM
  2. Replies: 8
    Last Post: Jul 28th, 2005, 10:42 AM
  3. Replies: 0
    Last Post: Nov 25th, 2004, 11:26 AM
  4. Replies: 3
    Last Post: Sep 29th, 2004, 03:34 PM
  5. Automatic remoting of managed objects
    By scornflake in forum JMS
    Replies: 2
    Last Post: Sep 14th, 2004, 09:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •