2010年4月7日水曜日

BlazeDS 入門記(Using the FlexContext class with FlexSession and FlexClient attributes)

BlazeDS architecture / Managing session data / Using the FlexContext class with FlexSession and FlexClient attributes

The flex.messaging.FlexContext class is a utility class that exposes the current execution context on the BlazeDS server. It provides access to FlexSession and FlexClient instances associated with the current message being processed. It also provides global context by accessing MessageBroker, ServletContext, and ServletConfig instances.

FlexContext からは、FlexSession や FlexClient といった BlazeDS 依存の情報から、 ServletContext や ServletConfig など Servlet 系の情報まで。一通り取得することが可能なようですね。

The following example shows a Java class that calls FlexContext.getHttpRequest() to get an HTTPServletRequest object and calls FlexContext.getFlexSession() to get a FlexSession object. Exposing this class as a remote object makes it accessible to a Flex client application. Place the compiled class in the WEB_INF/classes directory or your BlazeDS web application.
package myROPackage;

import flex.messaging.*;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SessionRO {

    public HttpServletRequest request;
    public FlexSession session;

    public SessionRO() {
        request = FlexContext.getHttpRequest();
        session = FlexContext.getFlexSession();
    }
    
    public String getSessionId() throws Exception {
        String s = new String();
        s = (String) session.getId();
        return s;
    }

    public String getHeader(String h) throws Exception {
        String s = new String();
        s = (String) request.getHeader(h);
        return h + "=" + s;
    }
}

上記、HttpServletRequest と FlexSession の利用例。

0 件のコメント:

コメントを投稿