J2ee Introduction

  • Uploaded by: api-3829400
  • 0
  • 0
  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View J2ee Introduction as PDF for free.

More details

  • Words: 5,681
  • Pages: 130
J2EE

J2EE Objectives

To Understand the relevance and implication of J2EE, in the present day Eenabled business environment  To understand and appreciate the distinguishing characteristics of J2EE 



To understand the J2EE Application Programming Model



To understand the Components that makeup J2EE



To develop a simple J2EE application using various server-side Java Components To understand Web Application Servers as implementations of J2EE



J2EE Organisation 

Part-I





Current problems with enterprise-wide networked application environments Future needs What is J2EE? How J2EE meets the challenge? A taste of J2EE



Part-II





J2EE application programming model Components & component APIs – an in-depth look Interactions between the components A component-based development approach



Part-III Application Development with J2EE





Developing Servlets and JSPs Developing Enterprise JavaBeans (EJBs) Interactions between the components Architecting a simple J2EE application



Part-IV J2EE Web Application Servers



Implementing J2EE : Web application servers Features of Web application servers J2EE certification for Web application servers Future of J2EE

  

 

 

  

Introducing J2EE

Components of J2EE

J2EE Assumed knowledge

Basic understanding of Java language  Basic OOP concepts  Basic understanding of E-Commerce applications 

Introducing J2EE

Introducing J2EE Part-I Organization

    

Current problems with enterprise application environments Future needs What is J2EE ? How J2EE meets the challenge A taste of J2EE

Introducing J2EE

Current problems with enterprise application environments

Introducing J2EE Current problems with enterprise application environments

Presence of multiple hardware / operating system combinations combination

Unix / Solaris / Windows NT/Windows XP/ 2000 / Windows 95, 98 etc.

Introducing J2EE Current problems with enterprise application environments

Lack of serious OOP design and application architecture

PROCEDURAL PROGRAMS

OBJECTS

OBJECTS

OBJECTS

OBJECTS

OBJECTS

OBJECTS

Weak application programming models

Introducing J2EE Current problems with enterprise application environments

Minimal or no reuse of code

Less than 30% of the code is reused, currently

Introducing J2EE Current problems with enterprise application environments

Rigidity and Inflexibility

  

Lack of portability. Entire system becomes a huge and complex behemoth System more and more difficult to handle – as the business becomes more and more complex.

Introducing J2EE Current problems with enterprise application environments

Serious problems in integrated data flow Dept 2

Dept 1

DATA

Dept 4

 

Exchange of data across departments : a nightmare Exchange of data outside the enterprise : ruled out

Dept 3

Introducing J2EE Current problems with enterprise application environments

Back-end systems integration

 

Highly heterogeneous environment - Legacy systems, Relational Databases, ERP Implementations etc. Need to cope up with scattered enterprise information systems

Introducing J2EE

Future Needs

Introducing J2EE Future needs

Internationalization and Globalization

 

Business applications must meet the challenges imposed by distributed development environment Developers - and even applications may be distributed !

Introducing J2EE Future needs

Unique challenges of e-Business

 

Business must embrace the Internet and e-Commerce – not only for growth, but for very survival ! Need to face a whole new set of problems like Security , Scalability, Load-balancing , Fail-over , Availability

Introducing J2EE Future needs

Challenges of E-Commerce driven business

 

Businesses should rapidly adopt themselves to B2B transactions Otherwise, they will be left behind !

Introducing J2EE Future needs

Businesses need Rapid Application Development

 

Need to respond quickly and effectively in the dynamic market environments…. Competitor is just a click away!

Introducing J2EE Future needs

Businesses cannot spend heavily on Information Technology in the future

Need to develop quality solutions at competitive prices, in no time!

Introducing J2EE Future needs

Challenges in re-architecting systems for multi-tier application development

TIER 1

TIER 2

Can it ever be accomplished ?

TIER 3

Introducing J2EE Future needs

Need to have a standard environment and a common platform

Unified development efforts and co-ordination

Introducing J2EE Future needs

Relevant even to small and medium scale enterprises because of B2B transactions

Nobody can neglect

Introducing J2EE

What is J2EE?

Introducing J2EE What is J2EE?

Java 2 Platform, Enterprise Edition

An enterprise-level platform for developing portable, secure, scalable, distributed, multi-tier business applications with Java.

Introducing J2EE What is J2EE?

It is an application development platform

EJB CONTAINER CLIENTS

WEB CONTAINER

E IS

ENTERPRISE SERVICES

. . . with a rich set of server-side Java APIs

JSP Architecture Model 1 architecture

Model 2 architecture

Introducing J2EE What is J2EE?

