Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.

Slides:



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

11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
An architecture for webb applications, J2EE
1 Softsmith Open Learning - EJB 21-Nov Enterprise Java Beans Introduction –Application ServerApplication Server –Java 2 Enterprise EditionJava.
JBoss Seam: Contextual Components Jason Bechtel
Sapana Mehta (CS-6V81) Overview Of J2EE & JBoss Sapana Mehta.
Enterprise Applications & Java/J2EE Technologies Dr. Douglas C. Schmidt Professor of EECS.
EJB Design. Server-side components Perform –complex algorithms –high volume transactions Run in –highly available environment (365 days/year) –fault tolerant.
Enterprise Java Beans Welcome to the world of “Distributed System” Presented By: Sameer Nanda Date: 12/17/03.
Java 2 – Enterprise Edition Kevin J. LaFata April 21, 2003 UM – St. Louis.
1 Build a Web Application on J2EE. 2 J2EE Scenario Client – Web Server – EIS Resources Client – Web Server – EIS Resources Client – Application Server.
Current Topics in Programming Languages Lecture 15_1 George Koutsogiannakis SUMMER
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Session-01. What is a Servlet? Servlet can be described in many ways, depending on the context: 1.Servlet is a technology i.e. used to create web application.
Emmanuel Cecchet et al.  Performance Scalability of J2EE application servers.  Test effect of: ◦ Application Implementation Methods ◦ Container Design.
INTRODUCING THE JAVA EE PLATFORM Ch-5. Introduction Java is a  platform-independent programming language  secure and robust applications  may run on.
Chapter 10 EJB Concepts of EJB Three Components in Creating an EJB Starting/Stopping J2EE Server and Deployment Tool Installation and Configuration of.
EJB Overview Celsina Bignoli Distributed Business Applications Server DB Client DB Server DB.
Distributed Multitiered Applications The J2EE platform uses a multitiered distributed application model. Application logic is divided into components 1.
1 J2EE Components. 2 Application Servers relieve the programming burden for business distributed components. They provide support for system level services.
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Session Beans Overview EJB container Remote Invocation Represent client's access to app Local / Remote speed / flexibility trade-off when to choose local.
CS 493/693: Distributed Systems Programming V. “Juggy” Jagannathan CSEE, West Virginia University March 21, 2005.
Entity Java Beans Jorg Janke Open Source ERP & CRM.
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.
CD Database Server (CDDB) Zachary Carter Alan Savage Diana Abbas Kyle Dorman.
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.
TDDD05 EJB Lab (Part of slides reused from Mikhail’s) Lu Li
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
第十四章 J2EE 入门 Introduction What is J2EE ?
J2EE Structure & Definitions Catie Welsh CSE 432
Source: Peter Eeles, Kelli Houston, and Wojtek Kozaczynsky, Building J2EE Applicationa with the Rational Unified Process, Addison Wesley, 2003 Prepared.
Ch 2 – Application Assembly and Deployment COSC 617 Jeff Schmitt September 14, 2006.
1 Java EE Programming Enterprise JavaBeans. 2 Topics J2EE Overview Enterprise JavaBeans Overview Enterprise Entity Beans Case Study How to build them.
Introduction to Enterprise JavaBeans Topics In Systems Architecture Barry Herbold
Enterprise Java Overview Panos Konstantinidis Java Developer JUG Leader & Java Champion
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Component Patterns – Architecture and Applications with EJB copyright © 2001, MATHEMA AG Component Patterns Architecture and Applications with EJB Markus.
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.
1 Distributed Systems Distributed Object-Based Systems Chapter 10.
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.
©NIIT Introducing Enterprise JavaBeans (EJB) Lesson 1A / Slide 1 of 43J2EE Server Components Objectives In this lesson, you will learn about: The features.
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.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
©NIIT Session Beans Lesson 1B/ Slide 1 of 37J2EE Server Components Objectives In this lesson, you will learn to: Describe the characteristics of session.
Session Beans and The Timer Service. Contents  Session Beans  The Timer Service.
Callbacks and Interceptors. Contents  Session Beans Life Cycle  Interceptors.
J2EE Lecture 10: EJB 3.0 Overview
Enterprise JAVA Bean.
Structure of a web application
EJB (Enterprise Java Beans)
Introduction to J2EE Architecture
J2EE Application Development
Understanding and Designing with EJB
Luca Simone Software Engineering 2 a.a. 2001/2002
Objectives In this lesson, you will learn to:
Objectives In this lesson you will learn about: Need for servlets
Component-based Applications
Component Technology Bina Ramamurthy 2/25/2019 B.Ramamurthy.
Understanding and Designing with EJB
Enterprise Java Beans.
Knowledge Byte In this section, you will learn about:
Presentation transcript:

Enterprise Java Beans

Contents  Understanding EJBs  Practice Section

1. Understanding EJBs  Types of EJBs  Anatomy of an EJB  EJB Container  Embedded Container  Dependency Injection and JNDI  Packaging

1.1.Types of EJBs EJBs are server-side components that encapsulate business logic and take care of transactions, security … Architecture layering

The Java EE platform defines several types of EJBs. Session beans are used to encapsulate high- level business logic, which makes them the most important part of the EJB technology. A session bean may have the following traits:  Stateless: The session bean contains no conversational state between methods, and any instance can be used for any client.  Stateful: The session bean contains conversational state, which must be retained across methods for a single user.

 Singleton: A single session bean is shared between clients and supports concurrent access.

1.2.Anatomy of an EJB Session beans encapsulate business logic, are transactional, rely on a container that does pooling, multithreading, security, and so on. A Simple Stateless EJB  The BookEJB is a is a stateless session bean that acts like a façade and handles CRUD operations on the Book entity.

