BAM! Flash! (and Hessian)
After a hiatus during a paper/presentation/training season, I’ve finally gone back and cleaned up the Flash/Flex versions of Hessian and BAM. The Hessian side is now updated to be compatible with the latest Hessian 2 changes. As Scott mentioned, the BAM API and protocol has undergone some changes since the last revision, so I’ve rewritten the Flash implementation of that as well. It was a surprisingly large amount of work, but I think everything is now up-to-date as well as a bit more stable.
For those that are interested, here’s a quick hello world with the new BAM API with a Flash client and a Java backend…
The Flash client just sends a basic query. This is a bit long not because of the BAM bits, but just because of the UI stuff. Pay attention to what the HmtpClient is doing…
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
import bam.*;
import bam.hmtp.*;
private const TEST_VALUE:String = "test query value 1234";
private var _client:HmtpClient;
public function onCreationComplete():void
{
_client = new HmtpClient("/hmtp");
_client.connect("foo@localhost", "password",
onLoginResult, onLoginError);
}
public function onLoginResult(jid:String):void
{
jidLabel.text = "jid: " + jid;
}
public function onLoginError(error:ActorErrorMessage):void
{
jidLabel.text = "login error: " + error;
}
public function testQueryGet():void
{
_client.queryGet("basic-test@localhost", TEST_VALUE, onResult, onError);
}
public function onResult(id:Number, to:String, from:String,
value:Object):void
{
if (value == "result[" + TEST_VALUE + "]")
resultLabel.text = "test passed";
else
resultLabel.text = "test failed: received value '" + value + "'";
}
public function onError(id:Number, to:String, from:String,
value:Object, error:ActorErrorMessage):void
{
resultLabel.text = "test failed: received error '" + error + "'";
}
]]>
</mx:Script>
<mx:Panel title="Bam Basic Test">
<mx:VBox>
<mx:Label id="jidLabel" text="logging in..."/>
<mx:Button label="click to send query get" click="testQueryGet()"/>
<mx:Label id="resultLabel"/>
</mx:VBox>
<mx:HRule/>
</mx:Panel>
</mx:Application>
The Java service that receives and processes the query is pretty simple as well:
Finally, to configure the service in a webapp, your resin-web.xml will look like this:
<web-app xmlns="http://caucho.com/ns/resin">
<sec:AdminAuthenticator xmlns:sec="urn:java:com.caucho.security"
password-digest="none">
<user name="foo@localhost" password="password"/>
</sec:AdminAuthenticator>
<bam-service name="basic-test@localhost" class="qa.BasicTestService"/>
<servlet-mapping url-pattern="/hmtp"
servlet-class="com.caucho.remote.HmtpServlet"/>
</web-app>
We specify the password that clients will use, configure the BasicTestService, and deploy the HmtpServlet to handle the protocol requests.
If you’re familiar with the previous BAM incarnation, this shouldn’t look too different, but I’ll also try to get some decent examples up soon for those of you who are new to BAM. I’ll be releasing a snapshot soon with the final release coinciding with Resin 4.0

October 19th, 2009 at 7:51 am
hello
I wonder if I can get some help related to hessian-comet.
I want to test example from http://hessian.caucho.com/comet/#Comet%20Servlet, but I get this error in flex “Could not resolve to a component implementation”. I use external lib (hessian-flex-4.0.0.swc), from http://hessian.caucho.com. Maybe is not the right swc file?
thanks for any ideea
serj
October 19th, 2009 at 10:45 am
serj,
I’m sorry, that example is out of date. We’ve changed our streaming/comet model from that example to use BAM instead. Unfortunately since BAM is also in transition, we don’t have an up-to-date example for that either. We’ll be focusing a lot more on streaming to the browser in the next few months though, during which time, we should also bring all of the flash-related work to a much more stable point.
Thanks for you patience,
Emil
November 13th, 2009 at 6:46 am
Hi,
Is there a Java client for BAM, ideally with an example of how to use it?
thanks
James
November 13th, 2009 at 4:41 pm
Hi James,
BAM is actually primarily Java (in fact the Hessian/Flash client needs updating), but most uses have been internal so far. The API is visible in the com.caucho.bam package of Resin, but at the moment it’s still quite subject to change. I think the plan is to solidify and publicize BAM more in the first half of 2010 to make it a solid way to do bi-directional web work.
Thanks,
Emil