It is an application programming model CLIENTS TIER External Clients from INTERNET (Browsers , WAP etc.) Applets

J2EE WEB APPLICATION SERVER TIER PRESENTATION BUSINESS LOGIC LOGIC (EJB Container )

BACK END TIER

(Web Components) SERVLETS

JSP

EJB

EJB

EJB

EJB

EJB

EJB

Enterprise Information Systems (Databases, ERP, Legacy Systems)

XML Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

ENTERPRISE SERVICES WML JDBC

JNDI

JMS

JTS

HTML RMI - IIOP

. . .describing how enterprise applications need to be built / structured

Introducing J2EE What is J2EE?

It is a standard middleware architecture

. . .for developing middleware web application services

Introducing J2EE

How J2EE meets the challenge

Introducing J2EE How J2EE meets the challenge

Hardware / OS Independent

   

Java is write once and run anywhere! The JVM is available for all platforms and OS Standardised environment for development & deployment Codes can be easily ported across multiple platforms

Introducing J2EE How J2EE meets the challenge

Adherence to OOP CLASS

CLASS

CLASS

CLASS

CLASS

CLASS

Java is a strictly Object-Oriented Programming language

Introducing J2EE How J2EE meets the challenge

Component-based development for code re-use

 

Entire application development as bits and pieces of independent components Self-contained modules and logic – ‘assembled’ business applications

Introducing J2EE How J2EE meets the challenge

Multi-tier application development J2EE WEB APPLICATION SERVER TIER

BUSINESS LOGIC (EJB Container )

CLIENTS TIER

BACK END TIER

PRESENTATION LOGIC (Web Components)

ENTERPRISE SERVICES

Clear demarcation of various tiers across the application-independent development environment

Introducing J2EE How J2EE meets the challenge

Distributed development & deployment made easy

 

Developers can work anywhere! Application components can be spread across the globe!

Introducing J2EE How J2EE meets the challenge

Flexible and portable solutions

 

Flexibility in developing and assembling solutions Portability of application components across J2EE platforms

Introducing J2EE How J2EE meets the challenge

Satisfying the essential requirements of E-Commerce web applications

Automatic load-balancing / scaling / fail-over

Introducing J2EE How J2EE meets the challenge

Back-end systems integration

 

Standardisation efforts by means of Connector architecture Support for IDL / CORBA

Introducing J2EE

A taste of J2EE

Introducing J2EE A taste of J2EE

J2EE as an application programming model

CLIENTS

       

PRESENTATION / BUSINESS LOGIC

BACKEND

Multi-tier thin client architecture MVC model architecture Client tier Presentation tier Business logic tier Enterprise Platform Services tier Back-end tier: Enterprise Information Systems Developing middleware Web Application Services

Introducing J2EE A taste of J2EE

J2EE – as a combination of various server-side technologies SERVLETS

JSP         

Java Servlets Java Server Pages (JSP) Enterprise JavaBeans (EJBs) EJB Java Database Connectivity (JDBC) Java Messaging Services (JMS) Java Naming and Directory Interface (JNDI) Java Transaction Services (JTS) JavaMail XML

JDBC

Introducing J2EE A taste of J2EE

J2EE – as the standard for web application servers

WEB APPLICATION SERVERS



Web application servers – implementations of J2EE reference infrastructure

Components of J2EE

Components of J2EE Organization

   

J2EE application programming model Components & component APIs – an in-depth look Interactions between the components A component- based development approach

Components of J2EE

SERVLETS

JSP J2EE Application Programming Model EJB

JDBC

Components of J2EE J2EE Application Programming Model J2EE WEB APPLICATION SERVER TIER

BUSINESS LOGIC CLIENT TIER

(EJB Container )

PRESENTATION LOGIC (Web Components)

ENTERPRISE SERVICES

J2EE application programming model

BACK END TIER

Components of J2EE J2EE Application Programming Model CLIENT TIER

J2EE WEB APPLICATION SERVER TIER

External Clients from INTERNET (Browsers , WAP etc.)

Applets

BUSINESS LOGIC (EJB Container )

PRESENTATION LOGIC

BACK END TIER

(Web Components)

Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

ENTERPRISE SERVICES

Client tier components

Components of J2EE J2EE Application Programming Model CLIENTS TIER

J2EE WEB APPLICATION SERVER TIER PRESENTATION LOGIC

External Clients from INTERNET (Browsers , WAP etc.)

(Web Components)

SERVLETS

Applets JSP

BUSINESS LOGIC (EJB Container )

BACK END TIER

XML

Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

WML

ENTERPRISE SERVICES HTML

Presentation logic components (or web components)

