J2EEcourses.daiict.ac.in/.../content/0/IT556_SOC/lecture_notes/J2EE.pdf · Java 2 Platform,...
Transcript of J2EEcourses.daiict.ac.in/.../content/0/IT556_SOC/lecture_notes/J2EE.pdf · Java 2 Platform,...
J2EE
What now?
• At this point, you understand how to design servers and how to design clients
• Where do you draw the line?• What are issues in complex enterprise
platform?• How many servers?• How many forms of client?
Problems in Scaling an Application Client
• communication overhead• delay in accessing servers• issues of priority and fairness• synchronization• running on different platforms
– based on USER needs
Problems in Scaling an Application Server
• need for independence from client• variety of client demands• scalability• transparency to client• hardware based on
– performance– infrastructure needs
Problems in Scaling an Enterprise System
• transaction service (commit/rollback)• security• load balancing• thread management• persistence• middleware• accounting and logging• migrating from legacy systems
Defining J2EE
• The Java 2 Platform, Enterprise Edition (J2EE) specification describe a services-based application architecture within which transactional, scalable, secure, portable Javacomponents can be deployed and redeployed.
Assumption• Goal is to design enterprise-oriented Java
applications that can be deployed on multiple platforms– Transactions (DB updates)– Security (users must be authorized)– Scalability (able to handle very large number of potential &
simultaneous users)– Reliable (able to withstand planned and unplanned
component failures)
Java 2 Enterprise Edition (J2EE)
Building Distributed Applications was Difficult
• Need to support: Transactions, resource-pooling, security, threading, persistence, life-cycle, etc…
• System programming at the expense of business logic
• Developers had to become specialists• Proprietary APIs resulted in non-portable
code
Java 2 Platform, Enterprise Edition (J2EE)
• J2EE defines an ARCHITECTURE for developing complex, distributed java applications
• Consists of:– Design guidelines for developing enterprise
applications using J2EE– A reference implementation to provide an operational
view of J2EE– A compatibility test suite for compliance testing of
third party products– Several APIs (Application Programming Interfaces)– Technologies to simplify enterprise Java Development
J2EE Application Server• The Application server handles all system level
programming– Security
• Authorization• Authentication
– Transactions– Threading– Object life time management– Caching– Object persistence– Database Connection pooling
A Typical J2EE Server
Security
Development and
DeploymentOperations, Administration
and Management
Application Server
Integration
Portal
Several Clients one System
J2SE J2EE
J2SE and J2EE
Basic libraries for java development
I/oGUIsappletsetc
Based on J2SECan UTILIZE EJB Uses other technologiesDefines a SpecificationComponents are constrained
to abide by interfacespecs if they abide J2EE
Changes in J2EE 1.3 Specification
• New Container managed Persistence Model• Support for Message Driven Beans• Support for Enterprise Local Beans• Finally, J2EE1.3 requires Support for
J2SE1.3
Changes in J2EE 1.4 Specification
• Support for Web Services• JAX-RPC and SAAJ APIs provide the basic
web services interoperability support• JAXR API support access to registries and
repositories• JMX API supports J2EE Management API
Benefits of the J2EE ApproachAllows developers to develop systems without
regard of – the operating system or hardware technology
platforms (platform independence)– The application server software that will be
used to implement (execute) the business system (application independence)
– The physical locations from which the business system will be accessed (location transparency)
Benefits of the J2EE Approach• Allows developers to specify the resources a
business system will employ and set specific levels for these resources without having to write elaborate lines of code to achieve this (attribute based programming):– Example: developers can specify:
• Security levels for different users of the system• How business system will connect to database and access data,
access remotely located objects, manage transactions, intercommunicate with other component, etc
• Allows for Higher productivity of systems development team (cost-effective, rapid, re-use of pre-built components
Benefits of the J2EE Approach
• Facilitates componentization in many ways:– J2EE offers a well thought-out approach of separating
the development aspects of a component from its assembly specifics
– J2EE offers a wide range of APIs that can be used for accessing and integrating products from third-party vendors, creating a market for software components
– J2EE offers function-specific or highly specialized components optimized for specific types of roles
J2EE Communication as Tiers
The Container Concept– A Container is a software entity that runs
within the server and is responsible for providing the execution environment for J2EE components
– A Container also manage the life-cycle of components deployed within it.
– The container is responsible for resource-pooling, enforcing security, and enforcing transaction management requirements
J2EE Containers
• Before a component can be executed, it must be assembled into a J2EE application and deployed into its container
EJB Container
• A container is provided by the Application Servervendor to provide basic services that are required by J2EE specification.
• An EJB programmer places their code here, and is assured a variety of basic services are available
• EJBs are fundamental links between presentation components (web tier) and business critical data and systems (EIS tier).
EJB Container
Business Tier in EJB Container
Basic Services Supplied by the EJB Container
• Security• Transaction management• Remote client connectivity• Life cycle management• Database connection pooling
Web Container
• Services supported by the web container– HTTP– JSP– Servlets
Web tier in web container Web Tier components runs on EJBServer under Web Container. Web Container provides web componentsnaming context & Life-cycle management.
Application client component container
• User interface allowing interaction with business logic
• Examples– Applications/Applets– Servlets/JSP– Web Browsers (HTML/XML)– Others
Client Tier at Client Component Container
J2EE Components
• Server-side components– Enterprise JavaBeans (EJBs)– Java Servlets– JavaServer Pages (JSPs)
• Client-side components– Application client
• Configured via deployment descriptors• Deployed into containers
J2EE Components in J2EE Container
J2EE Standard APIs
• JDBC• Java Naming and Directory Interface (JNDI)• Java Message Service (JMS)• Remote Method Invocation (RMI)• Enterprise JavaBeans (EJBs)• Technologies
– Servlets– JavaServer Pages (JSPs)
Other J2EE APIs
• J2EE Connectors• Java Transaction API (JTA)• JavaIDL• RMI-IIOP• Java Transaction Service (JTS)• JavaMail
Development Roles
• Roles allow developer to concentrate on areas of expertise
• Roles:– J2EE Product Provider– Tool Provider– Application Component Provider– Application Assembler– Deployer– System Administrator
Mapping of J2EE Development Roles
EJB provider
Application assembler
Deployer
EJB container provider
EJB server provider
development
Enterprise Bean (EJB)
Application
Container
Server
deployment andexecution
System administrator
Administration tools
Servlets
• Used to provide an effective mechanism for interaction between the server-based business logic and web-based clients
• Functions:– Process requests– Create replies
• Deployed into a Web container, which– Manages servlet life cycle– Maps URLs to servlets– Converts HTTP requests and responses to objects
Request/Response flow for a servlet call
Servlet Example• A simple servletpublic class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException{
response.setContentType("text/html");PrintWriter out = response.getWriter();out.println(“<html><head><title>hello</title></head> ");out.println(<body><h1>Hello</h1></body></html>);
}
Java Server Pages
• JSP is a document that contains two types of text– Template data (HTML, XML, WML) that generates
static content– JSP elements that generate dynamic content
• Delegates dynamic processing to EJBs, JavaBeans components, custom tags
• Translates into and executes as a servlet• JSPs run in a web container hosted on a web-
server
JSP Invocation
JSP Elements
• Directive controls translation into servlet class– <%@ page import=“java.io.*” %>
• Declaration creates object or method– <%! int i %>
• Scriptlet for dynamic processing– <% ArrayList accts =
beanManager.getAcountController().getAccountsOfCustomer(request.getRemoteUser()); %>
JSP: JavaBeans Components
• Create components and access their properties– <jsp:useBean id=“accountHistBean”
class=“AccountHistorybean” scope=“request”/>scope: page, request, session, or application
– <jsp:setProperty name=“accountHistbean”property=“beanManager” value=“<%= beanManager%>” />value can be a String or a JSP expression
– <jsp:getProperty name=“accountHistBean”property=“credits” />
JavaBeans
• JavaBeans are the Java component architecture that allows components to interact using properties, setters and getters, and events.
• The power behind this concept is that theseJavaBeans can be built now and reused again later. EJBs are an extension of this principle. They have their own architecture and rules and can be built with JavaBeans if you choose.
JavaBeans
• Enterprise JavaBeans extend the JavaBean concept to Java server-side component architecture.
• JavaBeans contain components, which are reusable software building blocks with defined interfaces that work with other JavaBeancomponents to produce a custom application. This component technology found with JavaBeanspromises a world in which customized business solutions can be assembled rapidly from a set of software components.
JavaBeans
• JavaBeans are developed to act and run a certain way. They can be on the client or on the server. Because the JavaBeancomponents are simple and have limited functionality, the beans may not cover all the actions needed by the enterprise. It will take a programmer lots of development time to write new code for the extra functions a bean would require such as accessibility, lifecycle management, transaction management, and security. Or, we can add functionality another way.
JavaBeans
• How can we extend JavaBeans? We can use connector beans! Now, if we need more functions, we can CONNECT to the server and use the functionality of the larger, more complicated connector bean.
• At this point, there's a lot on the client; that's why we call it a "fat" client. The server connector beans can connect to other servers or use little JavaBeans on the server. But we know there are problems with fat clients. You need complicated application administration. That's why there's a trend toward network computing.
EJB
• With EJBs, you move the business and data manipulation logic to the second tier server. In doing so, you allow applications to take advantage of the power of high-end, multi-threaded, and multi-processing systems. Server components can pool and share scarce resources.
• As system demands increase, you can distribute highly active components across multiple servers. With modern multi-tiered systems, partitioning or replicating data among distributed servers brings some relief from common bottlenecks.
EJB
• In a thin-client application, you deploy very little or no application code on the client systems. You install most of the application on servers. You can administer fixes, upgrades, and extensions, as well as new versions, through a centralized management environment.
• The EJB model even supports transparent downloading of the client part of an application at start-up time. With EJBs, you not only increase reliability, but you also enable stricter security policies through the server.
Enterprise Java Beans
– Component for EJB technology– Runs on the server– Encapsulates business logic– Portable– Reusable– Transactional
Type of Enterprise Beans
• Enterprise JavaBeans aren’t JavaBeans• Session Beans
– Stateful– Stateless
• Entity Beans– Bean Managed Persistence– Container Managed Persistence
• Message Beans
EIS Layer
• This is where you keep the data that is integral to your system
• Examples– Database– ERP Software – Other Legacy Applications
Session Bean
• Executes on behalf of a single client• Can be Transaction Aware• Does not represent data in the Database,
although it may access and update• Relatively Short Lived , removed or lost as
EJB container crashes• Classified into: Stateless and Stateful
Stateful vs. Stateless Session Beans
• StatefulI. Possess Internal State II. Can live during
subsequent method callIII. One per client
IV. Need to handle activation/ passivation
• StatelessI. Do not possess stateII. Can live during a
method callIII. Can be pooled to
handle multiple clientsIV. Do not need to be
passivated
Entity Beans• Provides an Object View of the data in
database • Multiple clients can use entity bean
simultaneously. The clients are isolated from each other via transactions
• Do NOT contain business process logic -they model data
• Are long lived and survive critical failures
CMP vs. BMP
• Container Manager Persistence
I. Container responsible for database accesses/ controls
II. Automatic Persistence
III. Developer focuses on data use
• Bean Managed Persistence
I. Developer must write code to handle database accesses/ controls
II. Persistence by Hand
III. Used for more specialized data mapping strategies
Naming conventions
• The component naming schemes vary from company to company and among developers.
• For EJB class name, the class name followed by the postfix EJB for synchronous EJB, e.g.StudentEJB. For asynchronous EJBs MDB (Message Driven Beans) is used, e.g. RosterMDB.
• For the home interface, the class name followed by the postfix Home, e.g. ScheduleHome. Localhomeinterfaces are named using the prefix Local, e.g. LocalScheduleHome.
Naming conventions
• For the component interface, the class name is followed without or with postfix or prefix, e.g. Schedule. For the local component interface, LocalSchedule.
• The postfix DAO is used for data access Java class, and VO represents value object Java class.
Parts of an Entity Bean
• Includes the:– enterprise bean(s)– Primary key class– remote interface(s)– home interface(s)– deployment descriptor(s)
Enterprise beanhellobean.java
Remote Interfacehello.java
Home interfacehelloHome.java
Deployment descriptorsDeploymentDescriptor.xml
HelloWorld.jar
Primary key classhelloPK.java
Message Driven Beans
• They listen for specific asynchronous messages to which they respond by processing the messages and managing the actions other beans take in response to these messages
• Can be Transaction aware and may update data• Is Stateless, Short-lived, removed as server
crashes• They have NO remote interfaces• They are NOT persistent in nature
Message Driven Beans• In J2EE, Messaging was intended for
sending messages (units of data) from one process to another, concerning:– Events that have taken place– Requests for data– Replies to queries
• Message driven beans are designed to receive and process messages asynchronously using JMS
Message Driven BeansJMS (Java Messaging Service): • is one of the J2EE Application Programming Interfaces• Supports two kinds of messaging:
– Point-to Point: • direct messaging between a sender (client, component or bean) and a
receiver (client, component, or bean). • Messages are QUEUED at the receiver and processed in the same
order that they were received. – Publish-subscribe:
• Multiple applications send multiple messages that can be received by multiple applications
• Messages are sent (published) to a TOPIC and received by all theapplications that have subscribed to the topic
• MDBs are JMS message listeners that are accessed by the client via a particular QUEUE or TOPIC
MESSAGE DRIVEN BEANSAdvantages of MDBs :
– Decoupling: they reduce inter-dependence between applications (beans) and thus increase modularity or independence of applications
– Flexible Integration: They make it easier to put together multiple applications into a complex system (MDBs “wrap” the linkages to other applications)
– Efficiency: Allow for the use of messaging to separate those elements of business logic that can be processed independently from the main timeline (workflow). Allows multiple applications to be served with same message simultaneously
J2EE Component Technology
Component Technologies(JDBC)
• JDBC (Java Database Connectivity)• Allows access of variety of databases in a uniform way.• Enables data manipulation from relational databases.
Component Technologies(JNDI)
(Java Naming and Directory Interface)• Standardized access to various enterprise wide naming and
directory services, such as DNS, LDAP, local file systems, etc.
Component Technologies(JNDI)(Continued…)
• All objects are stored in a hierarchical way• The way the Home interface for EJBs are located• Used to store connection pools for JDBC• Context.lookup(“java:comp/env/jdbc/Pool1”)
– Private context from within components– Defined with a <resource-ref> in deployment
descriptors• Context.lookup(“Pool1”)
– Global context from the outside
Component Technologies(EJB)
• EJB (Enterprise JavaBean)• The flexible business component model• Conceals application complexity and enables the component
developer to focus on business logic.• Types: Session, Entity, and Message-Driven.
Component Technologies(JMS)
• JMS (Java Messaging Service)• a messaging standard that allows J2EE app components to create,
send, receive, and read messages.• Enables distributed communication that is loosely coupled,
reliable, and asynchronous.
Component Technologies(JTA)
• JTA (Java Transaction API)• Provides a standard interface for
demarcating transactions. e.g., a transaction requiring two separate database access operation that depend on each other.
• Provides a way for J2EE components and clients to manage their own transactions, and for multiple components to participate in a single transaction.
Component Technologies(JCA)
• J2EE Connector Architecture enables J2EE components to interact with EIS like-ERP, Mainframe Transaction Processing and non-relational Databases
Component Technologies(JCA)(Continued..)
SAP
JCA
Peoplesoft Tibco Others
Application
Driver Driver Driver Driver
Component Technologies(JAXR)
• JAXR enables Java software programmers to use a single, easy-to-use abstraction API to access a variety of XML registries.
Component Technologies(JAX-RPC)
• Specify APIs for supporting XML based RPC for the Java platform
• The JAX-RPC specification describes the support for message handlers that can process message requests and responses.
• In XML based RPC, a remote procedure call is represented using an XML based protocol. SOAP 1.1 specification defines an XML based protocol for exchange of information in a decentralized, distributed environment.
Component Technologies(JAAS)
JAAS (Java Authentication and Authorization Service)• A Java version Pluggable Authentication Module (PAM),
extending the J2EE security architecture to support user-based authorization.
• JAAS can be used for two purposes: • for authentication of users, to reliably and securely determine who is
currently executing Java code• for authorization of users to ensure they have the access control rights
(permissions) required to do the actions performed.
Component Technologies(RMI-IIOP)
• RMI-IIOP (Remote Method Invocation - Internet Inter-ORB Protocol)• combines the programming ease of Java RMI with
CORBA’s IIOP for easier integration of J2EE applications with legacy applications
Component Technologies(XML)
• XML (eXtensive Markup Language)• Is a cross-platform, extensible, and text-based standard for
representing data. • Parties are free to create their own tags to describe the data, set up
schemas to specify which tags can be used in a particular kind of XML document, and use XML style sheets to manage the display and handling of the data.
• Java API for XML Processing (JAXP)• Simple API for XML Parsing (SAX)• Document Object Model (DOM)• What does it get me?
– You decide the parser that best fits your organization.
Component Technologies(JavaMail, JAF)
• JavaMail• can be used to send internet mails.• Supports provision of new protocols & functionality• Can be used to implement IMAP4, POP3, and SMTP.
• JAF (JavaBeans Activation Framework)• helps determine data types, encapsulate access,
discover operation• Constructs to support MIME (Multi-purpose Internet
Mail Extensions ) data types, as used by the JavaMail API.
J2EE Components packed into Modules
• Enterprise Beans (JAR file)– Classes– Deployment descriptor
• Web Components (WAR file)– Servlet classes, JSPs, HTML, images– Web application deployment descriptor
• Application Clients– Classes– Application client deployment descriptor
J2EE Application Creation StepsServlet
JSP
Web.xml
EJB Archive
Application.xml
Enterprise Archive.ear
EJB
Web Archive.war
Create Components
Create ComponentDeployment Descriptor
Create Component Archive
Create ApplicationDeployment Descriptor
AssembleApplication
Ejb-jar.xml
J2EE Application Creation Steps (Cont.)
J2EE Application Scenario
Future Directions in J2EE
XML Data Binding API• The XML Data Binding API is being
defined through the Java Community Process as JSR-031.
• XML Data Binding depends on schema languages to define the XML data.The current widely used schema language is the DTD language.
Future Directions in J2EE
JNLPThe Java Network Launch Protocol defines a mechanism for deploying Java applications on a server and launching them from a client.
• J2EE products be able to deploy application clients in a way that allows them to be launched by a JNLP client, and that application clientcontainers be able to launch application clients deployed using the JNLP technology.
Future Directions in J2EE
JDBC RowSets• RowSets provide a standard way to send tabular
data between the remote components of a distributed enterprise application. The JDBC API defines the RowSet APIs, and in the future will contain RowSet implementations. Future versions of this specification will require that the JDBC RowSet implementations be supported.