The BookEJB becomes a stateless session bean. The EJB obtains a reference of an entity manager using dependency injection.

The client side invokes smethod on the BookEJB. The BookEJB is deployed in a container, the Main class (the client) needs to access the EJB remotely.  Adding a simple remote interface to the EJB will give it remote access capabilities.

1.3. EJB Container An EJB is a server-side component and needs to be executed in a container. This runtime environment provides core features common to many enterprise applications.  Remote client communication: Without writing any complex code, an EJB client (another EJB, a user interface, a batch process, etc.) can invoke methods remotely via standard protocols.  Dependency injection: The container can inject several resources into an EJB (datasources, other EJBs, environment variables,...).

 State management: For stateful session beans, the container manages their state transparently.  Pooling: For stateless beans and message-driven beans (MDBs), the container creates a pool of instances that can be shared by multiple clients. Once invoked, an EJB returns to the pool to be reused instead of being destroyed.  Component life cycle: The container is responsible for managing the life cycle of each component.

 Messaging: The container allows MDBs to listen to destinations and consume messages.  Transaction management: With declarative transaction management, an EJB can use annotations to inform the container about the transaction policy it should use. The container takes care of the commit or the rollback.  Security: Class or method-level access control can be specified on EJBs to enforce user and role authentication.

 Concurrency support: Except for singletons, where some concurrency declaration is needed, all the other types of EJB are thread-safe by nature. You can develop high performance applications without worrying about thread issues.  Interceptors: Cross-cutting concerns can be put into interceptors, which will be invoked automatically by the container.  Asynchronous method invocation: With EJB 3.1, it’s now possible to have asynchronous calls without involving messaging.

Once the EJB is deployed, the container takes care of these features, leaving the developer to focus on business logic. When a client invokes an EJB, it doesn’t work directly with an instance of that EJB but rather with a proxy on an instance.  The call is actually proxied through the container, which provides services on behalf of the bean instance. Of course, this is completely transparent to the client.

In a Java EE application, the EJB container will usually interact with other containers: the servlet container (responsible for managing the execution of servlets and JSF pages), the application client container, or ACC (for managing stand-alone applications), the message broker (for sending, queuing, and receiving messages), the persistence provider, and so on.  These containers will all run inside an application server (GlassFish, JBoss, Weblogic, etc.).

1.4. Embedded Container EJBs have to be executed in a container that runs in a separate JVM. The application server first needs to be started before deploying and using your EJB. An issue with servers running in a different process is that unit-testing capabilities are limited, and unit tests cannot be easily run without deploying the EJB in a live server.  Some application server implementations came with embedded containers.

An embedded container is to be able to execute EJB applications within a Java SE environment allowing clients to run within the same JVM and class loader.  This provides better support for testing, offline processing (e.g., batch processing), and the use of the EJB in desktop applications. The embeddable container API (defined in javax.ejb.embeddable ) provides the same managed environment as the Java EE runtime container and includes the same services.

Creating an instance of an embeddable container, get a JNDI context, get a lookup for an EJB, and invoke a method:

1.5. Dependency Injection and JNDI EJBs use dependency injection to access several kinds of resources (other EJBs, datasources, environment resources, etc.).  In this model, the container pushes data into the bean. Injection is made at deployment time.  A client gets injected a reference to an EJB using private static BookEJBRemote bookEJB;

JNDI is an alternative to injection; through JNDI, the code pulls data only if it is needed, instead of accepting pushed data that may not be needed at all. Using the InitialContext of JNDI and look up a deployed EJB named java:global/BookEJBRemote as follows:  Context ctx = new InitialContext(); BookEJBRemote bookEJB = (BookEJBRemote) ctx.lookup("java:global/BookEJBRemote");  Naming convention: java:global[/ ]/ / [! ]

1.6. Packaging EJBs need to be packaged before they are deployed into a runtime container.  In the same archive, you will usually find the enterprise bean class, its interfaces, interceptors, any needed superclasses or superinterfaces, exceptions, helper classes, and an optional deployment descriptor (ejb-jar.xml).  Once these artifacts are packaged in a jar (Java archive) file, they can be deployed directly into a container. Another option is also to embed the jar file into an ear (enterprise archive) file and deploy the ear file.

An ear file is used to package one or more modules (EJBs or web applications) into a single archive so that deployment into an application server happens simultaneously and coherently.

Since EJB 3.1, EJBs can also be directly packaged within a web module (war file).

2. Practice Section EJBs are transactional by nature, so our stateless session bean (BookEJB) will handle Create, Read, Update, Delete (CRUD) operations on the Book entity with container- managed transactions CMTs. The BookEJB and the Book entity will then be packaged and deployed into GlassFish. The EJB needs a remote interface, as an external client application (Main class) will invoke methods remotely on the EJB using the ACC.

1. Create an enterprise application  BookEnterpriseApplication

2. Create a datasource required by persistence unit. This datasource must be created using GlassFish administration console or command line.

Create JDBC connection pool

Create JDBC Resource

3. Write the Book entity in EBJ module

4. Writing the BookEJBRemote interface and BookEJB Stateless Session Bean

5. Writing the Main class in Application Client Module

6. Run the enterprise application

Run: Build, Undeploy, deploy, run Main class Check the database

6. Writing the BookEJBTest Class  To unit test the EJB The EJB embedded container.

Stop the GlassFish server and test the file.

A stand- alone java client to access Remote EJB component 1. Add gf-client.jar (glassfish\modules) to the classpath 2. Add the jar file of ejb module to the classpath

Reference Antonio Goncalves, Beginning Java EE 6 Platform with GlassFish 3, Chapter 6, Apress 2009