Components of J2EE J2EE Application Programming Model CLIENTS TIER

J2EE WEB APPLICATION SERVER TIER BUSINESS LOGIC

PRESENTATION LOGIC External Clients from INTERNET (Browsers , WAP etc.)

(EJB Container )

(Web Components)

SERVLETS

EJB

EJB

EJB

EJB

EJB

EJB

Applets JSP

XML

Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

WML

ENTERPRISE SERVICES HTML

Business logic components

BACK END TIER

Components of J2EE J2EE Application Programming Model CLIENTS TIER

J2EE WEB APPLICATION SERVER TIER BUSINESS LOGIC

PRESENTATION LOGIC External Clients from INTERNET (Browsers , WAP etc.)

BACK END TIER

(EJB Container )

(Web Components)

SERVLETS

EJB

EJB

EJB

EJB

EJB

EJB

Applets JSP

XML

Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

ENTERPRISE SERVICES WML JDBC

JNDI

JMS

HTML RMI - IIOP

Enterprise Service APIs

JTS

Components of J2EE J2EE Application Programming Model CLIENTS TIER

J2EE WEB APPLICATION SERVER TIER BUSINESS LOGIC

PRESENTATION LOGIC External Clients from INTERNET (Browsers , WAP etc.)

BACK END TIER

(EJB Container )

(Web Components)

SERVLETS

EJB

EJB

EJB

EJB

EJB

EJB

Applets JSP

Enterprise Information Systems (Databases, ERP, Legacy Systems)

XML

Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

ENTERPRISE SERVICES WML JDBC

JNDI

JMS

JTS

HTML RMI - IIOP

Enterprise Information Systems (Hosts)

Components of J2EE

Interactions between the Components

Components of J2EE Interactions between the Components CLIENTS TIER

J2EE WEB APPLICATION SERVER TIER BUSINESS LOGIC

PRESENTATION LOGIC External Clients from INTERNET (Browsers , WAP etc.)

BACK END TIER

(EJB Container )

(Web Components)

SERVLETS

EJB

EJB

EJB

EJB

EJB

EJB

Applets JSP

Enterprise Information Systems (Databases, ERP, Legacy Systems)

XML

Internal Clients from INTRANET (Browsers , Desk top Applications etc.) Applets, Javabeans

ENTERPRISE SERVICES WML JDBC

JNDI

JMS

JTS

HTML RMI - IIOP

Various interactions between the J2EE components

Components of J2EE SERVLETS

EJB

EJB

EJB

EJB

EJB

EJB

JSP

Components and Component APIs an in-depth look XML

JDBC

WML

HTML

JNDI

JMS

RMI - IIOP

JTS

Components of J2EE Components and Component APIs - an in-depth look

Java Servlets PRESENTATION LOGIC (Web Components)

SERVLETS

JSP HTTP Clients (Internal & External) XML

WML

HTML

   

Standard Java extensions to the basic web server framework. Provide additional functionality to the server / enable dynamic content creation. Programmers can extend Servlets for their applications. Servlets reside in Servlet engines.

Components of J2EE Components and Component APIs - an in-depth look

Java Server Pages (JSP) PRESENTATION LOGIC (Web Components)

SERVLETS

JSP HTTP Clients (Internal & External) XML

WML

HTML

Another set of server side Java APIs to enhance web server functionality  Collecting data / presenting processed results to the client  Java snippets can be embedded into normal HTML code  Closely linked interaction with JavaBeans API 

Components of J2EE Components and Component APIs - an in-depth look

Enterprise JavaBeans (EJB) BUSINESS LOGIC

PRESENTATION LOGIC

(EJB Container )

(Web Components)

SERVLETS

JSP

RMI

     

EJB

EJB

EJB

EJB

EJB

EJB

Scalable, distributed server-side Java components for encapsulating business logic Each EJB serves a specific set of well-defined business tasks. EJBs reside in EJB containers, which are an integral part of vendor’s J2EE implementation and provide crucial system-level services All EJBs should be coded to standard EJB API specifications. Types of EJBs: Stateful Session EJBs, Stateless Session EJBs, Entity EJBs etc. Different types of EJB will be introduced in the future

Components of J2EE Components and Component APIs - an in-depth look

Java Database Connectivity (JDBC) SERVLETS

Informix

EJB

JDBC API

JDBC Driver/ DB API

Oracle

Other Java Classes

 

Standard Java API for connecting to various databases “Hides” the database from the eyes of the program

SQL Server

Components of J2EE Components and Component APIs - an in-depth look

Java Naming and Directory Interface (JNDI)

LDAP Server

SERVLETS

JSP

