Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lab - Session Beans - Stateless

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 23

Creating Stateless Session Beans

Agenda
Install Pre-requisite Softwares and DB Connection Develop a simple Stateless Session Bean Call

Pre-requisites
Eclipse IDE (Bundled with JBoss 6) Jboss Server (http://sourceforge.net/projects/jboss/files/JB oss/JBoss-6.0.0.Final/)

Eclipse IDE
Eclipse IDE Download Jboss Eclipse Plugin
http://www.eclipse.org/

http://www.jboss.org/tools/download/

JBoss Server
Download the Application Server: http://sourceforge.net/projects/jboss/files/JBo s/JBoss-6.0.0.Final/

JBoss Server Installation


Install Jboss Server on your Eclipse IDE.
Step 1: Go to New > Server > Server Step 2: Choose Jboss AS 6.0 Step 3: Define the Location of the Jboss AS

JBoss Server
Define the Home directory of JBoss AS and click Finish.

Project Overview
For this session: We ll create a simple Stateless Session Bean.

Create Enterprise Java Bean Project


Go to > New > EJB > EJB Project Name: ejbsampleproject_<name> Target: JBoss 6. Create EAR Project Create Client Project Click Next to Finish

EJB Project Stateless Session Bean


Generated:
EJB Project Client Project EAR

EJB Project Stateless Session Bean


Make sure that:
Jboss Library is included on the Build Path of EJB and Client.

EJB Project: Develop the Bean


Create new Session Bean
Java Package: com.gradu.ejb.samplebeans Class name: SampleStatelessBean State Type: Stateless Create Remote and Local Interfaces

EJB Project: Develop the Bean


Create new Session Bean
Click Finish

EJB Project: Develop the Bean


Create new Session Bean
The Wizard Generated the following:
1. Session Bean named SampleStatelessBean 2. Remote Interface named SampleStatelessBeanRemote 3. Local Interface name SampleStatelessBeanLocal

EJB Project: Develop the Bean


Create new Session Bean
Generated Session Bean:

EJB Project: Develop the Bean


Create new Session Bean
Add a mappedName attribute to the bean. This will serve as the JNDI name of the Bean.

EJB Project: Develop the Bean


Modify Local and Remote Interface
Edit the Local and Remote Interface to implement the method.

Note: Remote and Local Interface served as the clients reference of the bean.

EJB Project: Develop the Bean


Implement Interface Methods
We need to implement the methods we just added and try returning a String value .

EJB Project: Develop the Client


Create a new Client Class
Create a new class on the client project. This client will be the one calling our Session Bean from the Application Server.

Java Package: com.gradu.ejb.client Class name: SampleClient

EJB Project: Develop the Client


Modify the Client Class to Call our Bean
Create a new class on the client project. This client will be the one calling our Session Bean from the Application Server.

EJB Project: Develop the Client


Deploy the Session Bean
We need to deploy the session bean first before executing the Sample Client.

Run the EAR file on the server to deploy the EJB Components.

EJB Project: Develop the Client


Verify Deployment from Console
After running the EAR file (deployment), we need to verify if the Application Server Indeed deployed our beans.

If the above lines are shown on the Console, then the Session Bean was successfully deployed.

EJB Project: Testing the Bean


Test the Session Bean using the Client Class
Run the Client Class.

If you were able to see the value thrown from the Session Bean, that means you have successfully called the Bean from the Application Server.

You might also like