Presented By Pradeep K Sahu. What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a.

Slides:



Advertisements
Similar presentations
12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
Advertisements

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Development and Deployment Roles Venugopal Pakanati.
Approaches to EJB Replication. Overview J2EE architecture –EJB, components, services Replication –Clustering, container, application Conclusions –Advantages.
6/1/20151 Luca Simone Software Engineering 2 a.a. 2001/2002.
1 Softsmith Open Learning - EJB 21-Nov Enterprise Java Beans Introduction –Application ServerApplication Server –Java 2 Enterprise EditionJava.
June 1999 EJB1 EJB and CHAIMS Dorothea Beringer Enterprise Java Beans and how to build a CHAIMS infrastructure using the EJB paradigm.
Remote Method Invocation Chin-Chih Chang. Java Remote Object Invocation In Java, the object is serialized before being passed as a parameter to an RMI.
Enterprise Java Beans Adam, Engels, Josh, Marc, Tim.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
CS 483 Enterprise and Web Application Programming
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Fundamentals Celsina Bignoli
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
Brad Rippe Fullerton College. What you need to get started? JDK 1.3 standard for compilation J2EE - SDK1.2.1 App Server - An EJB Container/Web Container.
1 Session Bean Chuyên đề Lập trình Java & J2EE Chương 14 Biên soạn: Th.S Nguyễn văn Lành.
1 3. Implementing Web Services 1.Create SOAP proxy interfaces and WSDL based service descriptions 2.Register/publish services 3.Stores service descriptions.
J2EE Part 2: Enterprise JavaBeans CSCI 4300 Images and code samples from jGuru EJB tutorial,
Enterprise Java Beans - (EJB)
Seminar: Enterprise JavaBeans. Agenda Agenda Java™ 2 Platform Java™ 2 Platform Java™ 2 Platform,Enterprise Edition(J2EE) Java™ 2 Platform,Enterprise Edition(J2EE)
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Enterprise Java Beans Part I Kyungmin Cho 2001/04/10.
Container-Managed Persistence (CMP) Entity Beans Lesson 3A / Slide 1 of 42J2EE Server Components Objectives In this lesson, you will learn to: Identify.
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Enterprise Java Beans Part II Kyungmin Cho 2001/04/13.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Enterprise JavaBeans. What is EJB? l An EJB is a specialized, non-visual JavaBean that runs on a server. l EJB technology supports application development.
Introduction to J2EE Architecture Portions by Kunal Mehta.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
J2EE Structure & Definitions Catie Welsh CSE 432
Session Beans -) stateless -) stateful. Session Beans A session bean represents a single client inside the J2EE server. To access an application that.
A TUTORIAL TO USING EJBs by SHREERAM IYER 09/17/2001.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
1 Session Beans and Business Logic Presented By: Sethu Ram Kettimuthu.
© jGuru.com Enterprise JavaBeans Fundamentals.
1 Java EE Programming Enterprise JavaBeans. 2 Topics J2EE Overview Enterprise JavaBeans Overview Enterprise Entity Beans Case Study How to build them.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Enterprise Java Bean Technology Briefing Markus Hebach.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Copyright © 2002 ProsoftTraining. All rights reserved. Enterprise JavaBeans.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
EJB Enterprise Java Beans JAVA Enterprise Edition
EJB. Introduction Enterprise Java Beans is a specification for creating server- side scalable, transactional, multi-user secure enterprise-level applications.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
J2EE Lecture 10: EJB 3.0 Overview
Introduction to Enterprise JavaBean
Understanding and Designing with EJB
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Component-based Applications
Understanding and Designing with EJB
Enterprise Java Beans: an introduction
Introduction to Session beans
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Presented By Pradeep K Sahu

What will be the Contents of the Seminar ? What is EJB ? EJB Architecture Types of EJB Session Entity Why EJB ? Writing a Hello World Session EJB Differences between Java Bean and Enterprise Java Bean

 It defines a framework for creating distributed enterprise middleware Enterprise Java Beans (EJB) ….  Defines a standard to building distributed server side systems  Frees the EJB developer to only concentrate on programming the business logic  Handles the other “plumbing” to handle transactions, security connection /thread pooling etc., by delegating this to the vendor

Differences between  No explicit support exists for transactions in Java beans.  EJB may be transactional and the EJB server provide transactional support. Java BeansEnterprise Java Beans  Can be either visible or non- visible  Are decidedly Non –Visible remote objects  Intended to be local to a single process on the client side  Remotely executable components deployed on the server  Uses the Bean Info classes. Property Editors and Customizers to describe it self  Uses the Deployment Descriptor to describe itself  Can also be developed as an ActiveX control  Cannot be deployed as an ActiveX control since OCX run on the desktop

Why Enterprise Java Beans?  Architectural Independence from middleware  Write Once Run Anywhere (WORA) for server side components  Establishes role for application development  Takes care of Transaction Management  Provides Distributed Transaction support  Helps create Portable and scalable solutions  Integrates seamlessly with CORBA  Provides vendor specific enhancements

