Configuring Remote Object Service At the heart of BlazeDS is a Servlet that intercepts all communication between a Flex client and BlazeDS instance. This Servlet uses artifacts like channels, endpoints and adapters to enable proxy, remoting and messaging services. Channels and endpoints connect Flex client to BlazeDS. Endpoints reside at the BlazeDS end while the channels are used by Flex clients to connect to these endpoints. Each endpoint defines a type and format for communication. The binding of endpoints to their implementation classes is done in the services-config.xml file. In BlazeDS, the services-config file is logically split into four configuration files, of which first is services-config and rest are namely:
Now to add the remoting services for the Java object, we provide its destination definition in remoting-config.xml file. From Flex Navigator, go to WebContent > WEB-INF > Flex and open the remoting-config.xml file in editor and add the destination definition as shown below before the closing of services tab:
com.pcq.demo.PcqDemo session
Now open the services-config.xml file in editor to change the channel-definition endpoints for Tomcat port, host and context. In the channel-definition description the endpoint would be defined as follows:
Change every instance of template quotes with the Tomcat server information, i.e. with Tomcat's information as follows in the services-config.xml file:
Invoking Object from Client The Flex client application uses the destination property to specify the destination for the remote Java object. Just above we have defined the destination for the Java class as 'pcqdemo' and we will be providing the same to the Flex client. Open up the PcqDemo.mxml file in editor. The application will have an input box and upon clicking the 'Submit' buton, the content of the box will be sent to Java object (PcqDemo.java) and returned with Hello appended to it. Therefore, the layout will have two textboxes, a 'Submit' button and relevant labels. These components can be added to application using the Components panel in the Design view. While in the source, add the following script and remote object definition to pass the information to BlazeDS on server side.
import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.events.ItemClickEvent;
private function btnClick():void { var name:String = txtIn.text; javaObject.addHello(name); } private function resultHandler(event:ResultEvent):void { txtOut.text += event.result ; } private function faultHandler(event:FaultEvent):void { txtOut.text += "FaultEvent : " + event.fault + "\n"; } ]]> destination="pcqdemo" result="resultHandler(event);" fault="faultHandler(event);"/>
To execute the application right-click on PcqDemo.html and select 'Run As' option. This will trigger open the application in a browser window.
Running the App Once the project is cleaned and built, you will notice that in the bin-debug node of the project, the compiled .swf and HTML files have been autogenerated. In our case, PcqDemo.swf and PcqDe mo.html have ben created. Right-click on PcqDemo.html and select Run as > Run on Server option to run the application in the browser. This way, you can integrate Flex to server side Java and hence provide real-time remote object or messaging to the Flex applications.
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.