Posts Tagged ‘Remoting

22
Aug
09

BlazeDs – HelloWorld Example

BlazeDS is a server-based Java remoting technology that allows you to connect to back-end distributed data and push data in real-time to Adobe Flex and Adobe AIR rich Internet applications (RIA).

You can get more information on BlazeDs on the following link “http://livedocs.adobe.com/blazeds/1/blazeds_devguide/”>

Below Are the steps to configure and run a Sample Program Using BlazeDS

Requirement:

Apache-tomcat-6.0.18 (download zip (pgp, md5) )

FlexBuilder

Step1:
Create a folder named BlazeDs in ${Tomcat}/webapps

Step2:
Download the BlazeDS Binaries from the following link
Download the BlazeDS binary distribution and extract it to ${Tomcat}/webapps/BlazeDs

step3:
Create a java Program “HelloWorld.java” in ${tomcat}\webapps\BlazeDs\WEB-INF\classes location

public class HelloWorld

{
public HelloWorld(){}
public String sayHello()
{
return “Hello World. It’s Working”;
}
}
compile and create the class file in the same location

step4:

Add the Following node in ${tomcat}\webapps\BlazeDs\WEB-INF\flex\remoting-config.xml

<service id=”remoting-service”  class=”flex.messaging.services.RemotingService”>
. . .
. . .

<destination id=”HelloWorld”>
<properties>
<source>HelloWorld</source>
</properties>
</destination>

. . .
. . .

</service>

Step5:
Create a new Project(name “BlazeDS”) using Flex Builder.

Copy and Paste the below code in BlazeDs.mxml

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml&#8221; layout=”horizontal” >
<mx:RemoteObject id=”ro” destination=”HelloWorld” result=”resultHandler(event)” fault=”faultHandler(event)”/>
<mx:Panel x=”10″ y=”10″ width=”604″ height=”643″ layout=”absolute” backgroundColor=”#DFE8EC” cornerRadius=”6″ alpha=”1.0″ backgroundAlpha=”0.52″ borderStyle=”inset” fontWeight=”bold” themeColor=”#1611EF” color=”#1B3DE8″>
<mx:TextArea id=”text” text=”initial text” x=”240″ y=”61″ width=”273″ height=”56″/>
<mx:Text x=”62″ y=”10″ text=”Blaze DS Example” width=”431″ height=”28″ fontFamily=”Georgia” fontSize=”15″ alpha=”0.58″ color=”#389AAF” textAlign=”center” fontWeight=”bold” fontStyle=”italic”/>
<mx:Button x=”244″ y=”152″ label=”Click Me” fontStyle=”italic” themeColor=”#0B0BF6″ borderColor=”#291AE6″ click=”ro.sayHello()” />
<mx:Label x=”32″ y=”62″ text=”Data Returned from the server ” width=”189″ color=”#5BA9BA”/>
<mx:Button x=”338″ y=”152″ label=”Reset” fontStyle=”italic” themeColor=”#0B0BF6″ borderColor=”#291AE6″ click=”reset()”  width=”62″/>
</mx:Panel>

<mx:Script>
<![CDATA[

import mx.controls.Alert;

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.utils.ObjectUtil;

import mx.utils.StringUtil;

var str:String

private function resultHandler(event:ResultEvent):void

{

text.text= ObjectUtil.toString(event.result)

}

private function faultHandler(event:FaultEvent):void

{

Alert.show( ObjectUtil.toString(event.fault) );

}

public function reset():void{

text.text="initial text";

}

]]>
</mx:Script>

</mx:Application>

set the Additional compiler arguments for Flex Compiler

-services ${tomcat}\webapps\BlazeDS\WEB-INF\flex\services-config.xml -context-root /BlazeDs

Clean and build the Project again

now copy and paste the generated output files BlazeDS.html , BlazeDS.swf and AC_OETags files to ${tomcat}\webapps\BlazeDS\

Step6:

Stop and Start your tomcat server

Hit The Following URL

http://localhost:8080/BlazeDs/BlazeDS.swf  (or)

http://localhost:8080/BlazeDs/BlazeDS.html

output




Follow

Get every new post delivered to your Inbox.