Flex Remote Object Service With Java
Flex Remote Object Service With Java
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,
• Place compiled class files under WEB-INF/classes. Be sure to preserve the folder
structure if you are using Java packaging.
• It’s recommended to compile your classes into a jar. In that case, place the jar under
WEB-INF/lib.
• The destination id attribute is referenced when you invoke the class from Flex.
• The <source> node points to the fully qualified name of the Java class. i.e.
packageName.className
• The <scope> node determines when the Java class will be instantiated,
o Application means the class will be instantiated once during servlet initialization
o Session means the class is instantiated for each user session.
o Request resets the class for each invokation
To invoke a method in the class, simply call the method name after the RemoteObject id,
<mx:Button click=“myService.sayHello()” />
You could add a result event handler to the RemoteObject to catch return messages, but a even
quicker method is to bind to the lastResult,
For scenarios where you have to pass multiple pieces of data back and forth, you need to
explicitly declare a custom data type. Here is a simple example that uses a custom Java class to
hold user registration info,
package sample;
For the RemoteObject to correctly parse the custom data type, you need to create a similar class
in ActionScript,
[Bindable]
[RemoteClass(alias="sample.UserInfo")]
public class UserInfo
{
public var userName:String=”";
}
Need to bring your Flex project up to speed? Zee Yang is a freelance Flex developer with deep
understanding of architecture and user experience. You can reach him at [email protected].
Comments (26)
[...] BlazeDS Remote Object Service – This is the bread n’ butter of BlazeDS. It enables
you to make RPC calls to your custom Java objects. It’s also a necessity if your
application is heavy on data [...]
I’m new to Java and noticed that an error was occurring when trying to access the class
via a remoteObject in flex 3.
After much experimentation, I noticed that once the destination set within the java class
path, (within the remote-config.xml) was set correctly, then the remote object connection
was established.. lol the obvious.
However (and this may help some people). When the path is changed the Java server
must be restarted. Even if the path is re entered correctly again. So in other words
myClass = after running in flex, the path is now bust, 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. However seems to be the case using tomcat on my
development machine. And was also the one thing that took the longest to get my head
around.
JC
This is cool, 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?
Jonas
sample custom java class is ok, but when i have a List property in the custom java class,
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; , it can’t
get the value from java end-back. and now org.userVO.length = 0.
Hello,
Thanks for the post, this is literally the only one on the net that seems to contain complete
code.
Unfortunately, this is still incomplete. The first part (client side) is missing the rest of the
code needed to run ….
Then you totally switch gears on the bottom half as a whole new sample with missing
code as well ..
Is there any chance you could provide a complete and working sample?
Thanks for the tutorial. I have gone through this several times but am still getting an
error. I am running this on Tomcat 6.0.16 with the latest BlazeDS jars (3.2.0.3978). Has
anyone seen this. I have seen others post a similar problem, but mine doesn’t have an
HTTP code.
Nevermind, I got it. I didn’t set my context in the Flex project properties -> Server
Properties
i have followed all the steps mentioned inthe above tutorial but i am getting the error
when I clicked the button. Here i am posting the error please see this and solve me .
Please help
9. on 03 Feb 2009 at 1:15 am 9.raj said …
hello,
i find this tutorial very good for me as beginners…. this really help me to do my 1st flex
java integration… i really appriciate that…. but m thinking how can i send my
parameters to java …if anyone knows then it will be highly appriciated..
thanks in advance
I have read the tutorial, its very nice thanks a lot.But I m getting this error Parse error at
”.can you please help me?
Zee, I’ve read a number of your articles now and they are excellent. I have a feeling I will
be coming back regularly as I use more and more complex AMF projects.
Your bare bones article was excellent and prompted me write my own specific one for a
tomcat turnkey solution. If you’re interested, you can read it at
http://flexbandit.com/archives/55
I have a Prob. i need to invoke a method in a class which is extends a base class… when i
give the source as extended class., blaze is not able recog this class!! Cant we use a
extended class as source in remote-config.xml??!!
I’m getting a parse error like raj on the RemoteObject tag. 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.adobe.com/jira/browse/SDK-16099
I everybody,
This is cool, 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
I’m not sure AMF is that much better than SOAP. You cited performance, and that
certainly is true. However, when you’re developing in FlexBuilder the only way to
validate that you’re calling the appropriate method is to verify at “runtime”.
FlexBuilder does no introspection for “type aheads” on the target Java destination
objects. You get that with with WSDLs. You get this with EJB interfaces. You get this
with CORBA IDLs.
From a coder perspective RemoteObject is a “code and pray” approach. If your builds
take a long time then finding typos, etc, can be all the more frustrating. You have no
guarantees that your “sayHello()” method exists in the remote object.
I was wondering guys, i have a flex client setup to get data through a webservice. I want
to modify my client to use the remoteobject so that i can move data through the AMF
protocol. My BlazeDS is deployed in the same oc4j server as my webservice. Webservice
is basically an archive(web archive, but still an archive) behind the scenes. Once
deployed, the class file should be accessible via classloader of the application server’s
java instance. Can i just create a destination in ‘remoting-config’ for my webservice’s
class file. In this way, 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.
For the entry #8 where Ramesh reported the problems where his destinations were not
recognized. You might want to check the setup of your Flex project. You have to be
careful when you select and set the root context. If you fail then you hit Ramesh’s
problem.
http://www.otembo.de/blog/blog3.php/development/
thx
Thanks for the tutotorial, but I’m having this error, any advice?
kjv007… Your problem can be solved by compiling the flex code with -services compiler
option
But things work fine for primitive like String. I have created a corresponding Action
Script class at client. Any idea how this could be resolved?