Home > Documentation > Reference > Samples > Sample applications > DataCDInfo -- A sample about Struts1+EJB+JPA+JTA+Security Annotations |
This article describes how to develop a Struts1 web application for Geronimo. Besides Struts1 technology, you can also find sample code about usages of JPA and Security annotations.
Because of a problem described in GERONIMO-5020, this sample application is not available as a geronimo plugin for the time being.
This article doesn't intend to serve as a tutorial of developing a Struts1 application. For informations about Struts1 development, see Struts1 web site.
This article is organized into the following sections.
Assuming you have accumulated lots of archival data CDs from your computer, each of them includes rich of information you ever collected. The collection of those archived CDs is your valuable knowledge asset, and certainly you want to manage them carefully and orderly for easy references in the future. The DataCDInfo sample application is about to assist you with this task.
With this application, you can register a user, and then login to add records for your archived CDs. You can record detail information that is not suitable to label on CD surface, such as detailed list of data CD content, archived date, and size of the CD.
This application pre-defines some admin roles who will be able to view overall recorded CDs and help retrieve user's forgotten password.
In short words, DataCDInfo is a simple CRUD(Create, Retrieve, Update and Delete) application, which adopts Struts1, JPA, JTA, and security annotation techniques.
DataCDInfo uses the typical Java EE application structure, which includes an EJB module, an Web module and an EAR module.
The EJB module includes the major business logic of an application. It consists of JPA entity beans, a stateless session bean, a stateful session bean and some exception classes.
ejb-jar.mxl
. The configurations in ejb-jar.xml
file will override the ones in code already.ejb-jar.xml
.
META-INF/persistence.xml
as shown below.
If the persistence context requires some non-transactional operations, such as table sequence generation, you have to define a non-jta-data-source
as well. Otherwise, you will encounter an exception like org.apache.openjpa.persistence.RollbackException: The transaction has been rolled back
.
The maven project layout of the EJB module as follows:
All Struts1 objects are in the Web module. A typical Struts1 web application uses a configuration file to initialize its resources. Those resources include ActionForms to collect input from users, ActionMappings to direct input to server-side Actions, and ActionForwards to select output pages.(Quoted from Struts1 documentation).
The DataCDInfo application web module consists of:
org.apache.commons.beanutils.PropertyUtils
method.DataCDInfoResource.properties
and several DataCDInfoResources_LANG.properties
resources
directory, and then run a new build for later deployment.struts-config.xml
and validation.xml
struts-config.xml
file is the main configuration file of a Struts1 application. All mandatory informations of a Struts1 artifact such as ActionForm, Actions, ActionMapping, and Validator, should all be defined in this file.Besides the artifacts of Struts1, there are some other artifacts used for DataCDInfo admin logic operations:
web.xml
as follows:
The maven project layout of the Web module as follows:
The EAR module contains database creation scripts and the application deployment plan. The application deployment plan will override the duplicate configurations defined in the EJB module and Web module.
In the application deployment plan, there are definitions about the web context root and the security realm used to authenticate the admin operations.
The DataCDInfo application uses the default geronimo security realm geronimo-admin
, which is a .properties file-based realm. To enable "superadmin" role used by this application, these .properties files in /var/security
must be modified before starting Geronimo server:
The plain text password will be encrypted when the geronimo server restarts.
Two datasources are defined in the deployment plan. jdbc/DataCDInfoDS
is for JTA scenarioa, and jdbc/NoTxDataCDInfoDS
for non-JTA.
To map the application security roles to Geronimo security roles, the deployment plan must include configurations as below:
Besides the default deployment plan, there is another plan for MySQL database. You can enable the database by using deploy command:
deploy deploy DataCDInfo-JTA-ear-2.2.ear geronimo-application-mysql.xml
You must install proper mysql jdbc driver into Geronimo repository first before deploying the DataCDInfo application with MySQL deployment plan geronimo-application-mysql.xml
.
The maven project layout of the EAR module as follows:
If you just use "admin" role(for example, use "system" account defined in the geronimo-admin realm) to pass the authentication of DataCDInfo Admin resources, you will see an exception like this when trying to view the owner's password.
Bookmark this on Delicious Digg this | Privacy Policy - Copyright © 2003-2011, The Apache Software Foundation, Licensed under ASL 2.0. |