Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Advertisements

12 Copyright © 2005, Oracle. All rights reserved. Implementing Business Tasks with Session EJBs.
Technische universität dortmund Service Computing Service Computing Prof. Dr. Ramin Yahyapour IT & Medien Centrum 12. November 2009.
Development and Deployment Roles Venugopal Pakanati.
Writing Enterprise Applications with J2EE (Sixth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Writing Enterprise Applications with J2EE (First lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Writing Enterprise Applications with J2EE (Seventh lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Writing Enterprise Applications with J2EE (Fifth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Organizational Communication Technologies 1 Enterprise Java Beans Detail.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB. Component Characteristics An enterprise Bean typically contains business logic that operates on the enterprise’s data. An enterprise Bean’s instances.
4-Tier Model Client Tier Web Tier Business Tier EIS Tier.
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.
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)
Writing Enterprise Applications with J2EE (Second lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
Distributed Object-Oriented Programming (3) – Enterprise JavaBeans SNU iDB Lab. Taewhi Lee May 14th, 2007.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
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.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 6 Session Beans.
Distributed Systems 1 Master of Information System Management Distributed Systems Persistence.
The Triad of Beans I Oleh: Dini Addiati ( ) Fahrurrozi Rahman ( Y) Irfan Hilmy ( ) Salman Azis A ( ) Aziiz Surahman.
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.
Enterprise JavaBeans. Lesson 1: Introduction to Server-Side Component Software.
Self-executing Java, J2EE James Atlas July 29, 2008.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Enterprise Java Bean Computer Networks Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Introduction to J2EE CS : Software Design Winter /T13 Based on: Advanced Web Applications Development, cs © Eliezer Dekel, Sara.
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
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
Writing Enterprise Applications with J2EE (Fourth lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)
© jGuru.com Enterprise JavaBeans Fundamentals.
Creating competitive advantage Copyright © 2003 Enterprise Java Beans Presenter: Wickramanayake HMKSK Version:0.1 Last Updated:
EJB Overview: Constraint Types and Enforcement in JBoss Elissa Newman Fluid Meeting 6/3/04.
Entity Beans & Persistence Chris Alexander CS 486 Spring 2001.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
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.
Enterprise Java Beans Ye Zhou CS6704 Presentation Virginia Tech.
13 Copyright © 2004, Oracle. All rights reserved. Managing Persistent Data in the Business Tier Entity EJBs.
Enterprise JavaBeans: Fundamentals. EJB Fundamentals(c)CDAC(Formerly NCST)2 Contents Introduction Technology Overview EJB Architecture EJB Specification.
D Copyright © 2004, Oracle. All rights reserved. BMP Entity EJBs J2EE Connector Architecture.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Enterprise JavaBeans™ Trademark of Sun Microsystems, Inc.
14 Copyright © 2004, Oracle. All rights reserved. Achieving State Management in the Business Tier.
17 Copyright © 2004, Oracle. All rights reserved. Integrating J2EE Components.
JAVA & J2EE UNIT – 8 ENTERPRISE JAVA BEAN - EJB 28-Jun-16 Prepared by: SANTHIYA.M & GANGA V. C. Department: Computer Science & Engineering Course code:
1 EJB 3.0: There’s Something Different About You Martin Jäkle, TSBU Middleware.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Entity Bean Chuyên đề Lập trình Java & J2EE Chương 15
Java Servlets By: Tejashri Udavant..
Structure of Enterprise Java Beans
J2EE Application Development
Objectives In this lesson, you will learn to:
EJB Types Alessio Bechini June 2002.
Enterprise Java Beans Bina Ramamurthy 1/13/2019 B.Ramamurthy.
Software Development using MacroMedia’s JRun
Understanding and Designing with EJB
Enterprise Java Beans Bina Ramamurthy 4/5/2019 B.Ramamurthy.
Enterprise Java Beans.
Introduction to Session beans
Presentation transcript:

Writing Enterprise Applications with J2EE (Third lesson) Alessio Bechini June 2002 (based on material by Monica Pawlan)

Cooperating Enterprise Beans The example in the previous lessons is modified, making the session bean look up and create the entity bean. Because the session and entity bean work together, they are bundled into one JAR file for eployment. Required steps: Change the Session Bean Change the Servlet Compile Start the Platform and Tools Assemble, Verify and Deploy Run the J2EE Application

Interacting Components In the example presented here, the entity bean is a client of the session bean. This means the entity bean gets its data from the session bean instead of from BonusServlet. So, the calcBonus method in the session bean is modified to take the social security number as a parameter and create the entity bean.

CalcHome The CalcHome interface is unchanged. It has the same create method that returns an instance of the remote interface. package Beans; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome; public interface CalcHome extends EJBHome { Calc create() throws CreateException, RemoteException; }

Calc The calcBonus method is changed to take the social security number as a parameter. This way CalcBean can pass the bonus and social security number to the entity bean. A new getRecord method is added so CalcBean can find an entity bean by its primary key (the social security number). Also, the calcBonus method signature throws DuplicateKeyException and CreateException, and BonusServlet can catch and handle either of them. DuplicateKeyException descends from CreateException. If you design the calcBonus method to throw DuplicateKeyException, but catch CreateException, DuplicateKeyException is not thrown. The way around this is to have calcBonus throw both DuplicateKeyException and CreateException.

Calc (Code) package Beans; import javax.ejb.EJBObject; import java.rmi.RemoteException; import javax.ejb.DuplicateKeyException; import javax.ejb.CreateException; public interface Calc extends EJBObject { public Bonus calcBonus(int multiplier, double bonus, String socsec) throws RemoteException, DuplicateKeyException, CreateException; public Bonus getRecord(String socsec) throws RemoteException; }

CalcBean The code to create the entity bean is moved from BonusServlet to the calcBonus method so the bonus and social security number can be written to the entity bean after the bonus is calculated. The homebonus variable is an instance variable: it can be used in the calcBonus method to look up the entity bean and in the getRecord method to locate the entity bean corresponding to the social security number.

CalcBean (Code, I) package Beans; import java.rmi.RemoteException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; import javax.ejb.DuplicateKeyException; import javax.ejb.CreateException; public class CalcBean implements SessionBean { BonusHome homebonus; //Throw DuplicateKeyException and CreateException //so BonusServlet can catch and handle these exception conditions. public Bonus calcBonus(int multiplier,double bonus, String socsec) throws DuplicateKeyException, CreateException { Bonus theBonus = null; double calc = (multiplier*bonus); try { InitialContext ctx = new InitialContext(); Object objref = ctx.lookup("bonus"); homebonus = (BonusHome) PortableRemoteObject.narrow(objref, BonusHome.class); } catch (Exception NamingException) { NamingException.printStackTrace(); }...

CalcBean (Code, II) // store data in entity bean try { theBonus=homeBonus.create(calc, socsec); } catch (java.rmi.RemoteException e) { String message=e.getMessage(); e.printStackTrace(); } return theBonus; public Bonus getRecord(String socsec) { Bonus record = null; // Use primary key to retrieve data from entity bean try { record=homeBonus.findByPrimaryKey(socsec); } catch (java.rmi.RemoteException e) { String message=e.getMessage(); } catch (javax.ejb.FinderException e) { e.printStackTrace(); } return record; } public void ejbCreate() { } public void setSessionContext(SessionContext context) { } public void ejbRemove() { } public void ejbActivate() { } public void ejbPassivate() { } public void ejbLoad() { } public void ejbStore() { } }

Servlet Code: init method public class BonusServlet extends HttpServlet { CalcHome homecalc; BonusHome homebonus; Bonus theBonus, record; public void init(ServletConfig config) throws ServletException{ try { InitialContext ctx = new InitialContext(); Object objref = ctx.lookup("calcs"); homecalc = (CalcHome)PortableRemoteObject.narrow(objref, CalcHome.class); } catch (Exception NamingException) { NamingException.printStackTrace(); }... The BonusServlet is very similar to the version of the previous lesson, with changes in the init and doGet methods. The init method now looks up the CalcBean session bean only.

Servlet Code: inside doGet (I) try { Calc theCalculation; //Retrieve Bonus and Social Security Information String strMult = request.getParameter("MULTIPLIER"); //Calculate bonus Integer integerMult = new Integer(strMult); multiplier = integerMult.intValue(); socsec = request.getParameter("SOCSEC"); double bonus = ; theCalculation = homeCalc.create(); //Call session bean theBonus = theCalculation.calcBonus(multiplier, bonus, socsec); record = theCalculation.getRecord(socsec); //Display data out.println(" Bonus Calculation "); out.println(" Soc Sec retrieved: " + record.getSocSec() + " "); out.println(" Bonus Amount retrieved: " + record.getBonus() + " "); out.println(" "); } catch (javax.ejb.DuplicateKeyException e) {...}

Assemble the J2EE Application The steps for assembling the new application, making use of the deploy tool, include the following: Create a new J2EE Application Create a new Web Component, with the new version of the servlet Bundle Session and Entity Beans in one JAR file

Create a new Application Application display name: 2BeansApp Locate the directory for the.ear file File name: 2BeansApp.ear

Create a new Web Component Using the proper wizard, a web component (bundled into a WAR file) containing bonus.html and BonusServlet.class is created, according to the following data: WAR display name: BonusWar Servlet class: BonusServlet.class Component Aliases: BonusAlias

The JAR File for the EJBs To put both the session and entity beans in the same JAR file, we can first create a jar for the session bean, and then add the entity bean to it. Note that transactions are required to be associated with methods calcBonus and getRecord of the session bean CalcBean.