My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
EJBAdapter  
An adapter to allow invocation of EJB methods via remote object
Phase-Deploy, Phase-Design, Phase-Implementation, Featured
Updated Feb 4, 2010 by ivanlat...@gmail.com

Introduction

This adapted is designed to work with EJB Session Facade pattern and allows you to call Session Facade Bean from your Flex application. Additionally it can pass user credentials and session ID to Session Facade Bean, so user can be authenticated and session state can be maintained.

Limitations

EJB Adapter is using JNDI lookup to obtain a bean at a runtime. It mean that your Session Facade Bean must have a remote (or local) interface(s) that can be looked up in JNDI registry.

Configuration

We assume that readers are familiar with basic BlazeDS configuration, and we will not cover this topic here.

Configuration of EJBAdapter is very similar to a standard BlazeDS Java adapter.

Following is a simplest BlazeDS configuration that allows you to call a method on SignupSessionEJB bean.

First we must define an adapter in remoting-config.xml:

...
<adapters>
  <adapter-definition id="ejb-object" class="flex.messaging.services.remoting.adapters.EJBAdapter" default="true"/>
</adapters>

Now we will add a destination, pointed to our SignupSessionEJB. Again in remoting-config.xml:

<!-- SignupDestination --> 
<destination id="signup">
  <properties>          
    <ejb-name>SignupSessionEJB/localHome</ejb-name>    
  </properties>
  <adapter ref="ejb-object"/>
</destination>

And that's it, you just have configured BlazeDS server to use EJBAdapter. Don't forget to add a flexserverlib library to your BlazeDS server.

Now you can call a method from SignupSessionEJB right from your Flex application. Somewhere in main.mxml:

<mx:RemoteObject id="signupRO" 
  endpoint="http://localhost:8080" 
  destination="signup"
  showBusyCursor="true">   
  <mx:method name="sigup" result="resultHandler(event)" fault="faultHandler(event)"/>
</mx:RemoteObject>

Advanced features

EJBAdapter can append request headers map to a method call. You can tell adapter to do so by specifying an additional property <inject-headers>true</inject-headers>.

Than destination configuration will look like:

<!-- SignupDestination --> 
<destination id="signup">
  <properties>          
    <ejb-name>SignupSessionEJB/localHome</ejb-name>    
    <inject-headers>true</inject-headers>
  </properties>
  <adapter ref="ejb-object"/>
</destination>

For each method call for this destination adapter will append a Map as a last parameter to a method call. So you have to change your method signature, and add a Map paameter, for example, you had a method:

MyProfile getProfile(Long id) throws RemoteException;

After adding a map as a last parameter method signature will look like:

MyProfile getProfile(Long id, Map headers) throws RemoteException;

Note:

Flex code will not change. Your RemoteObject and method call stays as is.

For example in your main.mxml method call will be:

signup.getProfile(1);

If you have any questions or suggestion, please post them on the user group Users Group

Contributed By Ivan Latysh


Sign in to add a comment
Powered by Google Project Hosting