+ All Categories
Home > Documents > Lab - Session Beans - Stateful

Lab - Session Beans - Stateful

Date post: 07-Apr-2018
Category:
Upload: alvin-reyes
View: 224 times
Download: 0 times
Share this document with a friend

of 23

Transcript
  • 8/6/2019 Lab - Session Beans - Stateful

    1/23

    Creating Stateful Session Beans

    Alvin Reyes

  • 8/6/2019 Lab - Session Beans - Stateful

    2/23

    Agenda

    Install Pre-requisite Softwares and DB

    Connection

    Develop a simple Stateful Session Bean Call

  • 8/6/2019 Lab - Session Beans - Stateful

    3/23

    Pre-requisites

    Eclipse IDE (Bundled with JBoss 6)

    Jboss Server

    (http://sourceforge.net/projects/jboss/files/JBoss/JBoss-6.0.0.Final/)

  • 8/6/2019 Lab - Session Beans - Stateful

    4/23

    Eclipse IDE

    http://www.eclipse.org/

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

    Eclipse IDE Download

    Jboss Eclipse Plugin

  • 8/6/2019 Lab - Session Beans - Stateful

    5/23

    JBoss Server

    Download the Application Server:

    http://sourceforge.net/projects/jboss/files/JBo

    s/JBoss-6.0.0.Final/

    Default Username: admin

    Default Password: admin

  • 8/6/2019 Lab - Session Beans - Stateful

    6/23

    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

  • 8/6/2019 Lab - Session Beans - Stateful

    7/23

    JBoss Server

    Define the Home directory

    of JBoss AS and click Finish.

  • 8/6/2019 Lab - Session Beans - Stateful

    8/23

    Project Overview

    For this session:

    Well create a simple Stateful Session Bean.

  • 8/6/2019 Lab - Session Beans - Stateful

    9/23

    Create Enterprise Java Bean Project

    Note: You can skip the Project creation if you already have an existing EJB

    project.

    1. Go to > New > EJB > EJB Project2. Name: ejbsampleproject_

    3. Target: JBoss 6.

    4. Create EAR Project

    5. Create Client Project

    6. Click Next to Finish

    We will now create the EJB that will serve as the consumer of the requests

  • 8/6/2019 Lab - Session Beans - Stateful

    10/23

    EJB Project Stateless Session Bean

    Generated:

    EJB Project

    Client Project

    EAR

  • 8/6/2019 Lab - Session Beans - Stateful

    11/23

  • 8/6/2019 Lab - Session Beans - Stateful

    12/23

    Create new Session BeanJava Package: com.gradu.ejb.samplebeans

    Class name: SampleStatefulBean

    State Type: Stateful

    Create Remote and Local Interfaces

    EJB Project: Develop the Bean

  • 8/6/2019 Lab - Session Beans - Stateful

    13/23

    Create new Session Bean

    Click Finish

    EJB Project: Develop the Bean

  • 8/6/2019 Lab - Session Beans - Stateful

    14/23

    Create new Session Bean

    The Wizard Generated the following:

    1. Session Bean named SampleStatefulBean

    2. Remote Interface named SampleStatefulBeanRemote

    3. Local Interface name SampleStatefulBeanLocal

    EJB Project: Develop the Bean

  • 8/6/2019 Lab - Session Beans - Stateful

    15/23

    Create new Session Bean

    Generated Session Bean:

    EJB Project: Develop the Bean

  • 8/6/2019 Lab - Session Beans - Stateful

    16/23

    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

  • 8/6/2019 Lab - Session Beans - Stateful

    17/23

    Modify Local and Remote Interface

    Edit the Local and Remote Interface to implement the method.

    EJB Project: Develop the Bean

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

  • 8/6/2019 Lab - Session Beans - Stateful

    18/23

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

    and add a new Setter to test that our Bean.

    EJB Project: Develop the Bean

  • 8/6/2019 Lab - Session Beans - Stateful

    19/23

    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.

    EJB Project: Develop the Client

    Java Package: com.gradu.ejb.client

    Class name: SampleClient

  • 8/6/2019 Lab - Session Beans - Stateful

    20/23

    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

  • 8/6/2019 Lab - Session Beans - Stateful

    21/23

    Deploy the Session Bean

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

    EJB Project: Develop the Client

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

  • 8/6/2019 Lab - Session Beans - Stateful

    22/23

    Verify Deployment from Console

    After running the EAR file (deployment), we need to verify if the Application Server

    Indeed deployed our beans.

    EJB Project: Develop the Client

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

    deployed.

  • 8/6/2019 Lab - Session Beans - Stateful

    23/23

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

    EJB Project: Testing the Bean

    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.


Recommended