EJB & J2EE. Component Technology with thanks to Jim Dowling. Components. Problems with Previous Paradigms. What EJB Accomplishes



Similar documents
Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

Java E-Commerce Martin Cooke,

Java-technology based projects

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

What Is the Java TM 2 Platform, Enterprise Edition?

Java EE 7: Back-End Server Application Development

Glassfish, JAVA EE, Servlets, JSP, EJB

JAVA ENTERPRISE IN A NUTSHELL. Jim Farley and William Crawford. O'REILLY 4 Beijing Cambridge Farnham Koln Paris Sebastopol Taipei Tokyo.

Elements of Advanced Java Programming

Chapter 4. Architecture. Table of Contents. J2EE Technology Application Servers. Application Models

How To Protect Your Computer From Being Hacked On A J2Ee Application (J2Ee) On A Pc Or Macbook Or Macintosh (Jvee) On An Ipo (J 2Ee) (Jpe) On Pc Or

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

White paper. IBM WebSphere Application Server architecture

Distributed Objects and Components

WebSphere Training Outline

Enterprise Application Integration

25 May Code 3C3 Peeling the Layers of the 'Performance Onion John Murphy, Andrew Lee and Liam Murphy

Oracle WebLogic Server 11g Administration

Enterprise Applications

OUR COURSES 19 November All prices are per person in Swedish Krona. Solid Beans AB Kungsgatan Göteborg Sweden

Outline SOA. Properties of SOA. Service 2/19/2016. Definitions. Comparison of component technologies. Definitions Component technologies

Enterprise JavaBeans Fundamentals

Introduction to Sun ONE Application Server 7

CHAPTER 1 - JAVA EE OVERVIEW FOR ADMINISTRATORS

What is Middleware? Software that functions as a conversion or translation layer. It is also a consolidator and integrator.

Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

JBS-102: Jboss Application Server Administration. Course Length: 4 days

MagDiSoft Web Solutions Office No. 102, Bramha Majestic, NIBM Road Kondhwa, Pune Tel: /

Java 2 Platform, Enterprise Edition (J2EE): Enabling Technologies for EAI

How To Write A Bean In Java (Java) (Java 2.4.2) (Java.Net) (Javax) 2 (Java Bean) ( Java Bean) 2-4.5

PERFORMANCE MONITORING OF JAVA COMPONENT-ORIENTED DISTRIBUTED APPLICATIONS

Service Oriented Architectures

Virtual Credit Card Processing System

Agenda. Java Features Review. Extreme Java G Session 1 - Main Theme Introducing Extreme Java

Motivation Definitions EAI Architectures Elements Integration Technologies. Part I. EAI: Foundations, Concepts, and Architectures

CACHÉ: FLEXIBLE, HIGH-PERFORMANCE PERSISTENCE FOR JAVA APPLICATIONS

White Paper: 1) Architecture Objectives: The primary objective of this architecture is to meet the. 2) Architecture Explanation

Enterprise Application Development In Java with AJAX and ORM

CONSUMER DEMAND MONITORING AND SALES FORECASTING (CDMFS) SYSTEM

Net-WMS FP Net-WMS SPECIFIC TARGETED RESEARCH OR INNOVATION PROJECT. Networked Businesses. D.8.1 Networked architecture J2EE compliant

Mastering Tomcat Development

This training is targeted at System Administrators and developers wanting to understand more about administering a WebLogic instance.

The Design of B2B E-commerce System Based on MVC Model and J2EE

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

WebLogic Server 7.0 Single Sign-On: An Overview

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

NetBeans IDE Field Guide

