1 Introduction to J2EE CS 236700: Software Design Winter 2004-2005/T13 Based on: Advanced Web Applications Development, cs236606 © Eliezer Dekel, Sara.

Slides:



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

Introduction to Servlets Based on: Hall, Brown, Core Servlets and JavaServer Pages.
An architecture for webb applications, J2EE
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
An introduction to Java Servlet Programming
Overview of The Java Platform Solution for E-Business Applications : JSP, Servlet and EJB.
1 Copyright 2002 © Paulo Merson J2EE – Building Component-based Enterprise Web Applications 05/09/2002 Paulo Merson.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
18-Jun-15 JSP Java Server Pages Reference: Tutorial/Servlet-Tutorial-JSP.html.
Application Server Lecture Paulo Barroso Kris Carver Todd Kitterman Eric Silva.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Introduction to Servlet & JSP
Java Server and Servlet CS616 Team 9 Kim Doyle, Susan Kroha, Arunima Palchowdhury, Wei Xu.
Object Oriented Analysis and Design 1 Chapter 8 - Web Application System Design  Modeling Web Application using UML  Application Server  Web Application.
Servlet and JSP Programming: An Introduction Spiros Papadimitriou
UNIT-V The MVC architecture and Struts Framework.
Java Server Pages B.Ramamurthy. Topics for Discussion 8/20/20152 Inheritance and Polymorphism Develop an example for inheritance and polymorphism JSP.
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.
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 J2EE. 2 Agenda 1. Application servers 2. What is J2EE?  Main component types  Application Scenarios  J2EE APIs and Services 3. EJB – a closer look.
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)
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.
Objectives Java Servlet Web Components
Enterprise JavaBeans Umer Farooq CS6704: Design Patterns & Component FrameworksFebruary 25, 2002.
Java Web Development with NetBeans IDE -- Kai Qian Chapter 6 Session Beans.
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
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.
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.
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.
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.
Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some.
A TUTORIAL TO USING EJBs by SHREERAM IYER 09/17/2001.
Java Servlets & Java Server Pages Lecture July 2013.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
Java Servlets and Java Server Pages Norman White Stern School of Business.
1 Introduction to Servlets. Topics Web Applications and the Java Server. HTTP protocol. Servlets 2.
CS562 Advanced Java and Internet Application Introduction to the Computer Warehouse Web Application. Java Server Pages (JSP) Technology. By Team Alpha.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
Enterprise Java Bean Technology Briefing Markus Hebach.
Enterprise JavaBeans Session Beans. Session beans are a type of Enterprise JavaBean component designed to implement business logic responsible for managing.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Java Servlets and Java Server Pages
Session Beans Objectives Introduction to Session Beans Local and Remote Session Beans Stateless and Stateful Session Beans Session Bean Lifecycle Accessing.
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.
©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.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Java Server Pages. 2 Servlets The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Bayu Priyambadha, S.Kom. Static content  Web Server delivers contents of a file (html) 1. Browser sends request to Web Server 3. Web Server sends HTML.
CS 562 Advanced Java and Internet Application Computer Warehouse Web Application By Team Alpha :-  Puja Mehta (102163)  Mona Nagpure (102147)
Speaker Name Speaker Title Speaker Title Oracle Corporation Olivier Le Diouris Principal Product Manager Oracle Corporation Building Servlet and JSP Applications.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Introduction to Servlets
CS122B: Projects in Databases and Web Applications Winter 2017
Java Servlets By: Tejashri Udavant..
CS122B: Projects in Databases and Web Applications Winter 2018
CS122B: Projects in Databases and Web Applications Winter 2019
Presentation transcript:

1 Introduction to J2EE CS : Software Design Winter /T13 Based on: Advanced Web Applications Development, cs © Eliezer Dekel, Sara Porat, Michael Factor, Gal Shachor: IBM Labs in Haifa © Tal Cohen: The Computer Science Department, the Technion

2 Preface  A huge scope  Complex terminology  Our goals: An overview of J2EE, J2EE services Understanding the EJB framework  Deployment is a significant issue Will not be discussed

3 Introduction (1/4): Enterprise Application  Enterprise Application Running the information and activity of big organizations Government agencies, Banks, Retailers Must support various demands High-availability Scalability Backwards compatibility Multiple clients from remote sites Consistent data Security Usually, designed around a client-server architecture A stand-alone design cannot support remote access A peer-to-peer design has security flaws and is more difficult to program A “leader” usually simplifies any distributed algorithm

4 Introduction (2/4): A Three-tier application  Typical design of an Enterprise application: Client Database Server First TierSecond TierThird Tier  This is a Three-tier application Quite similar the Model-View-Controller pattern The key difference: the brains of the system is located inside the 2 nd tier Usually called: Business Logic Many times the client is just web-browser

