![]() | Resin Documentationapp server |
hessian actionscript implementation for adobe flash
This document describes the ActionScript implementation of Hessian. Usage instructions, technical reference, and MXML instructions are given. Caucho Technology has released this Hessian implementation under an open source license (the Apache license). Anyone may freely download, use, and redistribute the Hessian implementation.
We will look at two versions of a Hessian Hello World program, one written in MXML and one with more programmatic elements in ActionScript. (These examples can be compiled by adding the above Hessian SWC files to your library path.) The Hessian service itself will be described at the end of this document for reference. First we will look at the MXML version of the client application. This application has a text input and a label for the result received from the server. The text from the input is sent to the server, which simply echos it back with a "Hello" greeting. The source for the application is below. MXML Hello World source <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:word="*"> <hessian:HessianService xmlns:hessian="hessian.mxml.*" id="service" destination="hello"/> <mx:Panel title="Caucho Hessian Hello World" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"> <mx:HBox> <mx:Label text='Whom do you want to say "Hello" to?'/> <mx:TextInput id="who" maxChars="20" enter="service.hello.send(who.text)"/> <mx:Button label="Say Hello" click="service.hello.send(who.text)"/> </mx:HBox> <mx:Label text='The server said: "{service.hello.lastResult}"'/> </mx:Panel> </mx:Application>
Most of the above code is standard MXML formatting code. The
important parts to note are the
The actions on the TextInput and Button are the same: they invoke
the
Finally, the text attribute of the final Label uses the value
Next we will look at a more programmatic way to interact with Hessian services from ActionScript. We retain the same MXML layout, but now we perform all of the communication with embedded ActionScript code. ActionScript Hello World source <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:word="*" implements="mx.rpc.IResponder"> <mx:Script> <![CDATA[ import hessian.client.HessianService; import mx.rpc.AsyncToken; import mx.rpc.events.ResultEvent; private var service:HessianService = new HessianService("hello"); private function sendText():void { var token:AsyncToken = service.hello.send(who.text); token.addResponder(this); } public function result(data:Object):void { var event:ResultEvent = ResultEvent(data); resultLabel.text = "The server said: \"" + event.result + "\""; } public function fault(info:Object):void { } ]]> </mx:Script> <mx:Panel title="Caucho Hessian Hello World" paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"> <mx:HBox> <mx:Label text='Whom do you want to say "Hello" to?'/> <mx:TextInput id="who" maxChars="20" enter="sendText()"/> <mx:Button label="Say Hello" click="sendText()"/> </mx:HBox> <mx:Label id="resultLabel" text='The server said: "null"'/> </mx:Panel> </mx:Application> As in the previous example, we have a local HessianService instance, but now we declare it in ActionScript code. The destination is now the specified in the first argument of the constructor.
The actions of the TextInput and button now call a method
The Java server for the Hello World example performs a simple
task: prefixing the given text with a greeting and returning it.
There are two files involved, an interface which describes the
service called HelloWorld interface package com.caucho.helloworld; public interface HelloWorld { public String hello(String who); } HelloWorldImpl class package com.caucho.helloworld; import com.caucho.hessian.server.HessianServlet; public class HelloWorldImpl extends HessianServlet implements HelloWorld { public String hello(String who) { return "Hello, " + who + "!"; } }
The
The To deploy this service we use a standard web.xml file: HelloWorld web.xml <web-app id=""> <!-- Configure the HelloWorld implementation --> <servlet servlet-name="hello" servlet-class="com.caucho.helloworld.HelloWorldImpl"/> <servlet-mapping url-pattern="/hello/*" servlet-name="hello"/> </web-app>
|