JNDI API / NAMING MANAGER/ SERVICE PROVIDER INTERFACE

LDAP / File System / DNS / Drivers

RMI



Standard Java API for distributed lookup services

File System

DNS Server

Components of J2EE Components and Component APIs - an in-depth look

Java Messaging Services (JMS) Transmission M

M

M

JMS API

Reception



M

M

M

Standard Java API for Enterprise Messaging Systems

Enterprise Messaging System

Components of J2EE Components and Component APIs - an in-depth look

Java Transaction API (JTA)

JDBC API

EJB

JTA

Transaction Monitor

Other Transactional Classes



Standard Java API for Distributed Transaction Services

Components of J2EE Components and Component APIs - an in-depth look

JavaMail API / JAF



Standard Java API for Mail Server Services (SMTP / IMAP)

Components of J2EE Components and Component APIs - an in-depth look

Java RMI / IIOP / IDL

RMI is a Java API for object-to-object communication between different java Virtual Machines (JVM)  RMI over Internet Inter-Orb Protocol (RMI-IIOP) integrates CORBA-compliant distributed computing directly into Java 

Components of J2EE

EJB

EJB

EJB

A component-based development approach EJB

EJB

Components of J2EE A component-based development approach

Pluggable Architecture

Required components can be ‘plugged in’ and ‘plugged out’

Components of J2EE A component-based development approach

Generic components vs. application specific components

SERVLETS EJB

EJB

Generic Utilities EJB JSP

  

Components that have relevance beyond the scope of the project EJBs should be generic – Servlets / JSPs can be specific Logic libraries (Packages) should be generic

Components of J2EE A component-based development approach

Identifying the right deployment parameters

  

Directory names and URLs Database parameters – table names, database URL etc. Application specific parameters

Application Development with J2EE

Application Development with J2EE Organization

   

Developing Servlets & JSPs Developing Enterprise JavaBeans (EJBs) Interactions between the components Architecting a simple J2EE application

Application Development with J2EE

SERVLETS

JSP

Developing Servlets and JSPs

Application Development with J2EE Developing Servlets and JSPs

Servlets - Core Concepts

SERVLETS

     

Server side Java Classes, that reside in J2EE Presentation Logic Tier Servlets are based on Request – Response models All Servlets extend javax.servlet.Servlet Interface. Most of the application Servlets extend javax.servlet.http.HttpServlet class ServletRequest and ServletResponse objects enable interaction with the clients Instantiate EJBs for business data processing

Application Development with J2EE Developing Servlets and JSPs

Servlets - Lifecycle Does Not Exist









In the event of a timeout or web server shutdown, Servlet’s destroy() method is called Java Virtual Machine does the garbage collection- finalize() method is called

Business tasks are performed through the service() methods



Servlet Engine instantiates and loads the Servlet - either during startup or first request call Initialisation performed through init() method - only once throughout the life of Servlet

Servlet Instance



Servlet threads are created for multiple requests. All threads use same Servlet instance.

Application Development with J2EE Developing Servlets and JSPs

