Power of BlazeDS
Recently, I found out that Adobe has released BlazeDS (subset of LiveCycleDS) that has 4 main advantages:
- AS3 to Java object communication (no XML passes back and forth is needed!)
- Boost up performance b/c AMF is a binary protocol
- Built-in proxy support that gets around the cross domain security issue from Flex in ease.
- Allow push messaging
I have followed the guideline and set it up. Now my Flex application can call my Java object method without passing xml back and forth. It is awesome! During the setup process, you may experience your flex cannot find the destination set up in the server.
The error “[MessagingError message=’Destination ‘SomeBean’ either does not exist or the destination has no channels defined (and the application does not define any default channels.)’]”.
The trick here is to add a services argument to the mxmlc call, something of the form below should do the trick!
-services “[local path to your java project]/WEB-INF/flex/services-config.xml”
Now you may start enjoying how AS3 talks to your Java Object. However, if we bypass the Servlet layer in the code, how can we carry session across remote method calls? Great that I have found out how to handle it via this article. In short, you can access Session from your Java object via:
FlexContext.getFlexSession()
Here is the quote I got from the BlazeDS developer guide.
The FlexContext class is useful for getting access to the session and the HTTP pieces of the session, such as the HTTP servlet request and response. This lets you access HTTP data when you use a Flex application in the context of a larger web application where other classes, such as JSPs or Struts actions, might have stored information.
The FlexSession class provides access to an ID and also provides setAttribute and getAttribute functionality. This is useful for storing data on the server that doesn’t have to go back to the client. However, FlexSession is not cluster-aware; if a client connects to a different server in the cluster, the client receives a new FlexSession. Nothing stored in the FlexSession attributes is persisted for clustering purposes. The FlexSessionListener class is useful for monitoring who is connected. You add a listener by using the static method to track new connections being made. You receive a reference to the session that was added. Each session can then report when it is destroyed to those same listeners. You use this for monitoring connections that close, and also to clean up resources.
When I looked into the source of FlexContext, I noticed that it leverages ThreadLocal to store context info like request, response and session.
private static ThreadLocal sessions = new ThreadLocal();
/**
* The FlexSession for the current request. Available for users.
*/
public static FlexSession getFlexSession()
{
return (FlexSession)sessions.get();
}
Reference
Below are some of the useful references I have read so far:






































(4.75 out of 5)
1 Comment Received
Pingback & Trackback
Sorry the comment area are closed for non registered users