Basic TCP/IP networking knowledge of client/server concepts Basic Linux commands and desktop navigation (if don't know we will cover it )

Detailed Table of Contents

3-Tier Architecture. 3-Tier Architecture. Prepared By. Channu Kambalyal. Page 1 of 19

Client-Server Applications

Chapter 6. CORBA-based Architecture. 6.1 Introduction to CORBA 6.2 CORBA-IDL 6.3 Designing CORBA Systems 6.4 Implementing CORBA Applications

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Web Application Architecture (based J2EE 1.4 Tutorial)

Oracle WebLogic Server 11g: Administration Essentials

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

SOFT 437. Software Performance Analysis. Ch 5:Web Applications and Other Distributed Systems

CS Developing Web Applications with Java Technologies

WEBSPHERE APPLICATION SERVER ADMIN V8.5 (on Linux and Windows) WITH REAL-TIME CONCEPTS & REAL-TIME PROJECT

Enterprise JavaBeans 3.1

Chapter 5 Application Server Middleware

Monitoring Pramati EJB Server

How To Write A Microsoft.Net Event Management System (Mnet)

ON-LINE BOOKING APPLICATION NEIL TAIT

Getting Started with Web Applications

WebSphere Server Administration Course

MIDDLEWARE 1. Figure 1: Middleware Layer in Context

JNMWare: Network Management Platform Using Java Technologies

IBM WebSphere Server Administration

Performance Comparison of Java Application Servers

B. WEB APPLICATION ARCHITECTURE MODELS

Adobe ColdFusion 11 Enterprise Edition

JAVA Technologies QUARTER 1 DESKTOP APPLICATIONS - ESSENTIALS QUARTER 2 NETWORKING AND OPERATING SYSTEMS ESSENTIALS. Module 1 - Office Applications

Sun Microsystems Inc. Java Transaction Service (JTS)

SAP Web Application Server 6.30: Learning Map for Development Consultants

Extreme Java G Session 3 Main Theme Java Core Technologies (Part I) Dr. Jean-Claude Franchitti

Designing an Enterprise Application Framework for Service-Oriented Architecture 1

GlassFish Security. open source community experience distilled. security measures. Secure your GlassFish installation, Web applications,

As you learned about in Chapter 1, WebSphere Application Server V6 supports the

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

WEB SERVICES. Revised 9/29/2015

DEPLOYMENT ARCHITECTURE FOR JAVA ENVIRONMENTS

JBoss JEE5 with EJB3.0 on NonStop. JAVA SIG, San Jose

Building Web Applications, Servlets, JSP and JDBC

JavaPolis 2004 Middleware and Web Services Security

Understanding Application Servers

Japan Communication India Skill Development Center

Monitoring Applications on Pramati Server

Transcription:

University of Dublin Trinity College EJB & J2EE Component Technology with thanks to Jim Dowling The Need for Component-Based Technologies The following distributed computing development paradigms have benefits but also have many problems: Remote Procedure Calls (RPC) 2-Tier Client/Server (Java RMI, DCOM) Object Request Brokers (ORBs). Deficiencies: Objects written in this environment are completely stateless, storage of the state of these objects is left to the developer. Developers must also write non-trivial code to deal with transactions, concurrency and other the integration of other object services. 2 Problems with Previous Paradigms Coding was far too complex because developers could not focus exclusively on writing Business Logic, rather there was too much focus on code for the infrastructure... Writing code to register Servers with Directory Services. Writing code to deal with Security and Transaction Services. Lifecycle issues Scalability issues Data Access Gartner Group estimates that 65% of programmer time is spent building infrastructure, instead of distributed application functionality [Financial Times, 04/01/02] Components A software component is a unit of composition with contractually specified interfaces and explicit context dependencies only. A software component can be deployed independently and is subject to composition by third parities. [Clemens Szyperski, Component Software: Beyond Object-Oriented Programming, 1997] Enterprise Java Beans, COM+,.Net and the CORBA Component Model are examples of distributed server-side component systems. 3 4 Enterprise JavaBeans Components Built on top of RMI RMI over IIOP allows integration with other existing CORBA products and middleware Makes Distributed programming (RMI/CORBA) easier Declarative Programming. EJB has a Container Model Let the EJB Server do all of the hard work! What EJB Accomplishes You can take a Java class and with little effort make it a distributed, secure, transactional class These are hard to bespoke implement You can take any a source and make the data source appear to be a collection of Java objects Eliminates distinction between data from a database and any other source: All information is accessed through Java objects All SQL is cleanly encapsulated in Java objects true object-oriented programming Database objects work with the full Java class library 5 6 1

Programming Implications Developers can focus on writing business logic rather than writing low-level infrastructure like data access, concurrency, transactions, threading, etc. Reduces development time Reduces complexity Increases quality and reliability However The programming model contains many restrictions as we will see later Enterprise JavaBeans Defined Enterprise JavaBeans defines a server component model for the development and deployment of Java applications based on a multi-tier, distributed object architecture. The Enterprise JavaBeans specification defines: A container model A definition of the services the container needs to provide to an Enterprise JavaBean, and vice versa How a container should manage Enterprise JavaBeans 7 8 Enterprise JavaBeans Architecture Enterprise JavaBeans Architecture The EJB architecture specifies the responsibilities and interactions among EJB entities: EJB Server EJB Container Enterprise Beans The EJB Bean is nothing more than a Java Class that implements one of the required EJB interfaces. This provides either the Business Logic or Data Access Logic. EJB Clients An EJB Client is any program, Java or not, which makes invocations on the EJB Server 9 10 1. EJB Server The EJB Server provides system services and manages resources Process and thread management System resources management Database connection pooling and caching Management API Provides a Runtime Environment The EJB Server (or Application Server as it is commonly known) is on its way to becoming an operating system Hosts the Enterprise JavaBeans Provides services to Enterprise JavaBeans Naming Life cycle management Persistence (state management) Transaction Management Security Likely provided by server vendor Provides a Run-time Environment for an Enterprise Bean 2. EJB Container 11 12 2

3. Enterprise Beans A specialized Java class where the real business logic lives Enterprise Java Beans may be: developer-written or tool-generated Distributed over a network Transactional Persistent Secure. EJB vendors provide tools that automatically generate distribution, transaction, persistence and security behavior. 4. EJB Clients Client access is controlled by the container in which the enterprise Bean is deployed via a Home Interface Clients locate an Enterprise JavaBean through a Java Naming and Directory Interface (JNDI) Registry RMI is the standard method for accessing a bean over a network CORBA clients can access a bean via an IIOP/RMI Bridge 13 14 Roles in EJB The subdivision of EJB development into different parts allows for the division of labour [A. Smith] Roles in EJB Client EJB Developer EJB Deployer Container Developer (Normally a Vendor) Portable Data XML Systems Portability Java is OS independent Application Server Portability Container API Servlets API Other J2EE APIs EJB Portability 15 16 EJB Supporting Technologies EJB is part of the Java 2 Enterprise Edition Specification (J2EE) J2EE also includes: Java Naming and Directory Interface (JNDI) Java Transaction API (JTA) Java Message Service API (JMS) The Object Bus (RMI & EJB-to-CORBA mapping) EJB Security Model See http://java.sun.com/j2ee/ for full details of the spec. Java Naming and Directory Interface (JNDI) JNDI is an API specification that is used to provide naming/directory services JNDI provides a common API on top of any directory service product Directory service products (LDAP, DNS, NDS, etc) implement most of the specification. JNDI is used by clients in conjunction with RMI and EJB to locate Enterprise JavaBeans on a server. 17 18 3

Java Naming and Directory Interface (JNDI) Client Clients accessing a Bean with JNDI Client Credential InitialContext Context Object EJBHome EJBContext EJBObject Authenticate(uname, passwd) Create a new Initial Context for use with JNDI EJBHome myhome = (EJBHome) ctx.lookup("...bn=myejb") EJBRemote mybean = myhome.create(...); create(context) Create or Clone 19 20 EJB Internals 21 22 EJB Class is written by the developer. EJB Internals EJBHome and EJBObject interfaces and classes control access to the Bean class. Deployment Descriptor and MANIFEST describe security and transactional characteristics of the Bean. EJBHome Interface and Class Used to get a reference to a bean s remote interface by creating or finding it. Must extend the class javax.ejb.ejbhome Provides bean creation services for clients myfoo = foohome.create() instead of myfoo = new foo() Supports multiple signatures to create EJB instances. Provides a bean removal interface also. The specialised EJBHome interface is written by the developer. The EJBHome Class implementation is generated by a tool. Also manages the bean: querying (Entity Bean) deleting (Entity Bean). 23 24 4

EJBObject Interface and Class A.k.a. the remote interface. The remote interface is written by the developer. Must extend the class javax.ejb.ejbobject The EJBObject Class implementation is generated by a tool. EJBObject class has the same methods as the bean and delegates to the bean for actual behavior. Intercepts calls to the EJB Class to add support for transactions, security & threading. EJBObject class checks security and sets up transaction before delegating method call to the bean. Clients can never get a reference to a bean s EJB Class, only the EJBObject interface. Clients accessing a Bean After the EJBHome Class instantiates the Bean... The EJBHome Class will instantiate the EJBObject Class, initializing it with the remote object reference to the Bean Class. The Client will now communicate to the EJBObject Class. The EJBObject Class will delegate the call to the Bean. Client now has reference to an instance of the EJBObject Class, not a reference to the bean itself! 25 26 Clients accessing a Bean EjbObject Interface EJBObject Class Passes Ref of Bean EJB Container EJB Class EJB Class A bean has a single Java class at its core This class is written by a developer if it s a session bean This class is sometimes generated by a tool if it s an entity bean Implements application-specific business logic. Implements one of the following contracts: javax.ejb.entitybean javax.ejb.sessionbean These contracts provide for consistent behavior when activating beans, passivating beans, reading data, writing data. Every container can expect these methods in every bean. EJB Server 27 28 EJB s Declarative Programming Model The EJB specification mandates a container model where common services are declared, not programmed At development and/or deployment time, attributes defining the bean s transaction and security characteristics are specified At deployment time, the container introspects the Enterprise JavaBean attributes for the runtime services it requires and wraps the bean with the required functionality At runtime, the container intercepts all calls to the object The container provides transactional, threading and security behaviour required before the method invocation. Invokes the method on the object Cleans up after the call Deployment Descriptor Allows you to declare transaction and security attributes, NO PROGRAMMING REQUIRED!!! An EJB Deployment Descriptor describes the classes, interfaces and declarative behavior of an EJB. The deployment descriptor is generated by server tools. The EJB Deployer fills in the XML deployment descriptor at deployment-time to define properties of the EJBean such as: JNDI name Define certain properties of bean methods Execution identity, type of transaction management, etc. Specify an Access Control List to be associated with the runtime environment of the EJBean 29 30 5

Generating Code with the Deployment Tool Write your Bean implementation Compile this Java source into Java bytecode Tool from the vendor is responsible for creating a serialized deployment descriptor for the bean EJB tools use the Reflection API on the compiled EJB Bean to determine: name of Bean class, methods, parameters, return values The EJB Tool uses the above information to generate a Deployment Descriptor file and an editor is used with which to declare attributes on different classes and methods EJB Tool generates an Empty Deployment Descriptor... Now the DEPLOYER can edit the transaction & security attributes for each individual method of the EJB Bean. The deployer DECLARES these attributes, there is no coding! Once the Deployment Descriptor is edited, the EJB Tools parse the file and generate the appropriate container code based on what is defined. All of the code is compiled and packed in the ejb-jar JAR file for distribution. 31 32 Container Services The EJB deployment tool generates code to handle: Security Naming Transactions Connection Pooling Thread Management Lifecycle Management Sample Deployment Descriptor PS(TicketDemo,Concert,deployment_descriptor) Entity{ VersionNumber { 1.0 } BeanHomeName { ConcertHome } ControlDescriptor { IsolationLevel { TRANSACTION_READ_COMMITTED } Method { int getid() throws java.rmi.remoteexception } RunAsMode { SYSTEM_IDENTITY } TransactionAttribute { TX_SUPPORTS } } } 33 34 EJBean Packaging Enterprise JavaBeans are comprised of many Java files These files are packaged in a JAR file A JAR file is a ZIP file with a MANIFEST that describes the contents of the file A MANIFEST is a simple text file Name: bank/accountdeployment.ser Enterprise-Bean: True A JAR file can contain more than one Enterprise JavaBean. Install Configure Execute I.C.E. Paradigm 35 36 6

Session Beans Stateful/Stateless The Bean Lifecycle Passing a Session Bean's Object Reference Accessing Environment Entries Entity Beans Persistence Shared Access Primary Key Primary Key Class Bean-Managed Persistence Container-Managed Persistence Two Types of EJBean 37 38 Session and Entity EJBeans Session and Entity EJBeans Session Bean Entity Bean Purpose Shared Access Performs a task for a client. May have one client. Represents a business entity object that exists in persistent storage. May be shared by multiple clients. Persistence Not persistent. When the client terminates its session bean is no longer available. Persistent. Even when the EJB container terminates, the entity state remains in a database. 39 40 Database Connections in EJB (Persistence) Coded Connections Logical name for DB JNDI!""#$% when obtaining the database connection When To Connect Long-term/Short-term connections Specifying Database Users and Passwords Container-Managed Connections Code Generated by Deployment Tool! Container-Managed Transactions Transaction Attributes Rolling-Back Transactions Synchronizing a Session Bean's Instance Variables Transactions in EJB Bean-Managed Transactions JDBC Transactions JTA Transactions Java Transaction API Invoke the JTA methods, which then call the lower-level JTS (Java Transaction Service) routines The J2EE SDK implements the transaction manager with the JTS. 41 42 7

Transactions in EJB Security Authentication In J2EE Users, Realms, and Groups are managed using realmtool, e.g. : realmtool&'!()*&+,-.$!*/&'.++&0%+"1!(2/ &'(3 %"4*&5,4*(- (5.*,' - (!, Authorisation Declare roles using EJB.jar file in the Deployment Tool or XML Descriptor In J2EE, using the Application Deployment Tool the administrator maps roles to J2EE users and groups 43 44 Common EJB Architectural Pattern Typical EJB E-Commerce Application 45 46 Bean Development Process Implement the EJB Class Specify the remote interface Specify the home interface Specify security and transactional characteristics using vendor tools or XML Descriptors Use vendor tools to generate supporting code and package components in EJB-jar files Iterate... See JBoss/Tomcat Introduction to EJBs Tutorial [with guest appearances by Ant and XDocLet] http://www.dsg.cs.tcd.ie/~dowlingj/teaching/ds/nds103/ Programming Restrictions for Enterprise Beans Enterprise beans make use of services provided by both the EJB container and the EJB (Application) Server. To avoid conflicts with these services, enterprise beans are restricted from performing certain operations: Managing or synchronizing threads Accessing files or directories with the 0.6.7(" package Using AWT functionality to display information or to accept information from a keyboard Listening on a socket, accepting connections on a socket, or using a socket for multicast Setting a socket factory used by 8,46,48"5#,*, 8"5#,*, or the stream handler factory used by the 9:; class Loading a native library 47 48 8

When do you need EJB's? If you really need any of: 2 Phase commit across multiple data sources method-level object security object distribution (especially shared logic for multiple client types) standard object-relational mapping capabilities See../other slides/ejb_arch for complex EJB architectures based on façade pattern command pattern You should look at EJB's but they're not right for every project 49 50 Critique of EJB Makes distributed systems programming easier and faster. Declarative programming. Separation of roles between developer and deployer of bean. Developer writes Java classes Deployer is a system administrator setting ACLs, etc Programming model is different to standard Java. Learning curve and restrictions. Not language independent. Performance hit. Not firewall friendly. References Ed Roman, Scott Ambler, and Tyler Jewel. Mastering Enterprise Java Beans, 2nd Edition, Wiley Computer Publishing, New York, 2002. TheServerSide.com, A J2EE Community, http://www.theserverside.com Java 2 Platform, Enterprise Edition (J2EE), http://java.sun.com/j2ee/ JBoss Tutorial : http://www.dsg.cs.tcd.ie/%7edowlingj/teaching/ds/tutorials/ejb/jboss_3_intro.htm 51 52 9