Servlets - A simple example import javax.servlet.*; import javax.servlet.http.*; public class SimpleServlet extends HttpServlet { public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); out.println(""); out.println("Simple Servlet"); out.println(""); out.println("

Hello J2EE !

"); out.println(""); } }

Application Development with J2EE Developing Servlets and JSPs

JSPs - Core Concepts

JSP

      

Server-side Java code that resides in J2EE presentation logic tier JSPs are based on Request – Response models Contain HTML code for presenting information, plus directives and scriplets for processing. JSPs interact with Servlets and JavaBeans Internally JSPs are no different from Servlets Dynamically compiled – unlike Servlets Can instantiate EJBs – but not advised to do so.

Application Development with J2EE Developing Servlets and JSPs

JSP - Lifecycle Does Not Exist





In the event of a timeout or web server shutdown, jspDestroy() method is called

 



Business tasks are performed through the _jspService() methods

JSP Engine dynamically complies the JSP page as a servlet class JSP Engine instantiates and loads the class - during the first request call Initialisation performed through jspInit() method - only once throughout the life of JSP

JSP Instance



Threads are created for multiple requests. All threads share the same instance.

Application Development with J2EE Developing Servlets and JSPs

JSP - A simple example <%! String a = “hai”; String b = “hai J2ee”; %>

Current Date

Today’s date is : <%= new Date().toString() %> <% if (a.equalsIgnoreCase(b)) { %> A is equal to B <% } %>

Application Development with J2EE Developing Servlets and JSPs

A Simple JavaBean public class Presentation { //attributes protected String session; protected String speaker; protected int duration_hours; //constructor method public Presentation () { this.session = “J2EE Tutorial”; this.speaker = “S.Gokul”; this.duration_hours = 4; } //Accessor Methods public String getSession() {…} public void setSession() {…} ……… }

Application Development with J2EE

EJB

EJB

EJB

EJB

EJB

EJB

Developing Enterprise JavaBeans

Application Development with J2EE Developing Enterprise JavaBeans

EJB : Core Concepts EJB       

Server side distributed, load balanced, scalable business logic components, that reside in the business logic tier Built on the top of Java RMI specification for distributed computing EJB Container manages EJBs – pooling, distribution, creation, activation etc. Three types of EJBs : Stateless Session, Stateful Session and Entity EJBs Each EJB Contains at least 3 user-defined classes and a number of Container classes. Home Interface – meant for EJB creation; Remote Interface - meant for using business logic; Bean Class – actual implementation details. Clients can access EJBs only through interfaces. Containers manage the implementation.

Application Development with J2EE Developing Enterprise JavaBeans

EJB : Breathing to Life JNDI

CLIENT

Home Stub obtained ejbCreate () from

from JNDI

EJB CONTAINER Home stub deployed during startup

Home stub reference Create EJB Instance Create Remote stub & Skeleton

Return the remote

stub reference

Invoke business methods through the remote stub reference Process data Return Results

Application Development with J2EE Developing Enterprise JavaBeans

EJB : Breathing to Life

       

EJB Containers manage the enterprise bean life cycle For each EJB in the system, a home stub is deployed into JNDI – during the application server startup Clients download a copy of the home stub, to create an EJB instance in the server. Upon this request, EJB container creates an EJB instance, gives it state and associates a client context to it. It also creates a remote skeleton and a remote stub The remote stub is returned by the home skeleton Client invokes business methods, through remote stub All clients get identical home stubs, but unique remote stubs !

Application Development with J2EE Developing Enterprise JavaBeans

Stateless Session EJBs

EJB

    

Provide a well-defined set of business services to the client Do not maintain state on the behalf of client and hence, do not have attributes. Do not survive EJB Container crashes. All Stateless EJB instances are identical – and can be reused. Less resource hungry – ideal for clustered environment.

Application Development with J2EE Developing Enterprise JavaBeans

Stateful Session EJBs

EJB

     

Provide business services and maintain state on behalf of client. Stores the state as attribute, for temporary usage. Do not survive EJB Container crashes. Every Stateful EJB instance is unique & tied to the client – hence, they cannot be reused. Lifetime is determined by the client. More resource hungry – should be avoided in a clustered environment.

Application Development with J2EE Developing Enterprise JavaBeans

Entity EJBs

EJB

     

Retrieve and store information from the database Represent persistent business data – every record in the table, is an entity bean (single table model) They survive EJB Container crashes Multiple clients may use the same EJB - that represents the same set of data – but they are not same Entity instances ! State of entity bean is persisted in the storage (file or database). Resource hungry - most useful for transactions.

Application Development with J2EE

PRESENTATION LOGIC (Web Components) SERVLETS

JSP

RMI

BUSINESS LOGIC (EJB Container ) EJB

EJB

EJB

EJB

EJB

EJB

Interactions between the Components

Application Development with J2EE Interactions between the Components Presentation Logic BROWSER

SERVLET

Business Logic

JNDI

JSP

Request Home Stub obtained ejbCreate () from

from JNDI

EJB CONTAINER Home stub deployed during startup

Home stub reference Create EJB Instance Create Remote stub & Skeleton

Return the remote

stub reference

Invoke business methods through the remote stub reference Process data Return Results

RESPONSE Response

Forward Response with Results

Application Development with J2EE Interactions between the Components

A Typical Interaction Scenario

      

The necessary EJBs / Servlets and JSPs are developed and deployed in the J2EE server Server is started A client request hits a Servlet Servlet gathers / validates the input data, creates an EJB and forwards the data to EJB for processing EJB processes the data by applying business rules / interacting with the database, and responds with the processed results. Servlet gathers the response and forwards to a JSP appropriately. JSP loads the response HTML page to the client.

Application Development with J2EE

Architecting a simple J2EE Application

Application Development with J2EE Architecting a simple J2EE Application

Application Sequence Presentation Logic BROWSER

SERVLET

Request : Collect User name and Password

Business Logic

JNDI

JSP

Authenticate EJB Home Stub obtained from JNDI

EJB CONTAINER Home stub deployed during startup

ejbCreate () from Home stub reference

Return the remote stub reference

Create Authenticate EJB Instance Create Remote stub & Skeleton

Verify Username and Password (Business method) Process data Return Results (True or False)

RESPONSE Response

Forward Response with Results

Userdata EJB Home Stub obtained from JNDI

Application Development with J2EE Architecting a simple J2EE Application

Application Sequence

      

The Request from HTTP client hits the Servlet Username and password are collected from the Request object The Authenticate stateless session EJB is initialised Username and password are passed to this EJB for verification This EJB returns True if the user details are correct If the details are not correct, inform the user accordingly If the details are correct, create / findbyPrimaryKey - an Entity EJB called Userdata with Username and Password as keys

Application Development with J2EE Architecting a simple J2EE Application

Table Details

NAME LOGINNAME PASSWORD EMAIL AGE SERVICE

Application Development with J2EE Architecting a simple J2EE Application

Servlet Code package portal; import java.io.*; import java.sql.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import java.net.URL; import javax.ejb.*; import javax.naming.*; public class login extends HttpServlet { static String url = "http://17.252.11.139:7001"; static String connection_pool = ""; static String user = “guest”; public void init()throws ServletException{ String connection_pool = "oraclepool"; }

Application Development with J2EE Architecting a simple J2EE Application

Servlet Code (Cont..)

public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{ //ACCPET THE FORM VARIABLES AS STRINGS FROM HTML String login = req.getParameter("login"); if (login == null) login = ""; else login = login.trim(); String password = req.getParameter("password"); if (password == null) password = ""; else password = password.trim(); //INITIALISING RESPONSE WRITER res.setContentType("text/html"); PrintWriter out = res.getWriter(); boolean result = false;

Application Development with J2EE Architecting a simple J2EE Application

Servlet Code (Cont..)

//THIS BLOCK IS INSIDE THE SERVICE METHOD try{ Context ctx = getInitialContext(); AuthenticateHome home = (AuthenticateHome) ctx.lookup("Authenticate");

Authenticate session_ejb = home.create(); result = session_ejb.check_authentication(login, password); //System.out.println(”session ejb = " + session_ejb.toString());

session_ejb.remove(); } catch (Exception e){ e.printStackTrace(); }

Application Development with J2EE Architecting a simple J2EE Application

Servlet Code (Cont..)

//SEPARATE METHOD - NOT INSIDE THE SERVICE BLOCK public static Context getInitialContext() throws NamingException{ Properties p = new Properties(); p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFac tory");

p.put(Context.PROVIDER_URL, url); if (user != null) { p.put(Context.SECURITY_PRINCIPAL, user); if (password == null) password = ""; p.put(Context.SECURITY_CREDENTIALS, password); } return new InitialContext(p); }

Application Development with J2EE Architecting a simple J2EE Application

Servlet Code (Cont..) //THIS BLOCK IS INSIDE THE SERVICE METHOD if (result){ try{ Context ctx = getInitialContext(); UserdataHome home = (UserdataHome) ctx.lookup(”Userdata");

Userdata entity_ejb = home.create(login, password); //...

} catch (Exception e){ e.printStackTrace(); }

Application Development with J2EE Architecting a simple J2EE Application

Authenticate Stateless Session EJB

//HOME INTERFACE CODE (AuthenticateHome.java) package portal; import javax.ejb.*; import java.rmi.RemoteException; public interface AuthenticateHome extends EJBHome { //CREATE METHOD TO BE IMPLEMENTED IN BEAN CODE public Authenticate create() throws CreateException, RemoteException; }

Application Development with J2EE Architecting a simple J2EE Application

Authenticate Stateless Session EJB (Cont..)

//REMOTE INTERFACE CODE (Authenticate.java) package portal; import javax.ejb.*; import java.rmi.RemoteException; public interface Authenticate extends EJBObject { //BUSINESS METHODS TO BE IMPLEMENTED IN BEAN CODE public boolean check_authentication(String username, String password)throws RemoteException; }

Application Development with J2EE Architecting a simple J2EE Application

Authenticate Stateless Session EJB (Cont..)

//BEAN CODE (AuthenticateEJB.java) package portal; import javax.ejb.*; import java.util.*; import javax.naming.*; import java.io.*; import java.sql.*;

public class AuthenticateEJB implements javax.ejb.SessionBean{ private SessionContext ctx; public AuthenticateEJB(){ } // SessionBean interface implementation public void ejbActivate(){ } public void ejbPassivate(){ } public void ejbRemove(){ }

Application Development with J2EE Architecting a simple J2EE Application

Authenticate Stateless Session EJB (Cont..)

public void setSessionContext(SessionContext ctx){ this.ctx = ctx; } // create methods public void ejbCreate(){ } // business methods public boolean check_authentication(String username, String password){ boolean result = false; username = username.toUpperCase(); password = password.toUpperCase(); Connection con = null; Statement stmt = null;

Application Development with J2EE Architecting a simple J2EE Application

Authenticate Stateless Session EJB (Cont..) //check_authentication method Block try{ Class.forName("weblogic.jdbc.pool.Driver").newInstance(); con = DriverManager.getConnection("jdbc:weblogic:pool:oraclepool", null);

DatabaseMetaData dma = con.getMetaData (); System.out.println("\nConnected to " + dma.getURL()); System.out.println("\nDriver " + dma.getDriverName()); stmt = con.createStatement(); String querry = "SELECT * FROM USERDATA WHERE UPPER(LOGINNAME) = '" + username + "' AND UPPER(PASSWORD) = '" + password +"'"; ResultSet rs =stmt.executeQuery(querry); //WHEN THERE IS ATLEAST ONE RECORD RETRIEVED, USER IS VALID while(rs.next()){ result = true; } } catch (SQLException exception){

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB

//HOME INTERFACE CODE (UserdataHome.java) package portal; import javax.ejb.EJBHome; import javax.ejb.FinderException; import java.rmi.RemoteException; import javax.ejb.CreateException; public interface UserdataHome extends EJBHome{ public Userdata create(String loginname, String password) throws CreateException, RemoteException; public Userdata findByPrimaryKey(UserdataPK key) throws FinderException, RemoteException; public Userdata findByLoginName(String loginname) throws FinderException, RemoteException; }

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB (Cont..)

REMOTE INTERFACE CODE (Userdata.java) package portal; import javax.ejb.EJBObject; import java.rmi.RemoteException; public interface Userdata extends EJBObject{ public void setService(String service) throws RemoteException; public String getService() throws RemoteException; public String getUserEmail() throws RemoteException; public String getUserName() throws RemoteException; }

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB (Cont..)

//PRIMARY KEY CLASS (UserdataPK.java) package portal; import java.io.Serializable; public class UserdataPK implements Serializable{ public String loginname; public boolean equals(Object that) { // SBgen: Compare members return(this == that); // SBgen: End compare } }

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB (Cont..) //BEAN CODE (UserdataEJB.java) package portal; import javax.ejb.EntityBean; import javax.ejb.EntityContext; import javax.ejb.CreateException; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; public class UserdataEJB implements EntityBean{ private EntityContext context; public String loginname;/** USERDATA.LOGINNAME */ public String password;/** USERDATA.PASSWORD */ public String name;/** USERDATA.NAME */ public String email;/** USERDATA.EMAIL */ public int age;/** USERDATA.AGE */ public String service;/** USERDATA.SERVICE */

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB (Cont..) //BEAN CODE (UserdataEJB.java) public void setEntityContext(EntityContext ec){ context = ec; } public void unsetEntityContext(){ this.context = null; } public void ejbActivate(){ } public void ejbPassivate(){ } public void ejbLoad(){ } public void ejbStore(){ }

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB (Cont..)

//BEAN CODE (UserdataEJB.java) public UserdataPK ejbCreate(String loginname) { this.loginname = loginname; return null; } public void ejbPostCreate(String loginname) { } public void ejbRemove() { } public UserdataPK ejbCreate(String loginname, String password)throws CreateException { this.password = password; return ejbCreate(loginname); } public void ejbPostCreate(String loginname, String password) { }

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB

//BEAN CODE (UserdataEJB.java) public void setService(String service) { this.service = service; } public String getService() { return this.service; } public String getUserEmail() { return this.email; } public String getUserName() { return this.name; } }

Application Development with J2EE Architecting a simple J2EE Application

Userdata Entity EJB

//BEAN CODE (UserdataEJB.java) protected String getPrimarykey() { java.lang.String prop = null; try { Context initial = new InitialContext(); Context environment = (Context) initial.lookup("java:comp/env");

prop = (java.lang.String) environment.lookup("primarykey"); } catch (NamingException e) { } return prop; }

