2. EJB 3 Sample Project Installation
What It Does
The EJB 3 sample application shows a basic address book with a list of persons in the left panel and, for each selected person, a list of contacts in the right panel. You may search existing persons by first or last name, and create, edit, and delete persons or contacts based on the login you choose. Note that admins have the right to make modifications, users have not.
The two panels are packed in HDividedBox container and the current position of this divider is saved in an EJB 3 stateful bean. This position will be restored if you reload the application via the Reload button of your browser.
More specifically, this sample illustrates:
- EJB 3 entity beans externalization, via the HibernateExternalizer class, with Gas3 generated ActionScript3 classes.
- EJB 3 stateless session beans. The PersonServiceBean class uses an EntityManager for persistence operations.
- EJB 3 stateful session beans. The PositionServiceBean stores the current divider position and, even if you reload the Flex application, this position is restored from this stateful context. However, if you click the "][" button at the top right corner of the Flex application, the remove() method is called on the EJB and the initial value is restored. This appends because the previous stateful bean instance is destroyed and the new one returns a default initial value of 300.
- Automatic configuration. Entity bean externalization and remote destinations are automatically configured. See the scan="true" attribute in ear/addressbook.war/WEB-INF/granite/granite-config.xml, the ejb3/META-INF/services-config.properties file and the @RemoteDestination annotation in session bean classes.
- Security settings, via the TomcatSecurityService class (see granite-config.xml), at two levels; a web-tier security that forbids unauthenticated accesses (@RemoteDestination annotation in PersonServiceBean), and a EJB-tier security that forbids modification method calls for a simple user (@SecurityDomain and @RolesAllowed annotations in PersonServiceBean).
Requirements
Follow general requirements here, then:
- Download JBoss 4.2+.
- Download graniteds-ejb3-1.2.0.zip.
- Download org.granite.gas3_1.2.0.zip.
Installation & Deployment
Follow these steps:
- Unzip the JBoss binary distribution somewhere on your computer; for example /jboss-4.2.2.GA.
- Unzip the org.granite.gas3_1.2.0.zip archive in your Eclipse plugin directory.
- (Re)start Eclipse, right-click in the Package Explorer view, choose Import, then General / Existing Projects into Workspace, choose Select Archive File, browse to graniteds-ejb3-1.2.0.zip, and click on Finish.
- Edit the env.properties file in the root directory of the graniteds_ejb3 project, and adjust the following variables:
# Set 'FLEX_HOME' property to your flex2 sdk installation directory and # 'FLEX_TASKS_JAR' to your flexTasks.jar location. # WARNING: This property must have this exact name ('FLEX_HOME'). FLEX_HOME=/flex_sdk_2 FLEX_TASKS_JAR=${FLEX_HOME}/lib/flexTasks.jar # Set 'JBOSS_HOME' property to your JBoss installation directory and # 'JBOSS_HOME_DEPLOY' to your deploy directory. JBOSS_HOME=/jboss-4.2.2.GA JBOSS_HOME_DEPLOY=${JBOSS_HOME}/server/default/deployThe JBOSS_HOME_DEPLOY variable should be ok without modification.
- Copy users.properties and roles.properties found in the root directory of the graniteds_ejb3 project into the /jboss-4.2.2.GA/server/default/conf/props directory. Make sure to backup existing files first.
- Edit the /jboss-4.2.2.GA/server/default/conf/login-config.xml and replace at the end of the file:
<application-policy name="other"> <authentication> <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required" /> </authentication> </application-policy>
by:
<application-policy name="other"> <authentication> <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required"> <module-option name="usersProperties">props/users.properties</module-option> <module-option name="rolesProperties">props/roles.properties</module-option> </login-module> </authentication> </application-policy>
- Open an Eclipse Ant view (Window / Show View / Ant), drag and drop the build.xml file, found in the root directory of the graniteds_ejb3 project, on it, and double-click the Deploy target. This should compile, package, and deploy the EJB 3 sample application in JBoss.
- Start JBoss (run.bat or run.sh in /jboss-4.2.2.GA/bin).
- Point your browser to http://localhost:8080/graniteds-ejb3/.
You should now see the EJB 3 sample application running.
Comments ( Hide )
Anonymous says:Oct 30, 2008 18:11 ( Permalink ) |
|
|
Franck Wolff says:As far as I know, amf-serializer-1.5.0.jar is part of the Flamingo project (that includes the GDS AMF serialization stack) and is not required for this sample to work. You may have another configuration problem but certainly not this one. |
Anonymous says:OK. I was getting: This goes away when I add the amf.jar to the server's lib dir. Any ideas why? |
Anonymous says:This is JUST GREAT!!! Everything works perfect. It took me 7 minutes to get the sample app up and running. I needed some simple to use Data Services implementation for my Java project. Tried BlazeDS, but Granite is simpler to understand and easy to use! DON'T STOP THIS PROJECT, IT'S THE BEST! |
Anonymous says:Hi, For me it didn't work straight away, I had this error when loading the flex page: It came from a conflict of flex versions. So I recompiled graniteDS (download the source package and run the build after modifying the properties file (see README), no problem, great job guys) and replaced graniteds_ejb3/lib/granite.swc and granite-hibernate.swc with the newly compiled ones (from graniteds/build). Great job guys, graniteds rocks! Morgan |
Anonymous says:On opening of the flash file, within ff3/ie7/standalone I get this error: VerifyError: Error #1053: Illegal override of FocusManager in mx.managers.FocusManager. at global$init() How would one fix this. I attempted the recompile of graniteDS as suggested by Morgan. Any idea's as to what is wrong? Andrew |
Anonymous says:Hi Andrew, I had the same error and solved the problem by looking at granite.swc to get the flex SDK version: granite.swc So after compiling this sample with this Flex SDK version, it worked! Keep up the good work guys! Laurent JOLY |
Anonymous says:I get a 404 error when I browser the site http://localhost:8080/graniteds-ejb3/. but I check c:\jboss-500GA\server\default\deploy. all deployed files are there. any idea why this happens. Thanks mike |

In order for the ejb3 example to work, you must also add amf-serializer-1.5.0.jar to your jboss /server/default/lib directory