Components of the EJB Architecture are The EJB Architecture  EJB Client  EJB server  EJB Container  The Home Interface and Home Object  The Remote Interface and EJBObject  EJBeans  Other services like JNDI,JTS & Security

Architecture

 Makes EJB Container visible The EJB Server  Provides an organized framework for EJB Containers to execute in  Provides system-services like multiprocessing, load balancing, device access, JNDI accessible naming and transaction services available to the container

 Session containers contain session EJBs and Entity containers contain entity EJBs EJB Containers  Interface between EJBeans and outside world  EJB client never access an EJBeans directly –any access is done through container- generated methods which in turn invoke bean methods

 The Home Object is the implementation of the Home Interface The Home Interface and The Home Object  Contains Factory methods for locating creating and removing instances of EJBs  The EJB developer defines the Home Interface for his bean  The Home Object is generated by tools provided by the Container Vender

The Remote Interface and the EJB Object  EJB Clients use the methods present in the Remote Interface to invoke business methods of the EJBean  The Remote Interface lists the business methods present in an EJB class  The Remote Interface is defined by the EJB developer  The EJBObject which is the concern class for the Remote Interface is generated by the tools provided by the container vendor

The EJB Client  Finds EJB containers using JNDI  Uses EJB containers to invoke EJB methods  Uses the Home Object to locate, create,or destroy an EJB class.  Uses the EJBObject instance to invoke business methods of the EJB instance

The Enterprise Java Bean  Contained within the EJB container and is only accesses through the container  There are two types of EJBeans  Session  Entity (3 rd type Message Driven Bean is added in EJB 2.0)  Session Beans are again two types  Stateless and  Stateful

Difference between Session and Entity Bean Session Bean Entity Bean  Are associated with a particular client  Are shared by multiple clients  Handle database access for a particular client  Handle database access for a multiple clients  Life is limited to the life of a particular client  Persist across multiple invocations  Do not survive server crashes  Survive server crashes

 Start the server and execute the client Steps involved in Developing an EJB  Define Home Interface  Define Remote Interface  Develop Entity or Session Bean  In the case of Entity Beans, define the Primary Key Class  Write the Deployment Descriptor / XML File.  Compile all classes and create the Jar file  Generate the container code by using the tools provided by the container provider  Develop the Client code  Deploy the EJB in the server

We have covered Lets Summarize….. Next  Why we need EJB and its advantages  Components of EJB Architecture  Types of EJB that is Session and Entity Bean  Difference between Session and Entity Bean Guess ?

Yes, you are right… Next Session Bean…..

Session Beans  Represents a business process and business process related logics.  Are two types 1.Stateless Session Bean : are beans that holds conversations that span a single method call. 2.Stateful session bean : are beans that hold conversations with clients that may span many method calls. Now let’s write a “Hello World” Stateless Session Bean(We will deploy in Weblogic) Introduction

Writing a “Hello World !” Stateless Session Bean

Writing the Home Interface Requirements for any Home Interface  Extend javax.ejb.EJBHome  Expose at least one create() method.

The Complete java Code for HelloHome.java import javax.ejb.*; import java.rmi.RemoteException; /** * This is the home interface for HelloBean. This interface * is implemented by the EJB Server's tools - the * implemented object is called the Home Object and serves * as a factory for EJB Objects. */ public interface HelloHome extends EJBHome { /* * This method creates the EJB Object. */ Hello create() throws RemoteException, CreateException; }

Writing the Remote Interface Requirements for any Remote Interface  Extend javax.ejb.EJBObject  Declare the business methods that are to be exposed.

The Complete java Code for Hello.java import javax.ejb.*; import java.rmi.RemoteException; import java.rmi.Remote; /** * This is the HelloBean remote interface. * * This interface is what clients operate on when * they interact with EJB objects. The container * vendor will implement this interface; the * implemented object is the EJB object, which * delegates invocations to the actual bean. */ public interface Hello extends EJBObject { /** * The one method - hello - returns a greeting to the client. */ public String hello() throws java.rmi.RemoteException; }

Requirements for SessionBean  Extend javax.ejb.SessionBean public interface javax.ejb.SessionBean extends javax.ejb.EnterpriseBean { public abstract void setSessionContext(SessionContext ctx) throws java.rmi.RemoteException; public abstract void ejbPassivate() throws java.rmi.RemoteException; public abstract void ejbActivate() throws java.rmi.RemoteException; public abstract void ejbRemove() throws java.rmi.RemoteException; }  Implements the Business methods defined in the Remote interface. In our example hello(). Writing the Bean Class

