Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee...

114
Copyright © 1998 Alex C haffee Bean Soup: Using Bean Soup: Using Components With Java Components With Java Alexander Day Chaffee [email protected] jGuru Training by the Magelang Institute http://www.jguru.com/

Transcript of Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee...

Page 1: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Bean Soup: Using Bean Soup: Using Components With JavaComponents With Java

Alexander Day Chaffee

[email protected]

jGuru Training by the Magelang Institutehttp://www.jguru.com/

Page 2: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

AbstractAbstract

"Component-based software design" is the hottest buzzword since "object-oriented programming." But what does it mean? What's a component? What's a JavaBean? An Enterprise JavaBean? What is COM and ActiveX? Can I use COM objects from Java? Can I use Java in an ASP? What about CORBA? Do components really help you reuse code and increase your team's productivity, or is it just another meaningless technology? In this section we pose these questions and more, and actually answer some of them.

Page 3: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

IntroductionIntroduction

jGuru Training by the Magelang Institute http://www.jguru.com/

Java Training and Consulting Alex Chaffee

Creator of Gamelan Cool Java Dude

Page 4: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

OverviewOverview

Component Architectures Client-side components

Java Beans Swing/JFC ActiveX

Page 5: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Overview (cont.)Overview (cont.)

Server-side components Servlets Remote Method Invocation CORBA Objects Enterprise Java Beans

Page 6: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

ComponentsComponents

Page 7: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

What is an object?What is an object?

Encapsulation State + behavior Data + methods

Polymorphism Inheritance Programming construct Buried inside a program An object may be reusable

Page 8: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

What is a component?What is a component? Software “part” Self-contained, independent Plug-and-play, drag-and-drop Interact and interoperate with other components Assemble components to create an application Ready for use by visual programming tools Marketable A component must be reusable

Page 9: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

What a component is notWhat a component is not

an application

Page 10: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Some Standard Some Standard Component FeaturesComponent Features

Visual representation Persistent state Event / message passing Distributed (network-aware)

Page 11: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Law and OrderLaw and Order

Components must operate according to a set of rules

APIs (interfaces) Naming conventions Message-passing model

method invocation event model

Page 12: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

The ArchitectureThe Architecture

Dictates rules Provides common set of services Example architectures

JavaBeans CORBA OLE / ActiveX OpenDoc EJB

Page 13: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Core Architecture ServicesCore Architecture Services

creation registration discovery disposal

Page 14: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

More Architecture ServicesMore Architecture Services

visual representation visual tool integration persistence event passing and notification networking

Page 15: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Advanced servicesAdvanced services

Security Licensing Scripting Introspection (meta) Transactions Naming Universal ID Version Management Install/uninstall Testing

Page 16: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Why Components?Why Components? Quick and easy GUI design Solve “bloatware” Scriptable Lower barrier to entry for small software

developers Easier to write, debug, mantain large applications Assemble targeted applications

e.g. Word for Hospitals

(cont.)

Page 17: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Why Components? (cont.)Why Components? (cont.)

Document-centric computing Wrappers for legacy code

Page 18: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Java BeansJava Beans

Page 19: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Why Java?Why Java?

Write once, run anywhere Well-designed event model and APIs Full-featured language

Page 20: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

GoalsGoals

100% Pure Java Keep it simple Not necessarily visual Leverages Java platform Usable inside builder tools

Page 21: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

What is a bean?What is a bean?

“A Java Bean is a reusable software component that can be manipulated visually in a builder tool.”

A Java class Any Java class

that follows certain naming conventions

Page 22: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Example BeanExample Beanclass CoffeeBean implements Serializable

{

private double price;

public CoffeeBean() { this(100);}

public void setPrice(double price) {

this.price = price;

}

public double getPrice() {

return price;

}

} Note: no explicit “is a bean” syntax

Page 23: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Classes vs. BeansClasses vs. Beans

If any class can be a bean, what makes a class a bean? Properties Events Persistence Customization Naming conventions

Page 24: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Naming ConventionsNaming Conventions

used to mark design patterns very important for JavaBeans simply by naming methods correctly,

your class becomes a bean Not required, but strongly

recommended can use BeanInfo class instead

Page 25: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

IntrospectionIntrospection

metabean 1) low-level reflection (JDK1.1) 2) analyze wrt design patterns or, use BeanInfo

Page 26: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

PropertiesProperties

Exposed data values Named attributes Accessor / mutator methods Design pattern:

