J2EE Chris Hundersmarck Maria Baron Jeff Webb. Java 2 Platform, Micro Edition (J2ME) Java 2...

50
J2EE Chris Hundersmarck Maria Baron Jeff Webb

Transcript of J2EE Chris Hundersmarck Maria Baron Jeff Webb. Java 2 Platform, Micro Edition (J2ME) Java 2...

Page 1: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

J2EE

Chris HundersmarckMaria Baron

Jeff Webb

Page 2: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Java 2 Platform, Micro Edition (J2ME) Java 2 Platform, Standard Edition

(J2SE) Java 2 Platform, Enterprise Edition

(J2EE) (J2ME) ‘is a subset of’ (J2SE) and

(J2EE) ‘is a superset of’ (J2SE).

Page 3: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

J2EE is…

A distributed multi-tiered application model for enterprise applications.

Divided into components according to function.

Components installed on different machines Client, Server, Database Server

Machines

Page 4: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Page 5: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Containers

Provide access to the underlying services of the J2EE Server environment.

Different types of containers for different types of components

The interface between a component and the low-level functionality that supports a component.

Page 6: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Containers

For example EJB container:

manages the execution of enterprise beans.

Web container manages the execution of JSP pages and

servlet components.

Page 7: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Containers

Page 8: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Client Tier

1. Web clients1. HTML, XML, etc..2. Applets

2. Application clients1. GUI2. Command line

Page 9: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Page 10: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Tier

1. Servlets2. JSP Pages

Page 11: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Components

Page 12: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

JavaServer Faces

Lets you create user interfaces from a set of standard, reusable server-side components

Provides a set of JSP tags to access those components

Transparently saves state information and repopulates forms when they redisplay

Page 13: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

JavaServer Faces

Provides a framework for implementing custom components

Encapsulates event handling and component rendering so you can use standard JSF components or custom components to support markup languages other than HTML

Lets tool vendors develop IDEs for a standard Web application framework

Page 14: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

JSF Components

Each component represents one or more Web page elements

Simple components – individual components such as a text box

Compound components – comprised of multiple elements such as a table

Page 15: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Each JSF component has:

A list of child components A hashmap of attributes One or more validators One or more event handlers An identifier for an optional renderer

Page 16: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Components

All JSF components perform three fundamental tasks Render the component, typically by

generating markup Handle the component's events Validate the component's values

Page 17: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Benefits

Foster the creation of development tools that allow user interface designers to drag and drop components into a layout.

Developer(s) can write event-handling code that will allow the view components to interact with the application model.

Faster GUI creation for prototyping and rapid application development (RAD).

Page 18: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

JSP And Java

Page 19: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

JSF AND JSP

JSF is not bound to JSP - strict decoupling of components from their view rendering

Rendering is done by using a rendering kit

JSP is a required rendering kit but developers can also use custom rendering kits to render views

Page 20: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Business Tier

1. Enterprise Java Beans1. Session Beans2. Entity Beans3. Message-Driven Bean

Page 21: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Java Beans vs. Enterprise Beans

1. Java Beans are not considered J2EE components by the J2EE specification

2. Java Beans:1. Can exist on Server tier or Client tier.2. Manage communication between all three

tiers.

3. Enterprise Beans: 1. Only exist on Business Tier as part of the

Server Tier

Page 22: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Business Components

Page 23: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Enterprise Java Beans

Server-side component Encapsulates business logic Simplifies development

EJB container provides system-level services

Separates business logic from client. EJB are portable components.

Page 24: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Session Beans

1. Represents a single client.2. Client invokes the session bean's

methods.3. Performs work for the client.4. when the client finishes executing,

the session bean and its data are gone.

Page 25: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Session Beans

Two types of Session beans: Stateless Stateful

Page 26: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Entity Beans

1. Represents persistent data stored in one row of a database table.

2. If the client terminates or if the server shuts down, the underlying services ensure that the entity bean data is saved.

Page 27: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Entity Beans

What makes Entity Beans different from Session Beans? Persistence Shared Access Primary Key Relationships

Page 28: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Message-Driven Bean

1. Combines features of a session bean and a Java Message Service (JMS) message listener

2. Allows a business component to receive JMS messages asynchronously.

Page 29: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Message-Driven Bean

Message-driven beans have the following characteristics: They execute upon receipt of a single

client message. They are invoked asynchronously. They are relatively short-lived. They do not represent directly shared data

in the database, but they can access and update this data.

They can be transaction-aware. They are stateless.

Page 30: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Component Packaging

.jar - Java archive : classes and web content for a J2EE application

.war - web application archive .ear – enterprise archive