Web Application Servers

Web Application Servers Organization

WEB APPLICATION SERVER

   

Implementing J2EE : web application servers Features of web application servers J2EE Certification of application servers Future of J2EE

Web Application Servers

SERVLETS

JSP

WEB APPLICATION SERVER

EJB

EJB

Implementing J2EE Web Application Servers

Web Application Servers Implementing J2EE - Web Application Servers

Web Application Servers - Definition

WEB APPLICATION SERVER

Forrester Research defines an application server as “a software server product that supports thin clients with an integrated suite of distributed computing capabilities. Application servers manage client sessions, host business logic and connect to back-end computing resources,including data,transactions, and content.”

Web Application Servers Implementing J2EE - Web Application Servers

What can Web Application Servers do for you ? WEB APPLICATION SERVER

    

Single robust platform to develop and deploy all enterprise / web applications. Support a variety of components – to cater to various business needs Independent of platform / OS and are capable of connecting together a heterogeneous mix of back-end systems. Can cluster a host of server instances and treat them as a single pool of resources – ensuring total availability Can service and monitor sensitive database transactions and allow for increased security and control.

Web Application Servers Implementing J2EE - Web Application Servers

What Web Application Servers can do for you ? (Cont..) WEB APPLICATION SERVER

   



Allow us to exercise more control over the overall flow of applications – caching, pooling and load balancing. Provide efficient remote administration capabilities for the enterprise system architecture. Capable of scaling to meet the increasing net traffic. Provide more flexibility and openness in the overall enterprise system architecture – every end resource can be virtually ‘plugged in’ or ‘plugged out’ of a single backbone. Increase the overall system performance – enterprise resources are routed through a single gateway.

