SlideShare a Scribd company logo
EJB
Creating first Session
Bean
Session 1
Introduction to EJB
1. EJB provides component base Development
2. Provide write once deploy anywhere
3. Allows customization via Deployment Descriptor (no Java code
modification)
4. Development focuses on Business Logic
5. EJB Server provides
1. Transaction Mgmt
2. Security
3. Concurrency
4. Resource Mgmt
5. Messaging
6. Depoly time Customization
Types of Bean
1. Entity Bean
• Represent a thing in persistence store e.g. row on database or
Serialized object in file.
2. Message Driven Bean
• Can listen a message from JMS Messaging service
3. Session Bean
• Represent a process or can contain a business logic
• Stateful Session Bean
• Can remember conversational state between method call
• Stateless Session Bean
• Can’t remember conversational state between method call
Rules for Building a Sample Bean
To create sample bean we need to follow below steps
• Code the bean class with all business method
• Code to interfaces for bean (home & component)
• Create XML Deployment Descriptor, must be
name it as ejb-jar.xml
• Deploy bean in application server
Bean Class HelloBean.java
package com;
import javax.ejb.*;
public class HelloBean implements SessionBean{
public void ejbActivate(){}
public void ejbPassivate(){}
public void ejbRemove(){}
public void setSessionContext(SessionContext ctx){}
public String helloWorld(){
return "Hello there!!!";
}
public void ejbCreate() {}
}
Little (More) about Bean Class HelloBean.java
If you are completely new to EJB, then you definitely says
what the hec is that… here is your answers
1. Your bean class (which contains the actual definition of mth
or says business logic) must implements SessionBean
interface according to spec
2. According to java rule you have to implements all
unimplemented mth from interface
3. The helloWorld() is your actual business mth, which will be
called by client
4. The ejbCreate() not come from SessionBean interface, but
we need to give the empty definition of it (???WTF??? this
is what is going is your mind right now, b relax the answer is
coming in next few slides.
Component Interface Hello.java
package com;
import javax.ejb.*;
import java.rmi.*;
public interface Hello extends EJBObject{
public String helloWorld() throws RemoteException;
}
Little (More) about Component Interface
1. You definitely find some similarities between Component
Interface & Bean class, if you are really thinking what I m
thinking, then you are right.
2. The component interface contains declarations of all
business mth which is to be defined by Bean class.
3. But according to java rules to implement the mth from
interface, the class must have the these magical statements
“implements Interface_Name”, which is in our case is
missing. Then how these two are related. Forget this for
now, I will explain this later.
4. Component interface must extends EJBObject interface
5. Its all mth must throws RemoteException
6. They can also thorws custom application (Checked)
Exception.
7. Its return type must be primitives/Serializable
Objs/Arrays/Collection of primitives or Serializable
Objs/Remote obj (These are called as RMI-IIOP
Complients).
Home Interface HelloHome.java
package com;
import javax.ejb.*;
import java.rmi.*;
public interface HelloHome extends EJBHome{
public Hello create() throws
CreateException,RemoteException;
}
Little (More) about Component Interface
• Home interface must extends EJBHome interface
• Must declare the create() (here is hint for your Bean class
ejbCreate() mth)
• Return type of create() must be component interface type
• Mth must throws CreateException & RemoteException.
• They can also thorws custom application (Checked)
Exception.
Combining the all stuff together
• Now what we have here : Component, Home & bean. we know
all these stuff work together, but question is how? Here is
ur ans.
• We need to tell the container that all these things are work
together by putting their entries in ejb-jar.xml
• WTH is ejb-jar.xml? : It is Deployment Descriptor (DD) like
web.xml in servlets.
• It tells the container that which is home, component & bean
to run the business logic.
• It also states what the Bean type i.e. Session(stateless,
stateful), Entity or Message-Driven (You can understand all
this from syntax).
• We are creating only sample stateless session bean, so only
session tags are avail. For Entity & Message-Driver will see
later.
Sample ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar>
<display-name>Hello EJB App</display-name>
<enterprise-beans>
<session>
<display-name>Hello</display-name>
<ejb-name>Hello</ejb-name>
<home>com.HelloHome</home>
<remote>com.Hello</remote>
<ejb-class>com.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
Deploying & Calling the Bean mth
• Now you have to create the jar of all compiled class with
below structure.
ejbApp.jar
com
Hello.class
HelloHome.class
HelloBean.class
META-INF
ejb-jar.xmlejb-jar.xml
glassfish-ejb-jar.xml
Deploying & Calling the Bean mth
• You noticed there is one more xml file glassfih-ejb-jar.xml,
now lets see what is it.
• As per my understanding, every server has its own ejb-
jar.xml file for deployment of ejb application. For e.g. if you
are deploying in weblogic server then you have additional
weblogic-ejb-jar.xml
• As I m using glassfish server for app deployment so I have
glassfish-ejb-jar.xml
• We will see the deployments of ejb & web application (part)
in later.
• Now I am writing the plane jsp to call the Bean mth.
• You need to deploy this jsp(war) file in glassfish & run the
jsp.
Client HelloClient.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.rmi.PortableRemoteObject"%>
<%@page import="com.HelloHome"%>
<%@page import="com.Hello"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<%
try{
InitialContext ic = new InitialContext();
Object obj = ic.lookup("Hello");
HelloHome home =
(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
Hello hello = home.create();
String res = hello.helloWorld();
System.out.println(res);
out.println(res);
}catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html>
Thank you
• I am not expert in EJB, but if you have any doubts in
tutorial please feel free to contact me on
ashishkirpan@gmail.com
• Sorry for spelling & grammar mistakes :)
Have a fun with EJB

More Related Content

What's hot

Ejb notes
Ejb notesEjb notes
Ejb notes
Mumbai Academisc
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
Kelum Senanayake
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
Bill Lyons
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
Armen Arzumanyan
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
Acp Jamod
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2vikram singh
 
EJB 2
EJB 2EJB 2
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
Jitender Singh Lodhi
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)vikram singh
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
Return on Intelligence
 