public void setColor(Color c) public Color getColor()

Page 27: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

MethodsMethods

Exposed public methods Design pattern:

public void scratchAndSniff()

Page 28: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

EventsEvents

Methods called when something interesting happens

Event source / event listener design pattern Design pattern:

public void addSniffListener(SniffListener listener)

public void removeSniffListener(SniffListener listener)

Page 29: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Design-time vs. Run-timeDesign-time vs. Run-time

Beans can run in two environments inside a BeanBox inside an application

Different requirements Different overhead

Page 30: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

CustomizationCustomization

default UI for editing properties a bean can provide its own UI

per property per entire bean

property sheet a window that allows a user to edit beans

Page 31: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

PersistencePersistence

all beans must support either Serializable or Externalizable

Page 32: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Beans and Java 1.1Beans and Java 1.1

Beans rely on many features added to JDK 1.1

Realistically, you need a 1.1 VM JDK 1.1, JRE 1.1 (Sun) Microsoft IE4.0 Netscape Navigator 4.03 + patch

Page 33: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Applets vs. BeansApplets vs. Beans

Applets live in browsers, beans live in applications

Beans need much more functionality Beans are more strict in their naming

conventions You can make a class that is both an

applet and a bean

Page 34: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Beans vs. ActiveXBeans vs. ActiveX

Beans have OO advantages of Java ActiveX controls have performance

advantages and access to Win32 API Interoperable

Sun’s Bean-ActiveX Bridge MS’s JVM transparently integrates the two

Page 35: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Limitations of JavaBeansLimitations of JavaBeans

Java-centric (pro and con)

Page 36: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Related TechnologiesRelated Technologies

ActiveX/OLE CORBA JavaIDL RMI JDBC

Page 37: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Bean Technology: Glasgow Bean Technology: Glasgow (JDK 1.2)(JDK 1.2)

Bean Contexts (aka “Runtime Containment and Services”) This provides a containment hierarchy for

JavaBeans and provides ways for beans to find context-specific information such as design-mode versus run-mode.

Native Drag-and-Drop support

Page 38: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Glasgow (cont.)Glasgow (cont.)

JavaBeans Activation Framework (Standard Extension) Using beans to view different media types Identify media type (e.g. MPEG) Locate viewer for that type

Page 39: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Bean Technology: InfoBusBean Technology: InfoBus

enables dynamic exchange of data between JavaBeans components

protocols based on a notion of an information bus

based on Lotus’ InfoBus technology only works inside a single VM

Page 40: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

DemoDemo

Page 41: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Some cool beansSome cool beans

HotJava Bean HTML Renderer

DoqView Word/Excel/Powerpoint viewers

Alphaworks image filters, POP3/SMTP/FTP protocols,

spinners, progress bars, XML parsers

Page 42: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright (c) 1997 Alex Chaffee

Bean Builders (IDEs)Bean Builders (IDEs)

BeanBox (Sun) Visual Café (Symantec) VisualAge for Java (IBM) JBuilder (Borland) Cosmo Code (SGI) Super Mojo (Penumbra)* (R.I.P.)

* written in 100% Pure Java

Page 43: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

JFC and SwingJFC and Swing

JFC = Swing + Java2D + Drag-and-drop + a few other things

Swing = New GUI widget set All Swing widgets are JavaBeans Standard (core) with JDK 1.2 release

Page 44: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Basic WidgetsBasic Widgets

JButton JLabel JPanel JMenu JFrame (window)

Page 45: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

JTree and JTableJTree and JTable

JTable spreadsheet-like

JTree hierarchical display

Page 46: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

JEditorPaneJEditorPane

Full HTML renderer component

Page 47: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

ActiveX and COM ActiveX and COM IntegrationIntegration

Page 48: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

DefinitionsDefinitions

COM ActiveX DCOM

Page 49: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

COM InterfacesCOM Interfaces

Base: IUnknown

Page 50: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

The RegistryThe Registry

Mongo database Register all COM objects Can also register Java objects as COM

objects JavaReg /register

/class:com.foo.Tommy /progid:Tommy

Page 51: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

COM Integration with the COM Integration with the Microsoft VMMicrosoft VM

Transparent integration COM objects are accessible from Java

as Java objects Note: huge security hole

Java objects are accessible from COM as COM objects Must register using JavaReg

Page 52: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

COM Integration with the COM Integration with the Sun VMSun VM