Web Application Servers Implementing J2EE - Web Application Servers

Looking at J2EE Web Application Servers

WEB APPLICATION SERVER

  

Vendor-specific implementations of J2EE infrastructure Features and performance distinguish the products Almost all products are J2EE-based / J2EE-compliant

Web Application Servers Implementing J2EE - Web Application Servers

Developing Applications with Web Application Servers

  

Integrated development environments Development and deployment of EJBs / Servlets / JSPs Example : BEA’s Webgain Studio with Visual Café, Dreamweaver, Weblogic and Structure Builder

Web Application Servers

???

Wow ! WEB APPLICATION SERVER

!!!!

@#$%!

Features of Web Application Servers

Web Application Servers Features of Web Application Servers

Performance-based Features

   

Scalability and availability – capacity to meet the increasing number of client requests Load balancing – ability to distribute requests evenly across multiple resources Fail-over and fault tolerance – coping up with software / hardware crashes Response time – ability to attend to the client’s request as early as possible.

Web Application Servers Features of Web Application Servers

Application Development Features

  

Tools and IDE support – overall application development environment Ease of use and development – overall skill set required for development Platform Support – compatibility across multiple hardware / OS configurations

Web Application Servers Features of Web Application Servers

Technical Features

WEB APPLICATION SERVER

  