Java EE EJB Applications
Java EE EJB ApplicationsJava EE EJB Applications
Java EE EJB Applications
DevelopIntelligence
 
Enterprise java beans
Enterprise java beansEnterprise java beans
Enterprise java beans
Quontra Solutions
 
Jsf+ejb 50
Jsf+ejb 50Jsf+ejb 50
Jsf+ejb 50
lullabyte
 
Session 1 Tp1
Session 1 Tp1Session 1 Tp1
Session 1 Tp1phanleson
 
Ch4 ejb
Ch4 ejbCh4 ejb
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
guest346cb1
 

What's hot (18)

Ejb notes
Ejb notesEjb notes
Ejb notes
 
Java bean
Java beanJava bean
Java bean
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2Enterprise java beans(ejb) update 2
Enterprise java beans(ejb) update 2
 
EJB 2
EJB 2EJB 2
EJB 2
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Enterprise Java Beans( E)
Enterprise  Java  Beans( E)Enterprise  Java  Beans( E)
Enterprise Java Beans( E)
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
Java EE EJB Applications
Java EE EJB ApplicationsJava EE EJB Applications
Java EE EJB Applications
 
Enterprise java beans
Enterprise java beansEnterprise java beans
Enterprise java beans
 
Jsf+ejb 50
Jsf+ejb 50Jsf+ejb 50
Jsf+ejb 50
 
Session 1 Tp1
Session 1 Tp1Session 1 Tp1
Session 1 Tp1
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
Ejb intro
Ejb introEjb intro
Ejb intro
 

Similar to 1-introduction to ejb

Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3phanleson
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)vikram singh
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2vikram singh
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4phanleson
 
Java j2eeTutorial
Java j2eeTutorialJava j2eeTutorial
Java j2eeTutorial
QUONTRASOLUTIONS
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical OverviewSvetlin Nakov
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patternsAlassane Diallo
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
rani marri
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
Krishna900061
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
Tharindu Weerasinghe
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
Pankaj Singh
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
achraf_ing
 