The Complete java Code for HelloBean.java import javax.ejb.*; public class HelloBean implements SessionBean { // EJB-required methods public void ejbCreate() { System.out.println("ejbCreate()"); } public void ejbRemove() { System.out.println("ejbRemove()"); } public void ejbActivate() { System.out.println("ejbActivate()"); } public void ejbPassivate() { System.out.println("ejbPassivate()"); } public void setSessionContext(SessionContext ctx) { System.out.println("setSessionContext()"); } //Business methods public String hello{ System,out.println(“hello()”); return “Hello,World”; }

Deployment Descriptor To Deploy any Session Bean on Weblogic server 5.1 we need 2 descriptor (XML) file. 1.ejb-jar.xml :This XML file must conform to the DTD provided by JavaSoft in the EJB 1.1 specification. This XML file is not vendor specific. 2.weblogic-ejb-jar.xml : specifies deployment properties required for deploying EJBs in WebLogic Server (For example defines timeout, pooling, and clustering behavior for EJBs)

Writing ejb-jar.xml Deployment Descriptor images/green-cube.gif images/orange-cube.gif HelloWorld HelloHome Hello HelloBean Stateless Container HelloWorld Remote * Required

Writing weblogic-ejb-jar.xml Deployment Descriptor HelloWorld 10 HelloHome The name which will be shown in the server The JNDI Name for the client to lookup Max no of bean in pool

Creating EJB-jar After getting all the java files compiled and the 2 xml file written we have to create the jar file containing all the files with the required order.For our Hello World application the files should be in the following order Hello.class HelloHome.class HelloBean.class ejb-jar.xml weblogic-ejb-jar.xml green-cube.gif orange-cube.gif Create the jar file with the following command Jar cf *.* For Example jar cf HelloWorld.jar *.* If package is defined then the files should be in the respective package order Like MyPackage/Hello.class in the root Icon image files

Generating EJB Container classes and Deployment Once the HelloWorld.jar file is created next is to  Create the container classes  Generate the container classes with the help of ejbc Compiler. The Command is ejbc Source jar file : is the jar file created by us.(Contains 2 XML files and Home,Remote and Bean classes. The target jar file :The jar file which will be created.This will contain all the required container classes. For Example : ejbc HelloWorld.jar HelloWorldEJB.jar

Continue…. Once we get the jar file containing the Container classes we are ready to deploy the our EJB in Weblogic 5.1 server. We can deploy in a different ways.We will deploy by adding the jar file details to the weblogic.properties file so that the EJB will get automatically loaded when the application server starts. The format is weblogic.ejb.deploy= Note : The folder path separator is “/” not ‘\’ For example: weblogic.ejb.deploy=D:/Java/Programs/Examples/EJB/HeloWorldEJB.jar After adding the above line restart the WebLogic.So that the EJB will get loaded.

Lets Summarize….. We have covered  EJB Architecture and its Components  Home Interface,Remote Interface  Session Bean Details  How to write a Stateless Session EJB  How to deploy an EJB in Weblogic server Next How to write the Client application.

Lets take a

How to write the Client program The Client code performs the following tasks : Looks up a home object Uses the home object to create an EJB Object. Calls the business methods ( hello() in our example ) on the EJB object Removes the EJB Object.

import javax.ejb.*; import javax.naming.*; import java.rmi.*; import java.util.Properties; public class HelloClient { public static void main(String[] args) { try { // Get System properties for JNDI initialization Properties props = System.getProperties(); // Form an initial context Context ctx = new InitialContext(props); // Get a reference to the home object (the factory for EJB objects) HelloHome home = (HelloHome) ctx.lookup("HelloHome"); // Use the factory to create the EJB Object Hello hello = home.create(); //Call the hello() method, and print it System.out.println(hello.hello()); //Remove the EJB Object hello.remove(); } catch (Exception e) { e.printStackTrace(); } The Complete java Code for HelloClient.java

The Client needs the following components or parameters  The J2EE class files in the classpath  The Home and Remote Interface in it’s classpath  The JNDI environment information Running the Client 1.Run the setEnv.bat file present in the Weblogic root folder to set the class path and other environment settings 2.Run the Client with the JNDI parameters. In case of weblogic we can run the command by the following command java -Djava.naming.factory.initial=weblogic.jndi.TengahInitialContextFactory -Djava.naming.provider.url=t3://localhost:7001 For our HelloWorld application it is java -Djava.naming.factory.initial=weblogic.jndi.TengahInitialContextFactory -Djava.naming.provider.url=t3://localhost:7001 HelloClient Running the Client

The Server-Side Output When we run the client, our container shows the folloeing output setSessionContext() ejbCreate() hello() ejbREmove() The Client-Side Output After running the client, we can see the following out put : Hello,World! Output

Stateless Session Bean Life Cycle Before Closing the Stateless Session Bean lets have a look on the Life Cycle and sequence diagram of Stateless Session Bean Each method call shown is an invocation from the container to the bean instance.

Sequence diagram for stateless session beans.

Presented By Pradeep K Sahu For Your Patience……