Open architecture – ability to accommodate multiple standards and components Back-end integration - ability to integrate with existing EIS Web server support – major HTTP web servers supported by the product

Web Application Servers Features of Web Application Servers

Administrative Features

   

Administration and Manageability – how easy is it to maintain the overall system ? Site monitoring / analysis and report generation Security management – user governance, requests logging, firewall / SSL support Transaction monitoring – ability to be a database watchdog

Web Application Servers Features of Web Application Servers

Miscellaneous Features

 

Availability of local technical support Pricing

Web Application Servers

J2EE Certification of Web Application Servers

Web Application Servers J2EE Certification of Web Application Servers

How to distinguish Web Application Servers ? ???

 

Sun Microsystems’ J2EE Compliance Test and Compatibility Test suite J2EE-branded server must pass more than 6,000 tests in the Compatibility Test suite.

Web Application Servers J2EE Certification of Web Application Servers

Some premier Web Application Servers

      

BEA’s WebLogic server Allaire’s Jrun Bluestone’s Sapphire (Total-e-server) i-Planet application server Oracle ‘s 9i application server Silverstream Ebusiness platform IBM’s Web Sphere

Web Application Servers

Future of J2EE

Web Application Servers Future of J2EE

Future Development Paths

 

tomcat@jakarta : Is it here to stay ? New Draft : Connector Architecture / Messaging beans etc.

Web Application Servers Future of J2EE

Web Application Servers of the Future

WEB APPLICATION SERVER

 

Move towards J2EE Jini / Javaspaces and other related technologies will have an influence

J2EE Tutorial RECAP 

Introducing J2EE





Current problems with enterprise-wide networked application environments Future needs What is J2EE? How J2EE meets the challenge? A taste of J2EE



Components of J2EE





J2EE application programming model Components & component APIs – an in-depth look Interactions between the components A component-based development approach



Application Development with J2EE





Developing Servlets and JSPs Developing Enterprise JavaBeans (EJBs) Interactions between the components Architecting a simple J2EE application



J2EE Web Application Servers



Implementing J2EE : Web application servers Features of Web application servers J2EE certification for Web application servers Future of J2EE

  

 

 

  

Related Documents

J2ee Introduction
November 2019 4
J2ee
November 2019 24
J2ee
December 2019 25
J2ee
November 2019 24
01 An Introduction To J2ee
November 2019 23