Introduction to Java EE EJB Component
Introduction to Java EE EJB ComponentIntroduction to Java EE EJB Component
Introduction to Java EE EJB Component
Ganesh P
 
J boss ide-tutorial
J boss ide-tutorialJ boss ide-tutorial
J boss ide-tutorialUTN
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
tayab4687
 
Ejb intro
Ejb introEjb intro
Ejb intro
MANOJ KUMAR
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
Simon Ritter
 

Similar to 1-introduction to ejb (20)

Session 3 Tp3
Session 3 Tp3Session 3 Tp3
Session 3 Tp3
 
Enterprise java beans(ejb)
Enterprise java beans(ejb)Enterprise java beans(ejb)
Enterprise java beans(ejb)
 
Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2Enterprise java beans(ejb) Update 2
Enterprise java beans(ejb) Update 2
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
J2 Ee Overview
J2 Ee OverviewJ2 Ee Overview
J2 Ee Overview
 
Java j2eeTutorial
Java j2eeTutorialJava j2eeTutorial
Java j2eeTutorial
 
J2EE - Practical Overview
J2EE - Practical OverviewJ2EE - Practical Overview
J2EE - Practical Overview
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patterns
 
ADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.pptADVANCED JAVA MODULE I & II.ppt
ADVANCED JAVA MODULE I & II.ppt
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
What's new in Java EE 6
What's new in Java EE 6What's new in Java EE 6
What's new in Java EE 6
 
Bea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guideBea weblogic job_interview_preparation_guide
Bea weblogic job_interview_preparation_guide
 
Ejb - september 2006
Ejb  - september 2006Ejb  - september 2006
Ejb - september 2006
 
Introduction to Java EE EJB Component
Introduction to Java EE EJB ComponentIntroduction to Java EE EJB Component
Introduction to Java EE EJB Component
 
J boss ide-tutorial
J boss ide-tutorialJ boss ide-tutorial
J boss ide-tutorial
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 

Recently uploaded

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 

Recently uploaded (20)

Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 

