Re: Fw: Using the HttpSession object with openamf

Todd Hivnor <[email protected]>
Newsgroups gmane.comp.java.openamf.user
Message-ID <[email protected]>
I use sessions with OpenAMF, and haven't had any troubles. Be sure the 
client has cookies enabled, of course.

I don't access HttpSession, I let OpenAMF manage all this. I store my 
user data in a dedicated data object. This class just nothing but the 
data I want stored in session. It implements Serializable. It also 
implements HttpSessionBindingListener, so I can see when it gets created 
and destroyed.

All my service functions take this data object as an argument. That is, 
they get the session data as a direct parameter. I don't have to do 
anything special with RequestContext or HttpSession to get at this data. 
(As an aside, I do use RequestContext.getHttpSession(), but for other 
reasons. Sometimes I want to know the servername, for example.)

In my openamf-config.xml file, I have:

    <state-bean>
        <name>LearnerData</name>
        <class>com.example.LearnerData</class>
        <scope>session</scope>
    </state-bean>   

    <service>
        <name>LearnerService</name>
        <service-location>com.example.LearnerService</service-location>
        <invoker-ref>Java</invoker-ref>
       
        <method>
            <name>*</name>
            <state-bean-ref><name>LearnerData</name></state-bean-ref>
            <parameter><type>*</type></parameter>
        </method>
    </service>

The <state-bean> declaration declares a Bean which is stored in session. 
The <service> exposes all methods in LearnerService to Flash, without 
explicily saying what the argument lists are. In LearnerService, I have 
method defs like this:

    public  static ASObject doStuff(String arg1, Boolean arg2, 
LearnerData learnerData) {
         // doStuff here. Session Bean is learnerData
   }


Inside my service methods, I always check that learnerData is non-null. 
It will be null if the session has expired.

I also syncronize on learnerData, so there is never more than 1 thread 
working on any given learnerData object.

But, generally, I use session objects, without dealing directly with 
HttpSession.

- Todd





-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.