5 Introduction (3/4): Application Server  The Business Logic layer (2 nd tier) Is usually the most complicated tier to design The other two tiers are complex, but their design is almost mechanical  Typically called: Application Server It servers as a platform which invokes different applications The platform provides core services to these applications Concurrency, Networking, Transactions Naming Security HTTP Connectivity etc.

6 Introduction (4/4): The Motivation Let a developer focus on the domain-specific programming. The general concerns are handles by the underlying platform  This goal has motivated the development of many Application Server products J2EE is a standard (by sun) for an application server Has several implementations: JBoss, Web-Sphere, WebLogic  Note that an application server addresses the same needs as an operating system

7 J2EE in Action: Banking System Browser Account Deposit Servlet Accounts EJB Database J2EE Server HTTP RMI JDBC First TierSecond TierThird Tier Employees EJB RMI JDBC  The applications: Account EJB, Employees EJB, Account Deposit Servlet  The J2EE server provide many useful services (as mentioned before)  The applications need to invoke these services… …But not to implement them

8 The J2EE internal architecture  Three basic types of applications JSP – Java Server Page Servlets EJB – Enterprise Java Beans  Containers: Each manages a certain type of application EJB Container Servlet Container (handles JSPs as well)  Fundamental technologies used by J2EE: Reflection, Dynamic Compilation, Serialization, RMI

9 JSP (1/2)  Purpose: A simplified way to generate dynamic web content  What is it? An HTML page with embedded tags and Java Code At runtime the JSP page is translated into an HTML page  The process: A JSP page is dynamically converted into a Java code that is compiled by the J2EE server When a user request arrives, it is passed to an instance of this class, which creates the desired textual output (HTML)

10  Special variables: out – A JspWriter object session – An HttpSession object of current user session. request – An HttpServletRequest object associated with current user request response – An HttpServletResponse object JSP (2/2) page language="java" contentType="text/html; charset=US-ASCII" pageEncoding="US-ASCII" %> What’s the time Welcome to what-is-the-time.com <% String s = new java.util.Date().toString(); out.print("Current time=" + s); %> page language="java" contentType="text/html; charset=US-ASCII" pageEncoding="US-ASCII" %> What’s the time Welcome to what-is-the-time.com <% String s = new java.util.Date().toString(); out.print("Current time=" + s); %> d1/time.jsp

11 Servlets (1/2)  Purpose: A standard way for a Java program to handle HTTP requests  What is it? A Servlet is a Java class that extends HttpServlet When the client sends a request to the server, it is forwarded to an instance of the appropriate servlet class

12 Servlets (2/2) import java.io.*; import javax.servlet.ServletException; import javax.servlet.http.*; public class MyServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println(" "); out.println("Your Name is " + req.getParameter("name")); out.println(" "); } import java.io.*; import javax.servlet.ServletException; import javax.servlet.http.*; public class MyServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter out = resp.getWriter(); out.println(" "); out.println("Your Name is " + req.getParameter("name")); out.println(" "); } d1/MyServlet.html

13 EJBs  Purpose: Provide the means for encapsulation and reuse of business logic and/or persistent data  What is it? The EJB mechanism is a realization of the component model A reusable software unit (like a class), which is dynamically manipulated by the J2EE server  Why is it needed? Many times the same business logic is used by several distinct elements in the J2EE. For instance: In a banking system, both the withdraw-servlet and the deposit-servlet need to use the “set-balance” functionality We are speaking of a distributed environment with persistent data => it is not possible to invoke the setBalance() method on an instance of the Account class

14 Types of EJBs  Session bean: Represents a single client Relatively short lived Does not represent shared data in a database Does not generally survive EJB server crashes  Entity bean: Represent shared, persistent data (The data is usually stored in a database) Can be long lived Survives EJB server crashes

15 The EJB mechanism (1/3)  Interaction: EJB container and an existing EJBs Pooling: Reuse of idle EJBs Sharing: Let two clients use a single EJB instance Usually used with a stateless session EJB Passivation/Activation: Save to file/reload from file An idle EJB may become passive due to memory considerations Etc.  EJBs are (of course) implemented as instances of classes  Option 1: The J2EE standard will define a dedicated class, which implements these methods Each EJB class will have to extend this dedicated class The flaw: In a single inheritance language, this approach rules-out the possibility of inheritance between EJBs  Option 2: Let the server “paste” the required methods into the EJB class (See next slide)