1-introduction to ejb

  • 2. Introduction to EJB 1. EJB provides component base Development 2. Provide write once deploy anywhere 3. Allows customization via Deployment Descriptor (no Java code modification) 4. Development focuses on Business Logic 5. EJB Server provides 1. Transaction Mgmt 2. Security 3. Concurrency 4. Resource Mgmt 5. Messaging 6. Depoly time Customization
  • 3. Types of Bean 1. Entity Bean • Represent a thing in persistence store e.g. row on database or Serialized object in file. 2. Message Driven Bean • Can listen a message from JMS Messaging service 3. Session Bean • Represent a process or can contain a business logic • Stateful Session Bean • Can remember conversational state between method call • Stateless Session Bean • Can’t remember conversational state between method call
  • 4. Rules for Building a Sample Bean To create sample bean we need to follow below steps • Code the bean class with all business method • Code to interfaces for bean (home & component) • Create XML Deployment Descriptor, must be name it as ejb-jar.xml • Deploy bean in application server
  • 5. Bean Class HelloBean.java package com; import javax.ejb.*; public class HelloBean implements SessionBean{ public void ejbActivate(){} public void ejbPassivate(){} public void ejbRemove(){} public void setSessionContext(SessionContext ctx){} public String helloWorld(){ return "Hello there!!!"; } public void ejbCreate() {} }
  • 6. Little (More) about Bean Class HelloBean.java If you are completely new to EJB, then you definitely says what the hec is that… here is your answers 1. Your bean class (which contains the actual definition of mth or says business logic) must implements SessionBean interface according to spec 2. According to java rule you have to implements all unimplemented mth from interface 3. The helloWorld() is your actual business mth, which will be called by client 4. The ejbCreate() not come from SessionBean interface, but we need to give the empty definition of it (???WTF??? this is what is going is your mind right now, b relax the answer is coming in next few slides.
  • 7. Component Interface Hello.java package com; import javax.ejb.*; import java.rmi.*; public interface Hello extends EJBObject{ public String helloWorld() throws RemoteException; }
  • 8. Little (More) about Component Interface 1. You definitely find some similarities between Component Interface & Bean class, if you are really thinking what I m thinking, then you are right. 2. The component interface contains declarations of all business mth which is to be defined by Bean class. 3. But according to java rules to implement the mth from interface, the class must have the these magical statements “implements Interface_Name”, which is in our case is missing. Then how these two are related. Forget this for now, I will explain this later. 4. Component interface must extends EJBObject interface 5. Its all mth must throws RemoteException 6. They can also thorws custom application (Checked) Exception. 7. Its return type must be primitives/Serializable Objs/Arrays/Collection of primitives or Serializable Objs/Remote obj (These are called as RMI-IIOP Complients).
  • 9. Home Interface HelloHome.java package com; import javax.ejb.*; import java.rmi.*; public interface HelloHome extends EJBHome{ public Hello create() throws CreateException,RemoteException; }
  • 10. Little (More) about Component Interface • Home interface must extends EJBHome interface • Must declare the create() (here is hint for your Bean class ejbCreate() mth) • Return type of create() must be component interface type • Mth must throws CreateException & RemoteException. • They can also thorws custom application (Checked) Exception.
  • 11. Combining the all stuff together • Now what we have here : Component, Home & bean. we know all these stuff work together, but question is how? Here is ur ans. • We need to tell the container that all these things are work together by putting their entries in ejb-jar.xml • WTH is ejb-jar.xml? : It is Deployment Descriptor (DD) like web.xml in servlets. • It tells the container that which is home, component & bean to run the business logic. • It also states what the Bean type i.e. Session(stateless, stateful), Entity or Message-Driven (You can understand all this from syntax). • We are creating only sample stateless session bean, so only session tags are avail. For Entity & Message-Driver will see later.
  • 12. Sample ejb-jar.xml <?xml version="1.0" encoding="UTF-8"?> <ejb-jar> <display-name>Hello EJB App</display-name> <enterprise-beans> <session> <display-name>Hello</display-name> <ejb-name>Hello</ejb-name> <home>com.HelloHome</home> <remote>com.Hello</remote> <ejb-class>com.HelloBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> </enterprise-beans> </ejb-jar>
  • 13. Deploying & Calling the Bean mth • Now you have to create the jar of all compiled class with below structure. ejbApp.jar com Hello.class HelloHome.class HelloBean.class META-INF ejb-jar.xmlejb-jar.xml glassfish-ejb-jar.xml
  • 14. Deploying & Calling the Bean mth • You noticed there is one more xml file glassfih-ejb-jar.xml, now lets see what is it. • As per my understanding, every server has its own ejb- jar.xml file for deployment of ejb application. For e.g. if you are deploying in weblogic server then you have additional weblogic-ejb-jar.xml • As I m using glassfish server for app deployment so I have glassfish-ejb-jar.xml • We will see the deployments of ejb & web application (part) in later. • Now I am writing the plane jsp to call the Bean mth. • You need to deploy this jsp(war) file in glassfish & run the jsp.
  • 15. Client HelloClient.jsp <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%@page import="javax.naming.InitialContext"%> <%@page import="javax.rmi.PortableRemoteObject"%> <%@page import="com.HelloHome"%> <%@page import="com.Hello"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <body> <% try{ InitialContext ic = new InitialContext(); Object obj = ic.lookup("Hello"); HelloHome home = (HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class); Hello hello = home.create(); String res = hello.helloWorld(); System.out.println(res); out.println(res); }catch(Exception e){ e.printStackTrace(); } %> </body> </html>
  • 16. Thank you • I am not expert in EJB, but if you have any doubts in tutorial please feel free to contact me on ashishkirpan@gmail.com • Sorry for spelling & grammar mistakes :) Have a fun with EJB