contains the whole application along with deployment descriptor that provides information about the application and its assembled components

Page 31: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Page 32: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Deployment

Deployment tool provides ability to configure and deploy a complex enterprise application onto the : Sun Java System Application Server or onto other application servers

Page 33: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

What Is XML ?

Text-based markup language As with HTML, you identify data

using tags. Collectively, the tags are known as markup.

Unlike HTML, XML tags identify the data rather than specify how to display it.

Page 34: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

What Is XML ?

<message>   <to>[email protected]</to> <from>[email protected]</from> <subject>XML Is Really Cool</subject><text>How many ways is XML cool? Let me count the ways... </text>

</message>

Page 35: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Java API for XML Processing

(JAXP) is for processing XML data using applications written in the Java programming language.

Leverages the parser standards: Simple API for XML Parsing (SAX)

parse your data as a stream of events

OR Document Object Model (DOM)

build an object representation of it.

Page 36: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Java API for XML Processing

Simple API for XML Parsing (SAX) It is read forward only SAX simply sends data to the

application as it is read Requires much less memory than DOM,

because SAX does not construct an internal representation (tree structure) of the XML data

Fast and efficient

Page 37: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Java API for XML Processing

Document Object Model (DOM) When you need to modify an XML

structure interactively in-memory structure (Object model) provides many powerful capabilities for

large-scale documents requires more complex coding

Page 38: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

JAX-RPC

Java API for XML-based RPC Technology for building web

services and clients that use remote procedure calls (RPC) and XML

Remote procedure call is represented by an XML-based protocol such as SOAP

Page 39: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.
Page 40: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

SOAP

SOAP specification defines the envelope structure encoding rules Conventions

for representing remote procedure calls and responses in XML.

These calls and responses are transmitted as SOAP messages (XML files) over HTTP.

Page 41: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

SOAP

SOAP messages are complex

The JAX-RPC API hides this complexity from the application developer.

Page 42: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Service using JAX-RPC

On the server side, the developer specifies the remote procedures by defining methods in an interface (written in the Java programming language)

The developer also codes one or more classes that implement those methods

Page 43: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Service using JAX-RPC

A client creates a proxy (a local object representing the service) and then simply invokes methods on the proxy.

The developer does not generate or parse SOAP messages

The JAX-RPC runtime system converts the API calls and responses to and from SOAP messages.

Page 44: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Service using JAX-RPC

JAX-RPC client can access a web service that is not running on the Java platform, and vice versa.

Flexibility is possible because JAX-RPC uses World Wide Web Consortium (W3C) technologies:

HTTP, SOAP, WSDL WSDL: Web Service Description

Language. WSDL specifies an XML format for describing a service.

Page 45: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Service using JAX-RPC

Web Client Web Service

Page 46: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Web Service using JAX-RPC

Service Code Extends the java.rmi.Remote interface Methods must throw the

java.rmi.RemoteException or one of its subclasses

Method parameters and return types must be supported JAX-RPC types

Page 47: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Hello Web Service

package helloservice;

import java.rmi.Remote;import java.rmi.RemoteException;

public interface HelloIF extends Remote { public String sayHello(String s) throws

RemoteException;}

Page 48: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

Hello Web Service

package helloservice;

import java.io.*;

public class HelloImpl implements HelloIF { public String message = "Hello ";

public String sayHello(String s) { return message + s; }}

Page 49: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

package staticstub;import javax.xml.rpc.Stub;

public class HelloClient { private String endpointAddress;

public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]);

Stub stub = createProxy(); stub._setProperty(javax.xml.rpc.Stub._ ENDPOINT_ADDRESS_PROPERTY, args[0]);

HelloIF hello = (HelloIF) stub; System.out.println(hello.sayHello("Duke!"));}

private static Stub createProxy() { return (Stub) (new MyHelloService_Impl().getHelloIFPort());

}}

Page 50: J2EE Chris Hundersmarck Maria Baron Jeff Webb.  Java 2 Platform, Micro Edition (J2ME)  Java 2 Platform, Standard Edition (J2SE)  Java 2 Platform, Enterprise.

package staticstub;import javax.xml.rpc.Stub;

public class HelloClient { private String endpointAddress;

public static void main(String[] args) { System.out.println("Endpoint address = " + args[0]);

Stub stub = createProxy(); stub._setProperty(javax.xml.rpc.Stub._ ENDPOINT_ADDRESS_PROPERTY, args[0]);

HelloIF hello = (HelloIF) stub; System.out.println(hello.sayHello("Duke!"));}

private static Stub createProxy() { return (Stub) (new MyHelloService_Impl().getHelloIFPort());

}}