16 The EJB mechanism (2/3) “EJBObject implementation” CalculatorImpl add(int,int) sub(int,int) getEJBHome() getHandle() getPrimaryKey() isIdentical(EJBObject) remove() EJBObject getEJBHome() getHandle() getPrimaryKey() isIdentical(EJBOBject) remove() Remote “Remote interface” Cart addBook(String) removeBook(String) extends implements API Interfaces Bean Developer Generated extends delegates “EJBObject implementation” CartImpl addBook(String) removeBook(String) getEJBHome() getHandle() getPrimaryKey() isIdentical(EJBObject) remove() “Bean class” CartBean setSessionContext(..) ejbCreate(String) ejbActivate() ejbPassivate() ejbRemove() addBook(String) removeBook(String)

17 The EJB mechanism (3/3)  Outline of steps Programmer writes an interface for the business logic Programmer writes a class which implements this interface But it does not have to declare “ implements X ” The EJB container creates a class which implements the interface This class forwards the calls to the actual class Additional code is inserted into this class

18 The EJB initialization mechanism (1/2)  Creation of a new EJB Client code can’t just use new MyEjbClass() to create an EJB Why? 1.The name of the actual implementation is not known 2.Many times the EJB container just recycles an existing instance  => Outline of steps: The programmer defines “initialization-methods” in his bean class Named: ejbCreate(…) The programmer defines the interface (called: Home Interface) for a factory class Parameters to methods must match the ejbCreate() methods The EJB container creates a class which implements the Home Interface This class forwards the calls to the appropriate ejbCreate() method Additional code is inserted into this class

19 The EJB initialization mechanism (2/2) EJBHome getEJBMetaData() getHomeHandle() remove(Handle) remove(Object) “Bean class” CartBean setSessionContext(..) ejbCreate(String) ejbActivate() ejbPassivate() ejbRemove() addBook(String) removeBook(String) Remote “Home interface” CartHome create(String) “EJBHome implementation” CartHomeImpl create(String) getEJBMetaData() getHomeHandle() remove(Handle) remove(Object) extends implements delegates API Interfaces Bean Developer Generated

20 A Stateful Session EJB (1/4)  We’d like to model a “Shopping-cart” in an on-line book store  The cart is represented by a stateful session bean

21 A Stateful Session EJB (2/4)  Our business logic: Add/remove book to cart Observe the contents of the cart public interface Cart extends EJBObject { public void addBook(String title) throws RemoteException; public void removeBook(String title) throws RemoteException; public Vector getContents() throws RemoteException; } public interface Cart extends EJBObject { public void addBook(String title) throws RemoteException; public void removeBook(String title) throws RemoteException; public Vector getContents() throws RemoteException; }

22 A Stateful Session EJB (3/4) import java.io.Serializable; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome; public interface CartHome extends EJBHome { Cart create(String name) throws RemoteException; Cart create(String name, String id) throws RemoteException; } import java.io.Serializable; import java.rmi.RemoteException; import javax.ejb.CreateException; import javax.ejb.EJBHome; public interface CartHome extends EJBHome { Cart create(String name) throws RemoteException; Cart create(String name, String id) throws RemoteException; }

23 A Stateful Session EJB (4/4) public class CartBean implements SessionBean { private String name_; private String id_; private Vector books_; public void ejbCreate(String name) { ejbCreate(name, "0"); } public void ejbCreate(String name, String id) { name_ = name; id_ = id; books_ = new Vector(); } public Vector getContents() { return books_; } public void addBook(String title) { books_.addElement(title); } public void removeBook(String title) { books_.removeElement(title); } public CartBean() {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sc) {} } public class CartBean implements SessionBean { private String name_; private String id_; private Vector books_; public void ejbCreate(String name) { ejbCreate(name, "0"); } public void ejbCreate(String name, String id) { name_ = name; id_ = id; books_ = new Vector(); } public Vector getContents() { return books_; } public void addBook(String title) { books_.addElement(title); } public void removeBook(String title) { books_.removeElement(title); } public CartBean() {} public void ejbRemove() {} public void ejbActivate() {} public void ejbPassivate() {} public void setSessionContext(SessionContext sc) {} }

24 A simple EJB client import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; public class CartClient { public static void main(String[] args) throws Throwable { Context initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/SimpleCart"); CartHome home = (CartHome) PortableRemoteObject.narrow(objref, CartHome.class); Cart shoppingCart = home.create( “ Graham Chapman ", " 123 " ); shoppingCart.addBook("Last of the Mohicans"); } import java.util.*; import javax.naming.Context; import javax.naming.InitialContext; import javax.rmi.PortableRemoteObject; public class CartClient { public static void main(String[] args) throws Throwable { Context initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/SimpleCart"); CartHome home = (CartHome) PortableRemoteObject.narrow(objref, CartHome.class); Cart shoppingCart = home.create( “ Graham Chapman ", " 123 " ); shoppingCart.addBook("Last of the Mohicans"); }  Uses JNDI classes to locate the home interface See: Object objref = initial.lookup( "..." );