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 开发者_Go百科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?
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);
}
精彩评论