Groups | Blog | Home
all groups > macromedia flash flash remoting > april 2004 >

macromedia flash flash remoting : Are you sure FlashRemoting w/FlashMX2004 and EJB


KarstenTS
4/19/2004 11:48:46 AM
I do have serious problems...
For quite a long time I am trying to connect some Enterprise JavaBeans to a
FlashMovie. The idea was to combine a great FrontEnd and a great BackEnd.
The problem is, I can't get it work.

I bought a copy of FlashMX2004 and installed the RemotingComponents (from
http://www.macromedia.com/software/flashremoting/downloads/components ).
I wrote Enterprise JavaBeans that work well, they are deployed on a JBoss
Server and a TestServlet shows me, that everything is okay and acts (answers)
like it should.
I searched the web and got quite litte information (EJB seems to be not too
popular with FlashRemoting) and about none concerning FlashMX2004.
I deployed the Gateway and can connect to it.

In a looong list of errors I fought my way through the very little delved and
barely penetrable jungle to what I call my final frontier.
When I run my move, I get connected to my EJB (Home Interface with
getService(myJNDI)) and even get an object when calling myEJB.create(). But
when I try doing anything with that, Flash does nothing. No request, no answer,
the NetConnection Debugger shows neither call nor answer.
I try to call the makeSomeNoise() Method which should give a simple String
back.

Sorry for telling my whole story, but I'm quite frustrated by now.

Any suggestion for emprovement strongly appreciated!
However, here is my code...

FRAME1:[Q]#include "NetServices.as"
#include "NetDebug.as"

var myURL:String = "http://localhost:8080/flashgateway/gateway";
var myEJB:String = "ejb/foo/facade/Entry";

var textCon:String = new String();
var createRes:Object = new Object();

_global.System.onStatus = createRes.onStatus;

EJBtext.text = "soon...";

// connection stuff
function init() {
   // Gateway
NetServices.setDefaultGatewayUrl(myURL);
var myGateway:Object = NetServices.createGatewayConnection();
// BeanInstance
EntryBean = myGateway.getService(myEJB);
if (EntryBean != null) {
textCon = "Connection Established\nEntryBean:" + EntryBean;
EntryBean.create(createRes);
} else {
EJBtext.text = "Cannot connect to server.";
}
}

createRes.onResult = function (resData:Object):Void {
EntryEJB = resData;
EJBtext.text = textCon + "\n\nGot Bean Instance.\nEntryEJB: " + EntryEJB;
}
createRes.onStatus = function (resData:Object):Void {
EJBtext.text = textCon + "\ncreate() - STATUS: \n" + resData.description;
}

init();
stop();[/Q]



FRAME2:[Q]var noiseRes:Object = new Object();
_global.System.onStatus = noiseRes.onStatus;

// Resulthandler
noiseRes.onResult = function (resData:Object):Void {
EJBtext.text = "makeSomeNoise() works!\n" + resData;
}
noiseRes.onStatus = function (resData:Object):Void {
EJBtext.text = "makeSomeNoise() sucks.\n" + resData.description;
}

EntryEJB.makeSomeNoise(noiseRes);

stop();[/Q][num]s[/num][bullet]sd[/bullet][bullet]d[/bullet]
silkpuppet
4/19/2004 10:32:27 PM
I would suggest using a business delegate class on the server to handle
interaction with the EJB layer.

The business delegate would be a standard java class that implements
java.io.Serializable. The method signatures would mirror the business method
signatures on the EJB layer. All the business delegate does is take requests
from the client and forward them to the EJB layer. It would be responsible for
finding and creating EJB's, then calling the business methods. Additionally, it
would handle EJB-specific Exceptions and hand them back to the Flash client in
a more usable form.

I tried using EJB directly from Flash and had the same problems as you. I
think that you can get it to work, but I opted for the Business Delegate design
pattern instead because I think it's more maintainable and easier to use.
Handling the myriad of possible EJB exceptions on the Flash client would be
difficult.

Do a google search on 'Business Delegate Design Pattern' for more info.

Also, [L=this
article]http://www.onjava.com/pub/a/onjava/2003/02/26/flash_remoting.html?page=2
[/L] may be helpful to you.

Hope that helps.

~j
KarstenTS
4/20/2004 8:41:47 AM
That would be one way, but that's already the 2. Session Facade I have. One more would be a little too much I think.
AddThis Social Bookmark Button