EJB and Flex Integration

I am currently writing a demonstrator application for MAX 2006, where I will be presenting on security. As part of my application I want to show the propagation of the user’s identity from the Web container, in which Flex executes, and the EJB container, where business logic could be executing. Rather than write a remote Java object that acts as a business delegate I have written an EJB factory for Flex that is now available for download on the Flex Exchange. The EJB factory allows Flex to call an EJB directly.

Many enterprise applications encapsulate their business logic in stateless session beans so it is executed in the EJB container. The benefits of such an architecture include pooling of EJBs, declarative transactions, declarative security and improved scalability through transparent clustering. In addition it allows the EJBs to be called from other clients, not just the web.

However, I would always advocate that you encapsulate your business logic in POJOs so it can be executed in any container, for example this flexibility means you can execute your POJOs in your Web container by calling them directly in Flex as remote objects or they can be wrapped in a stateless session beans to permit execution in the EJB container. This sort of approach can aid scalability where it is not always cost effective to invest in a mid-tier in the early stages of an application’s life – with success comes investment.

Download the ZIP from the Flex Exchange and follow the instructions in the README.txt to call EJBs from your Flex applications.

11 Responses to EJB and Flex Integration

  1. Tom Rombaut says:

    Hi Peter,the link you provided brings us to a page with a downloadbutton. Unfortunately, clicking on it leads to a 404 page. Could you please fix it? Thanks in advance!

  2. Andre Koppany says:

    Hi,thanks for this info.I am using Apple WebObjects and would like to exchange objects between Flex Clients and Enterprise Objects.Is there any adaptor available or can you point me to information about writing an adaptor myself.Thanks in advance,André

  3. Christina says:

    Hi Peter,there is a J2EE Web application with n JSp frontend. My work is to change he frontend into flex. I am trying to work with the remoteobject, so i get the Data, that i need from my Java methods into my client. I noticed that the data i want to present in my client flex are written in the session of the J2EE Applikation. How can i get this data? Is there something like a session in flex? Do you think the tool above would help me futher?thanksChristina

  4. greg h says:

    Might you consider updating the format of the home page on your blog to include the actual date on the “MOST RECENT POST” entries?I ask because your home page does not display the date of your “MOST RECENT POST”. Not at the top of the post, nor at the bottom where the timestamp is displayed (time on an unidentified day; now that is a weird convention ;)When selecting “Comments” and going to the page for the individual entry it does display the date … at the top and the bottom.In fact, your blog home page has the same format as all the Adobe consulting bloggers.I find it annoying. If your “MOST RECENT POST” is August 15, there is no harm in displaying the date. On the contrary, displaying the actual date is helpful … and normal.Why have you guys adopted this convention of “MOST RECENT POST” instead of actual date? I have never seen it anywhere else. And obviously if the entry is on the top of the list it is the most recent. Personally, I like seeing actual dates. Even if most recent isn’t today, or yesterday, or last week, etc.

  5. Aubrey says:

    Hi, not sure this is the right place to ask, but I’ve tried the FlexEJBFactory and am running into a problem creating the EJB.Where can I post questions regarding the FlexEJBFactory? Thanks!

  6. radyo says:

    thanks for this info.I am using Apple WebObjects and would like to exchange objects between Flex Clients and Enterprise Objects. Is there any adaptor available or can you point me to information about writing an adaptor myself.Thanks in advance,André

  7. Geert Lorang says:

    If you are having problems (error creating ejb exception) using the EJB Factory with EJB 3.0 specifications: you need to do some code changes;Under com.adobe.ac.ejb.EJBFactory.java change the lookup method so it looks like this:public Object lookup(final FactoryInstance instanceInfo ) {Object ejb=null;final String jndiName = instanceInfo.getSource();try {InitialContext ic = new InitialContext();ejb = ic.lookup(jndiName);} catch(NamingException e) { throw createServiceException(MessageFormat.format(“error creating EJB {0}”, new Object[] { jndiName } ), e );}return ejb;}now compile the package, re-jar it and place it under WEB-INF\lib.i’m quite new to EJB (started from EJB 3 for about 10 weeks now, never learned 1? or 2) but the create method in the current code looks like EJB 2.0 to me? So i’m very sorry if i said any mistakes or whatsover. Hopefully this is any helpful to anyone.This code’fix’ is in any case working for me with ejb 3 & sun’s application server 9.Cheers,Geert

  8. Rokku says:

    Hi!I am creating my project using Flex & EJB. I use EJBFactory or EJB3Factory. I define my configuration in service-config.xml as below:ORWhen I start my JBOSS. I always revieve the message:[[/ejb_fx]] Servlet /ejb_fx threw load() exceptionflex.messaging.config.ConfigurationException: An error occurred trying to construct FlexFactory ‘com.adobe.ac.ejb.EJB3Factory’. The underlying cause is: ‘flex.messaging.MessageException: An unknown exception occurred while creating an instance of type ‘com.adobe.ac.ejb.EJB3Factory’.’.I use JBOSS 4.2 & Flex 2.0, JRE 5Anyone could help me?Thanks in advance.Rokku

  9. Rokku says:

    Hi!I am creating my project using Flex & EJB. I use EJBFactory or EJB3Factory. I define my configuration in service-config.xml as below:ORWhen I start my JBOSS. I always revieve the message:[[/ejb_fx]] Servlet /ejb_fx threw load() exceptionflex.messaging.config.ConfigurationException: An error occurred trying to construct FlexFactory ‘com.adobe.ac.ejb.EJB3Factory’. The underlying cause is: ‘flex.messaging.MessageException: An unknown exception occurred while creating an instance of type ‘com.adobe.ac.ejb.EJB3Factory’.’.I use JBOSS 4.2 & Flex 2.0, JRE 5Anyone could help me?Thanks in advance.Rokku

  10. Bill Shirley says:

    I understand the EJB3 issues, but I’m new and clueless to Flex. How to I tie into it, once the factory is set up?

  11. geetha says:

    I am creating my project using Flex & EJB.so help what are all steps have to follow and where i have to store the files.How to compile?