EJBHomeFactory
.
Struts actions use EJBs directly and therefore it is impossible to use
another persistence method without having to rewrite all of the actions.getBean()
function provided by Spring
is now used. The applicationContext.xml
(olstoreweb/WEB-INF/spring/applicationContext.xml) configuration file
specifies the UserHelper
bean. <bean id="itemHelper"
class="org.springframework.ejb.access.LocalStatelessSessionProxyFactoryBean"
lazy-init="true">
<property
name="jndiName">
<value>ejb/ItemHelper</value>
</property>
<property
name="resourceRef">
<value>true</value>
</property>
<property
name="businessInterface">
<value>olstore.session.helper.ItemHelper</value>
</property>
</bean>
This delegates the retrieval of the LocalHome interface for ItemHelper
to Spring and returns an object that implements the business interface
we created for ItemHelper.
To access the EJB in this way
from a struts action all we need to do is to have the actions extend org.springframework.web.struts.ActionSupport
.
We can then simply access the item like this:
ItemHelper itemHelper =
(ItemHelper)getWebApplicationContext().getBean("itemHelper");
OlstoreFacade
interface. The implementation
for this version is olstore.domain.logic.OlstoreImpl.
applicationContext.xml
(olstoreweb/WEB-INF/springmvc/applicationContext.xml) file contains
this configuration to tell Spring which managers to inject into this
particular implementation of OlstoreFacade:
<bean id="olstore" class="olstore.domain.logic.OlstoreImpl">
<property name="itemManager"
ref="itemManager"/>
<property name="orderManager"
ref="orderManager"/>
<property name="userManager"
ref="userManager"/>
<property name="typeManager"
ref="typeManager"/>
<property name="shoppingCart"
ref="shoppingCart"/>
<property name="defaultType">
<bean
class="org.springframework.jndi.JndiObjectFactoryBean">
<property
name="jndiName">
<value>DEFAULT_TYPE</value>
</property>
<property
name="resourceRef">
<value>true</value>
</property>
</bean>
</property>
</bean>
In addition to the managers a default type is retrieved from the
JNDI registry right there in the configuration file and injected into
OlstoreImpl as a String.
<bean name="/store/viewItem.do"
class="olstore.controller.ViewItemController">
<property name="olstore" ref="olstore"/>
</bean>
The above configuration defines what controller class will be
invoked when the user accesses the url "store/viewItem.do" and provides
the OlstoreFacade object as a property to this controller class. Inside
the controller retrieving a POJO object representing the item is as
simple as:
String itemId = request.getParameter("itemId");
ItemValue item = this.olstore.getItemById(itemId);
ant original
- Builds only the original version as olstore.ear
ant spring
- Builds the 2nd version with Struts and
Spring communication with the EJBs as olstore-spring.ear
ant springmvc
- Builds the 3rd version with Spring
MVC used instead of struts as olstore-springmvc.ear
Though the three versions appear to be the same when viewed, the backend code is different in a few areas which will be outlined below:
Component | Olstore Original | Olstore Spring | Olstore Springmvc |
Build File | /build-original.xml | /build-spring.xml | /build-springmvc.xml |
Source Code | /src-original/olstore/* | /src/olstore/action
/src/olstore/dto /src/olstore/entity /src/olstore/form /src/olstore/framework /src/olstore/global /src/olstore/session /src/olstore/util /src/olstore/validation |
/src/olstore/util
/src/olstore/framework /src/olstore/dto /src/olstore/controller /src/olstore/domain |
JSP Source | /olstoreweb/struts/* | /olstoreweb/struts/* | /olstoreweb/spring/* |
Deployment Descriptor | /olstoreweb/WEB-INF/web-original.xml | /olstoreweb/WEB-INF/web-spring.xml | /olstoreweb/WEB-INF/web-springmvc.xml |
Spring Configuration | N/A | /olstoreweb/WEB-INF/spring/applicationContext.xml | /olstoreweb/WEB-INF/springmvc/applicationContext.xml /olstoreweb/WEB-INF/springmvc/olstore-servlet.xml |
Here is an example of how you would clear/drop a database when using the PostgreSQL supplied with the Olstore (please adapt to the datasource you are using):
Stop the jonas server: service jonas stop
Drop the database: dropdb -p 5433 db_jonas
Create the database: createdb -p 5433 db_jonas
Start the server: service jonas start
Deploy the app: jonas admin -a olstore.ear (or using the JonasAdmin Web Application)
visit Olstore: http://localhost:9000/olstore
Alternatively, tables in the database related to the olstore application are prefixed with 'olstore' in their names and they can be selectively dropped.
JOnAS comes with a UDDI registry based on jUDDI from Apache. You will need to follow the instructions provided with jonas to get jUDDI up and running.
You can find them at this following URL: http://jonas.objectweb.org/current/doc/doc-en/integrated/howto/install_juddi.html
IMPORTANT: The datasource.name should be set to 'jUDDIDB' (without the quotes) as that is the JNDI name specified in jUDDI's configuration files.
NOTE: You have to make sure that the user that you are going to be connecting to the registry as is listed as one of the publishers. Do this by adding a new row to the 'PUBLISHER' table.
Olstore registers its endpoints in the registry at the time it populates the database with all the product and user information. If the registry is not setup at that time Olstore skips and finishes populating product/user information anyway. If you need to register the endpoints again simply clean the database to trigger the populate action of Olstore. Instructions for PostgreSQL are provided above.
You can modify defult properties in the juddi.properties file.
There are two classes of users: customers and administrators.
CUSTOMERS: Customer users can perform the usual actions associated with an online store. They can browse and purchase products, mark products as interesting, checkout items, check the status of their orders, see which items they have bought, and update their user information. The usernames and passwords of some built in users are listed below. Some of these users already have friends associated with them and some have also purchased items. Also note that a new user can be created by clicking on the "register a new user" link on the login page.
Customer Usernames and Passwords:
mwringe/qwertyADMINISTRATORS: Another class of users is Administrator. These users can perform the same actions that customers can, but they also have special administrative actions they can perform. Administrators can: update the information about an item, create a new item, create a new type of item, and update orders. The usernames and passwords of the administrators are listed below. Please note that new administrators cannot be created by a user at this time.
aahmed/password
SamOak/Oaktree
bobbyv/bob47
lucy666/meow666
troll/troll9
mfrost/elley
icyMeg/74yci
Sammy/MarG14
user1/user1
user2/user2
user3/user3
user4/user4
Administrator Usernames and Passwords:
admin/admin
vivek/vivek
jonas/jonas