Remote Object Service, one of the keys services in LiveCycle DS and BlazeDS, enables Flex applications make remote

procedure calls to the Java server via the AMF3 protocol. AMF3 is architected similar to SOAP, but magnitudes faster because it’s a pure binary protocol. If your Flex application loads large amounts of data, and speed/bandwidth is a priority, you should consider leveraging the Remote Object Service. The conceptual diagram below demonstrates the architecture of a Flex app coupled with the remoting service,

Server Side Coding and Configuration
With the Remote Object Service, Flex applications could invoke methods from Java classes hosted on the server.There are a few rules you have to follow when creating a remote object class in Java,
• • • • •

The Java class must be public Only public methods are visible to the Flex client Method names should not begin with an underscore character Certain method names are reserved and should not be used, such as addHeader(), addProperty(), valueOf(), etc. Refer to the manual for the complete list Enterprise Java Beans (JNDI hosted classes) are not supported

Here is an example of a simple Java class,

} public int add(int a. It’s recommended to compile your classes into a jar. o Application means the class will be instantiated once during servlet initialization o Session means the class is instantiated for each user session. In that case. Finally.e. i.xml. Be sure to preserve the folder structure if you are using Java packaging. • • Place compiled class files under WEB-INF/classes. packageName. simply call the method name after the RemoteObject id. <destination id=“myJavaClass” > <properties> <source>MyRPC</source> <scope>application</scope> </properties> </destination> • • • The destination id attribute is referenced when you invoke the class from Flex.public class MyRPC { public String sayHello() { return “Hello from Remot Object!”. place the jar under WEB-INF/lib. The <source> node points to the fully qualified name of the Java class. <mx:RemoteObject id=“myService” destination=“myJavaClass”> To invoke a method in the class. } } To host the classes in Remote Object Service. you must add the class destination in WEB-INF/flex/remoting-config.className The <scope> node determines when the Java class will be instantiated. int b) { return a+b. . instantiate a RemoteObject class and set the destination attribute to match the destination id in the remoting-config file. o Request resets the class for each invokation Client Side Coding In the Flex client code.

for example.lastResult}” /> Data Exchange between Flex and Java Flex RemoteObject implicitly maps strongly typed objects between ActionScript and Java. is mapped to a Date object is Java automatically. you need to explicitly declare a custom data type.<mx:Button click=“myService. but a even quicker method is to bind to the lastResult. public class UserInfo { private String userName. } public void setUserName(String value) { userName = value. you need to create a similar class in ActionScript. Here is a simple example that uses a custom Java class to hold user registration info. } } For the RemoteObject to correctly parse the custom data type.UserInfo")] public class UserInfo { public var userName:String=”". package sample. [Bindable] [RemoteClass(alias="sample.sayHello. <mx:Label text=“{myService.sayHello()” /> You could add a result event handler to the RemoteObject to catch return messages. • Bindable attribute is necessary for binding the class property values . public String getUserName() { return userName. For scenarios where you have to pass multiple pieces of data back and forth. } Notice the two attributes attached to the ActionScript class. A Date object in Flex.

It enables you to make RPC calls to your custom Java objects.net » BlazeDS Tutorials said … [..xml) was set correctly. And was also the one thing that took the longest to get my head around.. then the remote object connection was established.com. is there a way to specify the remote connection as a http service to enable a swf on a different server to make a remote call? ..] BlazeDS Remote Object Service – This is the bread n’ butter of BlazeDS.. lol the obvious.FlexLive.yang@gmail.• RemoteClass attribute points to the corresponding Java class Click here for the sample code Need to bring your Flex project up to speed? Zee Yang is a freelance Flex developer with deep understanding of architecture and user experience. on 18 Jul 2008 at 1:30 am 3. It’s also a necessity if your application is heavy on data [. So in other words myPackage. hurray! myClass = after running in flex.jonas said … This is cool. You can reach him at zee. must restart tomcat server Try to fix path by entering myPackage.myClass = still bust must still restart server Now I’m not 100% sure about this. on 20 May 2008 at 5:49 am 1. I noticed that once the destination set within the java class path. (within the remote-config. However seems to be the case using tomcat on my development machine. However (and this may help some people). After much experimentation. Even if the path is re entered correctly again. the path is now bust. When the path is changed the Java server must be restarted.John said … I’m new to Java and noticed that an error was occurring when trying to access the class via a remoteObject in flex 3. on 04 Jul 2008 at 7:42 am 2.myClass = works. JC 3.] 2. Comments (26) 26 Responses to “BlazeDS Tutorial – Remote Object Service” 1..

0.2.david said … sample custom java class is ok. RPC Fault faultString=”Send failed” faultCode=”Client.0\frameworks\projects\rpc\src\mx\rpc\Responder.16 with the latest BlazeDS jars (3.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet.messaging::ChannelSet/faultPendingSends() [C:\autobuild\3. but mine doesn’t have an HTTP code.as:53] at mx.rpc::AbstractInvoker/http://www. but when i have a List property in the custom java class. on 12 Dec 2008 at 6:08 pm 5.Jonas 4.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest. Then you totally switch gears on the bottom half as a whole new sample with missing code as well .as:975] at flash.messaging::ChannelSet/channelFaultHandler() [C:\autobuild\3.adobe. call the RemoteObject will get error: TypeError: Error #1009: can not visit referenced property or method by null object… if i initialize the List property like this: public var userVO: Array = new Array.Zanpher said … Hello. Thanks for the post.2. on 19 Jan 2009 at 11:21 pm 6.as:220] at mx.as:103] at mx. and now org.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.rpc::Responder/fault() [C:\autobuild\3.MessageSend” faultDetail=”Channel.rpc::AsyncRequest/fault() [C:\autobuild\3.Call. Is there any chance you could provide a complete and working sample? 6.length = 0. . this is literally the only one on the net that seems to contain complete code.Error.2.Adam said … Thanks for the tutorial.2.0\frameworks\projects\rpc\src\mx\messaging\ChannelSet. I have gone through this several times but am still getting an error. Has anyone seen this.userVO.com/2006/flex/mx/internal::faultHandler() [C:\autobuild\3.as:1482] at mx.2.2.Connect.Failed: HTTP: Failed: url: ‘http://localhost:8080/WebContent/messagebroker/amf’”] at mx. The first part (client side) is missing the rest of the code needed to run …. 5. it can’t get the value from java end-back.events::EventDispatcher/dispatchEventFunction() .0.3978). I have seen others post a similar problem. I am running this on Tomcat 6. Unfortunately. on 03 Dec 2008 at 2:52 am 4.Failed error NetConnection.. this is still incomplete.

as:263] at mx.2.Adam said … Nevermind.2.at flash.as:997] at mx.adobe.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker. on 29 Jan 2009 at 8:21 pm 8.Ramesh Kumar B said … i have followed all the steps mentioned inthe above tutorial but i am getting the error when I clicked the button.as:290] at eee/___eee_Button1_click()[C:\Users\ramesh\Documents\Flex Builder 3\Test\src\eee.rpc::AbstractService/http://www.mxml:25] Please help . I didn’t set my context in the Flex project properties -> Server Properties 8.rpc.adobe. I got it.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.rpc.2.2.0\frameworks\projects\rpc\src\mx\rpc\remoting\Operation.adobe.com/2006/actionscript/flash/proxy::callProper ty()[C:\autobuild\3. [RPC Fault faultString="[MessagingError message='Destination 'myJavaClass' either does not exist or the destination has no channels defined (and the application does not define any default channels.0\frameworks\projects\rpc\src\mx\messaging\channels\PollingChannel.com/2006/flex/mx/internal::invoke( ) [C:\autobuild\3.rpc.remoting.com/AS3/2006/builtin::apply() at mx.messaging.com/2006/flex/mx/internal::invoke() [C:\autobuild\3.0\frameworks\projects\rpc\src\mx\rpc\AbstractService.remoting.mxml::Operation/send() [C:\autobuild\3.remoting::Operation/send() [C:\autobuild\3.)']” faultCode=”InvokeFailed” faultDetail=”Couldn’t establish a connection to ‘myJavaClass’”] at mx.0\frameworks\projects\rpc\src\mx\rpc\remoting\mxml\Operation.as :390] 7.as:113] at Function/http://adobe.2. on 20 Jan 2009 at 10:53 am 7. Here i am posting the error please see this and solve me .channels::PollingChannel/connectFailed() [C:\autobuild\3.rpc::AbstractInvoker/http://www.2.channels::AMFChannel/statusHandler() [C:\autobuild\3.mxml::Operation/http://www.com/AS3/2006/builtin::apply() at mx.as:197 ] at mx.2.events::EventDispatcher/dispatchEvent() at mx. as:354] at mx.messaging.2.0\frameworks\projects\rpc\src\mx\messaging\Channel.0\frameworks\projects\rpc\src\mx\rpc\remoting\mxml\Operation.as:170 ] at Function/http://adobe.messaging::Channel/connectFailed() [C:\autobuild\3.

raj said … I have read the tutorial. Your bare bones article was excellent and prompted me write my own specific one for a tomcat turnkey solution.xml??!! 13.But I m getting this error Parse error at ”.Basarat said … Thanks … session helped a lot 14.adobe. I have a same question of Jonas : . this really help me to do my 1st flex java integration… i really appriciate that….com/archives/55 12.Sean said … I’m getting a parse error like raj on the RemoteObject tag.. on 14 Apr 2009 at 6:18 am 15.babass said … I everybody. on 27 Feb 2009 at 9:49 am 10. Is there a workaround or fix for this? I’ve seen that it’s been a bug in the framework reported some time ago: http://bugs. but m thinking how can i send my parameters to java …if anyone knows then it will be highly appriciated. blaze is not able recog this class!! Cant we use a extended class as source in remote-config. i find this tutorial very good for me as beginners….9.donkeybandit said … Zee.can you please help me? 11. i need to invoke a method in a class which is extends a base class… when i give the source as extended class. you can read it at http://flexbandit.. its very nice thanks a lot. on 03 Feb 2009 at 1:15 am 9. on 26 Mar 2009 at 8:15 pm 14. on 15 Mar 2009 at 6:30 am 13. thanks in advance 10. I have a feeling I will be coming back regularly as I use more and more complex AMF projects.com/jira/browse/SDK-16099 15. I’ve read a number of your articles now and they are excellent. If you’re interested. on 04 Mar 2009 at 1:05 am 12.raj said … hello.Pavithra said … I have a Prob. on 01 Mar 2009 at 5:04 pm 11.

My BlazeDS is deployed in the same oc4j server as my webservice. If my question is not clear. You get that with with WSDLs. You have to be .Doug said … I’m not sure AMF is that much better than SOAP. on 17 Sep 2009 at 10:31 am 19. i can use the webservice so that other resources can access the webservice as well as allow my flex client to transfer data through AMF protocol. However. Webservice is basically an archive(web archive. on 07 May 2009 at 1:03 pm 16. You have no guarantees that your “sayHello()” method exists in the remote object.jorge said … thanks a lot for your samples. You get this with CORBA IDLs. i can explain it in detail.Ashwin suresh said … I was wondering guys. Can i just create a destination in ‘remoting-config’ for my webservice’s class file. I want to modify my client to use the remoteobject so that i can move data through the AMF protocol. You might want to check the setup of your Flex project.Jelle said … For the entry #8 where Ramesh reported the problems where his destinations were not recognized. i have a flex client setup to get data through a webservice. You cited performance. the class file should be accessible via classloader of the application server’s java instance. From a coder perspective RemoteObject is a “code and pray” approach. on 11 Sep 2009 at 5:28 pm 18.“jonas said … This is cool. when you’re developing in FlexBuilder the only way to validate that you’re calling the appropriate method is to verify at “runtime”. again more especificationes 20. 19. can be all the more frustrating. If your builds take a long time then finding typos. etc. You get this with EJB interfaces. but still an archive) behind the scenes. 17.Tanzeem Akhtar Bhatti said … Thanks a lot for your sample 18. is there a way to specify the remote connection as a http service to enable a swf on a different server to make a remote call? ” Babass 16. on 04 Sep 2009 at 4:01 am 17. on 25 Sep 2009 at 6:15 am 20. Once deployed. and that certainly is true. FlexBuilder does no introspection for “type aheads” on the target Java destination objects. In this way.

php/development/ 21. on 15 Oct 2009 at 7:54 pm 21.rpc::AbstractService/http://www.rpc.com/2006/flex/mx/internal::invoke( )[E:\dev\3.rpc.as:197] at mx.)']” faultCode=”InvokeFailed” faultDetail=”Couldn’t establish a connection to ‘myJavaClass’”] at mx.remoting.1.com/AS3/2006/builtin::apply() at mx.adobe. any advice? [RPC Fault faultString="[MessagingError message='Destination 'myJavaClass' either does not exist or the destination has no channels defined (and the application does not define any default channels. on 08 Mar 2010 at 5:15 am 23.adobe.com/2006/flex/mx/internal::invoke() [E:\dev\3. on 08 Mar 2010 at 5:17 am 24.1. The path to the services-config.com/AS3/2006/builtin::apply() at mx. on 22 Feb 2010 at 8:35 pm 22.mxml::Operation/send() [E:\dev\3.kjv007 said … Thanks for the tutotorial.de/blog/blog3. but I’m having this error.0\frameworks\projects\rpc\src\mx\rpc\remoting\mxml\Operation.xml file .as:290] at StartHere/handleRemoteObj() [E:\Workspace\ProofOfConceptWS\FSubmetering\flex_src\StartHere.1.adobe.as:113] at Function/http://adobe.1. If you fail then you hit Ramesh’s problem.com/2006/actionscript/flash/proxy::callProper ty()[E:\dev\3.remoting.as:170] at Function/http://adobe.0\frameworks\projects\rpc\src\mx\rpc\AbstractService.0\frameworks\projects\rpc\src\mx\rpc\remoting\mxml\Operation.mxml::Operation/http://www. http://www.remoting::Operation/send() [E:\dev\3.1.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.otembo.careful when you select and set the root context.as:259] at mx.Hidayath said … kjv007 … -services takes an argument..mxml:151] 23.rpc.doez said … thx 22.mxml:127] at StartHere/___StartHere_Button1_click() [E:\Workspace\ProofOfConceptWS\FSubmetering\flex_src\StartHere.rpc::AbstractInvoker/http://www.0\frameworks\projects\rpc\src\mx\rpc\remoting\Operation.Hidayath said … kjv007… Your problem can be solved by compiling the flex code with -services compiler option 24. Please check my image in .

meaning the value is null.25.Praveen said … Thanks a lot for the sample… It is really good. A string value set a server side is not reflected at client. I have created a corresponding Action Script class at client. on 13 Mar 2010 at 10:37 am 25. But things work fine for primitive like String. I have a problem when returning custom object from server. Any idea how this could be resolved? .

Sign up to vote on this title
UsefulNot useful