-1

I want to be able to reuse my existing controller logic regardless of whether a request has been sent from a Flex client (using BlazeDS + Spring at the backend), or as a simple HTTP POST/GET request. For simple cases, things work OK, however, there are some occasions when I need to access some session attributes. At first, I almost exclusively used the FlexContext class, but then I realized that when one sends an HTTP request, then the Flex Context is obviously undefined.

My question is, what is the best approach to abstract the session extraction logic,regardless of the type of the request. In other words, I would make a class called SessionManager, which has a method getSession. This class will make a check whether there is a Flex context, if there is, it will return the session of that context. If not, it will simply return the current HTTP session (which I assume is the same as the Flex client session, but I was not sure)

Any comments?

xantrus
  • 1,975
  • 1
  • 22
  • 44
  • By session attributes, I mean some data that I store in the session, and I only need to access on the server side - in order to make some checks when necessary. As for the rate, I would really like to keep it up, but for that to happen I need to get some decent answers, you know – xantrus Jun 06 '11 at 13:24
  • 3
    IF you have "Better" answers to your previous questions than the ones provided on this site; you should answer them yourself and them mark them as 'answered'. That said, I don't think you answered my question. "Session Attributes means data stored in the session." Are you talking about a server-session? Or a client side variable? – JeffryHouser Jun 06 '11 at 13:50

1 Answers1

2

Not sure if I understand your question right. Are you trying to read from the FlexSession when a flex client accesses the server and from the HttpSession in case of a non-flex client? If so, maybe you can try something like this ... I don't have a setup currently to test this so sorry if it doesn't work or if this isn't what you are asking about.

String attributeValue = null;
FlexSession fSession = FlexContext.getFlexSession();
if ( fSession != null ) 
{
     attributeValue = (String)fSession.getAttribute(attributeKey);
}
else // No flex session
{
    HttpSession hSession = request.getSession(); 
      // Where request is the HttpServletRequest
    attributeValue = (String)hSession.getAttribute(attributeKey);
}
Sai
  • 3,819
  • 1
  • 25
  • 28