Need to use “ActiveX Bridge” Straightforward but not as seamless

Page 53: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Server-side componentsServer-side components

Servlets CORBA EJB

Page 54: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

ServletsServlets

Page 55: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

What Is A ServletWhat Is A Servlet

A Java object Plug-in for a web server Replacement for CGI scripts

Can also be used to extend server as a plug-in Full power of Java

Platform-independent Database access Fun to write

Page 56: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Server/Service/ServletServer/Service/Servlet

server - a process running on a host machine Apache, Java Web Server

service - a protocol running on a port HTTP, FTP

servlet - a module running inside a service PhoneServlet

Page 57: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlets vs. AppletsServlets vs. Applets

Servlets have no GUI Server-side, not client-side Different security model Installed, not downloaded

But you can download remote servlets too Consistent server-side VM

Much easier to test

Page 58: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlets vs. CGIServlets vs. CGI

"performance, flexibility, portability, and security" (whitepaper)

Faster and Leaner No fork-process like Perl No need to initialize for each request Only lightweight thread context switching Built-in multithreading

Page 59: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlets vs. CGI (Cont.)Servlets vs. CGI (Cont.)

Easy to manage state share data across successive requests share data between concurrent requests use hidden fields, cookies, or sessions

Write once, run anywhere It's easy to write unportable Perl Servlets have standard API

Supports all methods GET, POST, PUT, DELETE, et al.

Page 60: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlets vs. FastCGIServlets vs. FastCGI

FastCGI sends multiple requests to a single separate process requires process context switch

Servlets send multiple requests to multiple threads in same process requires lightweight thread context switch

(Also applies to ISAPI) Nice diagram in White Paper Servlets also automatically take advantage of

multiprocessors if the underlying JVM does

Page 61: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Supported ServersSupported Servers

Java Web Server Apache Netscape Many others (see web site) Servlet Engines

IBM's ServletExpress Live Software’s JRun

Page 62: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet SecurityServlet Security

Trusted Servlets (full access) JWS Internal Local (in the "servlets" directory)

Servlet Sandbox Signed Network Servlets (full access) Unsigned Network Servlets (limited access)

Page 63: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet Security: Servlet Security: ImplicationsImplications

IT managers can sign servlets for use in their organization

ISPs can allow users to run servlets less of a security hole than CGI scripts, since Java

is safe and secure (at least more so than C or Perl)

still allows denial-of-service attacks Network servlets are possible

chaining / proxying allows agents common servlet repository for multiple servers

one place to install updates

Page 64: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet Security: ProblemsServlet Security: Problems

Too simplistic All or nothing

Should allow ACLs for particular signers They claim it will in a future version

Should get better with 1.2 security model Finer-grained access control

Page 65: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet Client SecurityServlet Client Security

Java Web Server Allows Access Control Lists for clients Supports HTTP authentication Supports Digest Authentication

Other Web Servers Usually support HTTP authentication May have other security features

Page 66: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

API AvailabilityAPI Availability

Standard Java Extension API From white paper: "This means that while it

is not part of the core Java framework which must always be part of all products bearing the Java brand, it will be made available with such products by their vendors as an add-on package."

package javax.servlet.*, javax.servlet.http.*

Page 67: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet Architectures:Three-tier Servlet Architectures:Three-tier systemsystem

Tier 1: Client HTML browser Java client

Tier 2: Servlets embody business logic secure, robust

Tier 3: Data Sources Java can talk to SQL, CORBA, OODB, File

system, etc. etc.

Page 68: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet Architectures: N-tier Servlet Architectures: N-tier systemsystem

Tier 1: HTML Browser Tier 2: Servlet

User interface Tier 3: EJB/CORBA/RMI Objects

Business logic Tier 4: Other Servers (e.g. RDBMS)

Data storage

Page 69: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Servlet Architectures: Web Servlet Architectures: Web PublishingPublishing

SSI Servlets JSP Servlets

Best to keep business logic inside Java objects Keep the JSP light so designers don’t get scared

Chaining servlets Multiple servers

data gathering, collecting, serving, load balancing, etc.

Page 70: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Server-side Includes (SSI)Server-side Includes (SSI)

Must be in a file named .shtml or .jsp can change this with Admin Tool

Normal SSI <!--#include file="foo.txt" -->

Servlet SSI <servlet code=DateServlet.class> </servlet>

Page 71: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

SSI DetailsSSI Details

pass init parameters in servlet tag pass servlet parameters in param tags can specify codebase in servlet tag e.g.<servlet code=DateServlet.class codebase=http://servlets.foo.com/ initParam1=val1 initParam2=val2>

<param name=serviceParam1 value=val3>

<param name=serviceParam2 value=val4>

</servlet>

Page 72: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

URL invocationURL invocation Directly from browser as URL

http://www.myserver.com/servlet/MyServlet From inside FORM tag as script

<FORM METHOD=POST ACTION=”/servlet/MyServlet”>

...</FORM>

From inside JHTML or JSP page Uses “Page Compilation” Compiles the jsp file into a servlet on the fly,

then executes it

Page 73: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Page Compilation (JSP)Page Compilation (JSP)

Embed Java code in static HTML pages then compile those pages into individual Java servlets to create a dynamic web site

Based on JHTML technology from Art Technology Group (http://www.atg.com/) Product: Dynamo, a Java Web Application

Server

Page 74: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

HelloHttpServletHelloHttpServlet

public class HelloHttpServlet extends HttpServlet{ public void doGet(HttpServletRequest req,

HttpServletResponse res) throws IOException, ServletException

{ String name = req.getParameter("name"); if (name == null) name = "Joe"; res.setContentType("text/plain"); ServletOutputStream out = res.getOutputStream();

out.println("Hello, " + name + "!"); }}

Page 75: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Saving State: WhySaving State: Why

Shopping Cart User Preferences “Wizard” interfaces

i.e., successive linked dialog boxes / form entry pages

Page 76: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Saving State: HowSaving State: How

Client-side storage Hidden fields URL Rewriting Cookies

Server-side storage Instance variables Database Access

JWS Session Management Best possible solution (but still flawed)

Page 77: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Remote Method Invocation Remote Method Invocation (RMI)(RMI)

Page 78: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

What Is RMI?What Is RMI?

Access to Remote Objects Java-to-Java only Client-Server Protocol High-level API Transparent Lightweight

Page 79: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

TCP

Remote Objects (Diagram)Remote Objects (Diagram)Java Virtual Machine

Client Object

Java Virtual Machine

Remote Object

Page 80: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

RMI LayersRMI Layers

TCPRemote Reference Layer

Transport Layer

Java Virtual Machine

Client Object

Remote Reference Layer

Transport Layer

Java Virtual Machine

Stub

Remote Object

Skeleton

Page 81: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

Stubs and SkeletonsStubs and Skeletons

Stub lives on client pretends to be remote object

Skeleton lives on server receives requests from stub talks to true remote object delivers response to stub

Page 82: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

Remote Interfaces and Remote Interfaces and StubsStubs

Remote Interface

StubRemote Object

(Server)Client Skeleton

implements implements

Page 83: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

Creating Remote ObjectsCreating Remote Objects

Define a Remote Interface extends java.rmi.Remote

Define a class that implements the Remote Interface extends java.rmi.RemoteObject or java.rmi.UnicastRemoteObject

Page 84: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

CORBA ObjectsCORBA Objects

Page 85: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

What is CORBA?What is CORBA?

Common Object Request Broker Architecture

Communication infrastructure for distributed objects

Allows a heterogeneous, distributed collection of objects to collaborate transparently

Page 86: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

What is CORBA good for?What is CORBA good for?

Developing distributed applications Locating remote objects on a network Sending messages to those objects Common interface for transactions,

security, etc. CORBA Services (more later)

Page 87: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

What is the OMG?What is the OMG?

Designers of CORBA Consortium of 700+ companies

Not including Microsoft Members:

platform vendors database vendors software tool developers corporate developers software application vendors

Page 88: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Basic CORBA ArchitectureBasic CORBA Architecture

Client Server

ORB ORB

request response

“Object Bus”

Page 89: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

CORBA ObjectsCORBA Objects

Examples Service Client Component Business object

CORBA objects approach universal accessibility Any Language Any Host on network Any Platform

Page 90: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

ORBORB

Object Request Broker “Object Bus”

Handles all communication among objects

Each host (machine) has its own ORB ORBs know how to talk to each other ORB also provides basic services to

client

Page 91: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

ORB ResponsibilitiesORB Responsibilities

Find the object implementation for the request

Prepare the object implementation to receive the request

Communicate the data making up the request

Retrieve results of request

Page 92: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Network of ORBsNetwork of ORBs

There’s an ORB on the server too ORB receives request

Page 93: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

IIOPIIOP

Internet Inter-Orb Protocol Network or “wire” protocol Works across TCP/IP (the Internet

protocol)

Page 94: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

Stubs and SkeletonsStubs and Skeletons

Stub lives on client pretends to be remote object

Skeleton lives on server receives requests from stub talks to true remote object delivers response to stub

Page 95: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1997 Alex Chaffee

Stubs and Skeletons (Fig.)Stubs and Skeletons (Fig.)

IIOPORB

Client Host Machine

Client Object

ORB

Server Host Machine

Stub

Remote Object

Skeleton

Page 96: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Client vs. ServerClient vs. Server

in CORBA, a client is a client relative to a particular object

i.e. an object with a reference to a “server” object

A client may also act as a server If it has an IDL and stubs and skeletons

Technically, a CORBA server contains one or more CORBA objects

Page 97: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

The Java ORBThe Java ORB

100% Java Generic Allows Java IDL applications to run

either as stand-alone Java applications, or as applets within Java-enabled browsers

Uses IIOP

Page 98: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

RMI over IIOPRMI over IIOP

In Development Uses IIOP as transport protocol Uses Value Objects to pass Java

serialized objects

Page 99: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

CORBA via RMICORBA via RMI

Possible using middleware server RMI from client to middleware IIOP from middleware to other servers Can use Servlet as middleware

Page 100: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Enterprise Java BeansEnterprise Java Beans

Page 101: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

What is an EJBWhat is an EJB

NOT a JavaBean Server-side business component Transactional Distributed Secure Platform-independent Vendor -independent

Page 102: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

The EJB SpecThe EJB Spec

Defines the role of an EJB server Levels the playing field

Removes competitive “lock-in” advantage Created by many competitors

Testament to power of having a common enemy

Allows EJBs to run in many different vendors’ products

Page 103: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Distributed TransactionsDistributed Transactions

One transaction Many operations Many servers Many databases Distributed two-phase commit

Page 104: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Two Types of Enterprise Two Types of Enterprise BeansBeans

Session Bean Represents a particular client during a

single session Entity Bean

Represents a data object E.g. a row in a table

Often, a session bean will invoke one or more entity beans

Page 105: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

EJB ContainersEJB Containers

Implement services used by EJBs Specialized containers

Extend EJB spec 110% Pure

Page 106: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

CORBA and EJBCORBA and EJB

Transport EJB uses RMI interface, RMI uses IIOP

CORBA 3.0 promises object compatibility with EJB Not quite sure what that means

Some EJB Servers contain an ORB All EJB Objects are also CORBA objects

Page 107: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

CORBA and EJB (Cont.)CORBA and EJB (Cont.)

All EJB Servers use CORBA Transactions (via JTS) That means that any client can make a

distributed transaction that includes both CORBA and EJB Objects

Not an either-or decision You can have both EJB and CORBA

working together in a single system

Page 108: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Java TransactionsJava Transactions

Java Transaction Service (JTS) A standard Java mapping of the OMG Object

Transaction Service (OTS) packages org.omg.CosTransaction and

org.omg.CosTSPortability

Java Transaction API (JTA) High-level transaction management specification package javax.transaction class UserTransaction

Page 109: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Object Transaction Service Object Transaction Service (OTS)(OTS)

Distributed transaction specification Part of CORBA, but also standalone Transactions can span

multiple queries multiple objects multiple servers multiple databases multiple vendors’ products

Page 110: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

OTS FeaturesOTS Features

Distributed transactions Flat or nested transactions

Nested not supported in Java

Two-phase commit Vendor interoperability (?)

Page 111: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

EJB + ServletsEJB + Servlets

A great architecture Wider platform for clients

HTML runs on most clients, even without Java

Secure No need to put password on client

Fast Data access happens inside your LAN

Page 112: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

ConclusionConclusion

Page 113: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

CreditsCredits

Thanks to Christof Sieberath (@swisscom.com) for may/must distinction

Page 114: Copyright © 1998 Alex Chaffee Bean Soup: Using Components With Java Alexander Day Chaffee alex@jguru.com jGuru Training by the Magelang Institute

Copyright © 1998 Alex Chaffee

Where to Get More Where to Get More Information: Information:

Web sites http://www.Developer.com/ (Gamelan) http://www.JavaWorld.com/ (magazine) http://www.Purpletech.com/ (author’s site) http://www.alphaworks.ibm.com/alphaBeans