Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML...
-
date post
21-Dec-2015 -
Category
Documents
-
view
223 -
download
2
Transcript of Open Source Java/XML Application Server & & Web Development with Open Source Enhydra Java/XML...
Open Source Java/XML Application ServerOpen Source Java/XML Application Server
&&
Web Developmentwith Open Source Enhydra Java/XML Application Server
Web Developmentwith Open Source Enhydra Java/XML Application Server
James Murphy
UC Santa CruzJanuary 2001
Agenda
• Introduction, CGI, and Servlets
• Architecture
• Application
• Enhydra XMLC
CGI Common Gateway Interface
• First We Have Static Web Pages
• Served by a Web Server to a Browser
• For Search or Buy on Line - Dynamic Web Page
• Enter CGI - Start Process for each request
• Request on standard input
• HTML page on standard output• URL http://www.ecst.csuchico.edu/~murphy/hellop.cgi
• test.cgi (bin/sh) hello.cgi (c program)
CGI Perl script
• #!/usr/local/bin/perl
• #hello: a simple Perl example
• # TWO carriage returns after the content type.
• # This is important to end the header!
• print "Content-type: text/html\n\n";
• # Output a proper HTML document, with <head> and <body> tags.
• print "<head>\n";
• print "<title>Hello, World</title>\n";
• print "</head>\n";
• print "<body>\n";
• print "<h1>Hello, World</h1>\n";
• print "</body>\n";
• Could be cshell Script or Java or C etc. Program
HTML source Generated
• <head>
• <title>Hello, World</title>
• </head>
• <body>
• <h1>Hello, World</h1>
• </body>
HTML Forms and Java Servlets
• <HTML>
• <HEAD>
• <TITLE>Introductions </TITLE>
• </HEAD>
• <BODY>
• <FORM METHOD=GET ACTION="http://localhost:9004/">
• If you don't mind me asking, what is your name?
• <INPUT TYPE=TEXT NAME="name"><P>
• <INPUT TYPE=SUBMIT>
• </FORM>
• </BODY>
• <HTML>
• <HTML>
Java Servlet Hello.java piece
• import java.io.*;
• import javax.servlet.*;
• import javax.servlet.http.*;
• public class Hello extends HttpServlet {
• public void doGet(HttpServletRequest req, HttpServletResponse res)
• throws ServletException, IOException {
• // Set the Content-Type header
• res.setContentType("text/html");
• // Return early if this is a HEAD
• if (req.getMethod().equals("HEAD")) return;
•
Java Servlet Hello.java continued
• // Proceed otherwise
• PrintWriter out = res.getWriter();
• String name = req.getParameter("name");
• out.println("<HTML>");
• out.println("<HEAD><TITLE>Hello, " + name + "</TITLE></HEAD>");
• out.println("<BODY>");
• out.println("Hello, " + name);
• out.println("</BODY></HTML>");
• }
• public void doPost(HttpServletRequest req, HttpServletResponse res)
• throws ServletException, IOException {
• doGet(req, res);
• }
• }
Servlets and eCommerce
• The Web is Stateless
• One servlet for all hits shares data members
• Amazon.com shopper visits many pages
• Need a private shopping cart
• Need a database connection
• Enter Application Servers and Enhydra
Enhydra: #1 Open Source Application Server
• Lutris is sponsor of Enhydra.org, an Open Source Java/XML Application Server
– www.enhydra.org
• Enhydra is a true Open Source Java/XML Application Server
• Over 20,000 downloads
• Over 1000 known participating developers
Professional Services
Professional Services
OpenSource
Software
OpenSource
Software
Startup Incubation
Startup Incubation
Lutris
Lutris
Lutris Technologies, Inc.
Founded: July 1995
Employees: 210
Headquarters: Santa Cruz
Services
•eBusiness Analysis
•Architecture and Implementation
•Creative Design and Branding
Recently Funded by Chase, Hambrecht & Quist, Intel and Trans Cosmos
An Open Source Enterprise Software and Services Company
“Enhydra Lutris”
The EnhydraSolutions Community
Open Source
Enhydra
Open Source
Enhydra
Lutris
Support
Professional Services
Add-On Products
Your Company
Genesis
• Motivation for creating Enhydra:
– Commercial products weren’t ready in 1997
– Offer Lutris customers time-to-market value
– Java on the server for platform independence, group development, etc.
• First licensee: FedEx
• Second licensee: Kinko’s
• Continual pull from customers, (especially start-ups in pre-funding mode.)
Value of Open Source to Lutris & Enhydra
• Lead Generation
• Bug Fixing
• Validate
• Features
• Development community
• Support community
• Internationalpresence
• 3rd party tools & modules
– e-mailBBS, Platypus
• Continue to be driven by real world requirements
• De facto standard
www.enhydra.orgfor the Enhydra Community
• Mail lists & Working Groups– [email protected]
• Mail Archive/Search
• Case studies, News
• On-line Demos– Shopping Cart,
Chat Room, Poker
• 3rd party Services and Products
Working Groups:EJB ContainerWeb Container
I18NWireless
ArchitectureJMX
Rocks/XMLCDODS
Working Groups:EJB ContainerWeb Container
I18NWireless
ArchitectureJMX
Rocks/XMLCDODS
Wizshop/Earthlink/Mindspring
Cisco LocalDirector
Cisco LocalDirector
•Sun E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
•Sun E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
The
Int
erne
t
•Sun E450•Oracle DB
•Sun E450•Oracle DB•Sun
E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
•Sun E250/2CPU•500M Memory•400Mhz•Enhydra•Apache/Jserv
Enhydra Technology
• Enhydra Multiserver
– Servlet runner
– Web Server & Web Server Connection Manager
– Management console
• Enhydra Debugger
– Graphical Servlet Monitor
• Enhydra XMLC– XML/DOM Presentations
• Enhydra Director
– Cluster Support
• Enhydra Application Framework
– “Superservlet Strategy”
• Enhydra Application Wizard (“Newapp”)
– Instant application to jumpstart development
• Enhydra DODS
– Graphical Object-to-SQL mapping application
Enhydra Architecture
Super Servlet Strategy
Enhydra Applications are Super Servlets that contain multiple presentation objects Connects URLs (*.po) and Java classes (presentation objects)
Shared session state/data across multiple URLs
Factoring of common functionality (DB Mgr, Pres Mgr, …)
Presentation objects generate HTML to produce dynamic content JDDI Compiler
XMLC Compiler (encouraged; example later)
Enhydra Multi-Server
Manages the lifecycle of Enhydra Services ServletContainer (now has embedded services)
soon: EJB Container, DatabaseManager Service, …
Establishes connections to ServletContainer
Manages the server configuration file Defines initial state of Enhydra
Connection
JVMMultiServer
<multiserv.conf>
Enhydra ServletContainer
Provides Web Server and Servlet execution HTTP server (will embed full Web Server later)
Runs existing Enhydra servlet applications
Servlet 2.2, JSP 1.1
Manages the lifecycle and connectivity of servlets and Enhydra Applications Provides custom class loader
Supports Connection via http, https, Director
Connection, Channel, Filter structure (more later)
Manages the ServletContainer configuration file section Defines initial state of each application
ServletContainer
Enhydra Director
Connects non-Java web servers to Enhydra App Server Efficient protocol to ServletContainer
Portable design to various Web Servers
Provides load direction capability Map request to available ServletContainer
Session affinity
Header cookie URL rewrite Web
Server
EnhydraDirector
ServletContainer
Connection, Channels & Filters
WebServer
EnhydraDirector
WebBrowser HTTP
WebBrowser HTTPS
WebBrowser
Channel
Connection
Servlet
RR
Servlet
RRChannel
ServletRR
Filter
ServletChannel
RR
R
Channel
Administration Manager
Graphical tool to manage resource parameters HTML interface
Remote accessibility
Management Operation (shown later) Start/Stop applications or servlets
Add/Remove applications or servlets
Modify operational attributes of applications or servlets
Check status of applications or servlets
ServletContainer
Admin Mgr
Presentation Manager Manages loading and execution of
presentation objects Translates URLs to Java classes (*.po)
Uses specified class loader to load classes
Ability to cache presentation objects
One instance per Enhydra application
Executes as a servlet HttpPresentationServlet class
One per Application
Session Manager Provides session key
Cookie URL rewriting
Provides access to session objects Maintain state and user identity across multiple URLs
Session object is passed with each request
Generalized implementation
Session working set management Basic (in memory)
Page to disk
Page to Database
Database Manager
Manages a connection pool Configurable connection pool size
Opened on an as needed basis and are reused
DBQuery Allocates connections from connection pool
Ensures integrity of connections
Manages result sets
DBTransaction Performs a commit or rollback on
inserts, updates, or deletes
DBConnection Pools
Architecture Summary
EnhydraNewApp
EnhydraXMLC
EnhydraDODS
MultiServer
ServletContainer
WebServer
EnhydraDirector
WebBrowser Admin Mgr
Connection
JVM
Overview
• Development Tools
• Development Process
• Example Application
3-Tier Architecture• Database (Back-end)
• Business Logic (Middle-tier)
• Presentation Logic (User Interface)
• Example Code
• Application Deployment
Overview
Enhydra Development Tools
• JBuilder 3 "Foundation"
+ XMLC Wizard
• vi/emacs + xmlc + javac
+ newapp (Utility) + make
• Run-time Debugging– with JBuilder (monitor Java threads, watch values)
– with multiserver (monitor HTTP request/response)
Development Tools
Enhydra Development Tools
• JBuilder Foundation+ XMLC Wizard
Enhydra Development Tools
• Command line tools
– The newapp utility generates "empty" Enhydra project:Directory structure
Stub application classes
make file
– The xmlc utility generates Java classes from HTML or XML templates (more on this later)
Form.html FormHTML.java
Enhydra Development Tools
• What is XMLC?– A compiler for converting an HTML or XML
document into a DOM-compliant Java Object
• What is DOM?– Document Object Model
– W3C specification (www.w3c.org/DOM)
– A standard API to represent a structured document as a traversable tree with branches, nodes, and leaves
– Each markup element in the document becomes a node in the DOM, nested markup elements become child nodes
– Allows HTML documents to be traversed as a tree; nodes can be added, removed, modified, or cloned
Enhydra Development Tools
• Debugging
– In JBuilder+ Multiserver Administration Console
Dynamic
HTML
Dynamic
HTML
Enhydra Development Process
• Typical development steps involve:
• Create database schema
• Typical development steps involve:
• Create data access objects
• Typical development steps involve:
• Create business objects
• Typical development steps involve:
• Create presentation objects
• Typical development steps involve:
Enhydra Multiserver
Enhydra Example Application
• Goal:
Display rows from a SQL query in an HTML table.
• Objects:– Application: App.java– Data: Data.java– Business: Biz.java– Presentation: Pres.java– Template: Table.html
(XMLC generates TableHTML.java)
HTTP Request
HTML Table
Example Java code…
Example Code:
public class App extends StandardApplication {
private Biz biz = null;
public void startup(Config appConfig) throws ApplicationException { super.startup(appConfig);
logChannel.write(Logger.INFO,"Starting up the Example Application");
biz = new Biz(); //Instantiate the "Business" Object. }
public Biz getBiz() { return biz; //Return a reference to the Biz Object. }
} //end class App
App.java
public class App extends StandardApplication {
private Biz biz = null;
public void startup(Config appConfig) throws ApplicationException { super.startup(appConfig);
logChannel.write(Logger.INFO,"Starting up the Example Application");
biz = new Biz(); //Instantiate the "Business" Object. }
public Biz getBiz() { return biz; //Return a reference to the Biz Object. }
} //end class App
Example Code:
public class Biz {
private int requests = 0; //Number of requests serviced.
public String[] getList() { requests++; //Increment the request count. return new Data().query(); //Return list of employee names. }
//Expose number of times a request has been made
public int getRequestCount() { return requests; //Return request count. }
} //end class Biz
Biz.java
public class Biz {
private int requests = 0; //Number of requests serviced.
public String[] getList() { requests++; //Increment the request count. return new Data().query(); //Return list of employee names. }
//Expose number of times a request has been made
public int getRequestCount() { return requests; //Return request count. }
} //end class Biz
Example Code:
public class Data extends Vector {
public String[] query() { //Perform SQL database query.
try { //Use Enhydra database connection pool. DBConnection c = Enhydra.getDatabaseManager().allocateConnection(); ResultSet r = c.executeQuery("select ENAME from EMP"); while (r.next()) add(r.getString(1)); c.reset(); c.release(); // Be sure to release DBConnection... } catch (Exception e) { //...back into the connection pool! e.printStackTrace(); } //Explicit cast is required by compiler. return (String[])toArray(new String[] {}); }
} //end class Data
Data.java
public class Data extends Vector {
public String[] query() { //Perform SQL database query.
try { //Use Enhydra database connection pool. DBConnection c = Enhydra.getDatabaseManager().allocateConnection(); ResultSet r = c.executeQuery("select ENAME from EMP"); while (r.next()) add(r.getString(1)); c.reset(); c.release(); // Be sure to release DBConnection... } catch (Exception e) { //...back into the connection pool! e.printStackTrace(); } //Explicit cast is required by compiler. return (String[])toArray(new String[] {}); }
} //end class Data
Example Code:
<html>
<head> <title>Employee Names</title> </head>
<body>
<table id="exampleTable" border="1" > <tr id="tableRow"> <td><span id="name">Employee Name<span></td> </tr> </table>
</body>
</html>
+ XMLC
Table.html
= TableHTML.java
DOM
HTMLTableRowElement getElementTableRow();
HTMLTableElement getElementExampleTable();
void setTextName();
+"Convenience methods":
Example Code:
public class Pres implements HttpPresentation {
public void run(HttpPresentationComms c) throws HttpPresentationException { TableHTML tableDOM = new TableHTML(); //Generated by XMLC. Biz b = ((example.App)c.application).getBiz(); //Business object. fillTable(tableDOM, b.getList()); //Populate the table. c.response.writeHTML(tableDOM.toDocument()); //Display the table! }
private void fillTable(TableHTML tableDOM, String[] list) { //Manipulate table related elements of DOM. HTMLTableElement table = tableDOM.getElementExampleTable(); // Add new row... for (int i = 0 ; i < list.length ; i++) //...elements to DOM table.appendChild(createNewRow(tableDOM, list[i])); }…
Pres.java
TableHTML tableDOM = new TableHTML();
fillTable(tableDOM, b.getList()); c.response.writeHTML(tableDOM.toDocument());
private void fillTable(TableHTML tableDOM, String[] list)
HTMLTableElement table = tableDOM.getElementExampleTable();
HTMLTableElement table = tableDOM.getElementExampleTable();
Example Code:Pres.java
…
private HTMLTableRowElement createNewRow(TableHTML tableDOM, String name ) { tableDOM.setTextName(name); //Set the <SPAN> text.
return (HTMLTableRowElement) //Return the row element. tableDOM.getElementTableRow().cloneNode(true);
}
} //end class Pres
(cont)
…
private HTMLTableRowElement createNewRow(TableHTML tableDOM, String name ) { tableDOM.setTextName(name); //Set the <SPAN> text.
return (HTMLTableRowElement) //Return the row element. tableDOM.getElementTableRow().cloneNode(true);
}
} //end class Pres
…
private HTMLTableRowElement createNewRow(TableHTML tableDOM, String name ) { tableDOM.setTextName(name); //Set the <SPAN> text.
return (HTMLTableRowElement) //Return the row element. tableDOM.getElementTableRow().cloneNode(true);
}
} //end class Pres
Enhydra Application Development
• make
(…and then a miracle occurs…)
Enhydra Application Deployment
• Example.conf
Server.ClassPath[] = "/enhydra/classes/example.jar"
Server.AppClass = "example.App"
Server.PresentationPrefix = "example/presentation"
Application.DefaultUrl = "Pres.po"
• Created by JBuilder Application Wizard
• …or by running newapp
• …automagically!
Enhydra Application Deployment
• Example.conf (cont.)DatabaseManager.Databases[] = "Example"
DatabaseManager.DefaultDatabase = "Example"
DatabaseManager.DB.Example.ClassType = "Oracle"
DatabaseManager.DB.Example.JdbcDriver = "oracle.jdbc.driver.OracleDriver"
DatabaseManager.DB.Example.Connection.Url = "jdbc:oracle:thin:@artemis:1521:SID2"
DatabaseManager.DB.Example.Connection.User = "scott"
DatabaseManager.DB.Example.Connection.Password = "tiger"
DatabaseManager.DB.Example.ObjectId.CacheSize = 0
Enhydra Application Deployment
• multiserver.conf
Application.Example.ConfFile = "Example.conf"Application.Example.Description = "Example Enhydra Application"Application.Example.Running = "yes"
Connection.Http8001.Type = "http"Connection.Http8001.Port = 8001
Channel.Http8001.ExampleChannel.Servlet = "Example"Channel.Http8001.ExampleChannel.Url = "/"Channel.Http8001.ExampleChannel.Enabled = "yes"
• Created by Enhydra Administration utility
• …automagically!
Enhydra Application Deployment Adding "Example"• Enhydra Administration:
Example
Enhydra XMLC
Separate Graphics from Code
What is XMLC?
• XMLC = XML Compiler
• XMLC - Compiles an HTML or XML document into a DOM (Document Object Model)-compliant tree that can then be used as a java object which can reconstruct that document
• Provides object-oriented access to HTML or XML document templates
• Convenience getElement...() and setText…() direct accessor methods are additionally compiled into the document to facilitate common tasks
...Enhydra XMLC Overview
• Programmer adds dynamic content to the document by adding and manipulating DOM objects
• Static page URLs can be replaced with dynamic ones
• Prototype table rows can be used as templates for other rows.
Embedded Page Languages: Bad Idea!• HTML is developed by graphic artists
– Authoring programs can break the code
– Pages with mocked-up data are not final mockup
– Most graphic artists cannot program
• Code is developed by programmers
– They use source code editors
– Code added to HTML is difficult to maintain
– Most programmers cannot draw
Embedded Page Languages: Bad Idea!• Embedded page languages are not legal
HTML
– Can’t parse the pages with standard parsers
– Standards are a good thing.
• Flow-of-control is obscured
• Little compile-time type checking available
• Does not integrate well with debuggers, profilers
• Poor support for I18N
JSP Example
<HTML><%@ page language==“java”
imports==“com.wombat.JSP.*” %><H1>Welcome</H1><P>Today is </P><jsp:useBean id==“clock”
class==“calendar.jspCalendar” /><UL><LI>Day: <%==clock.getDayOfMonth() %><LI>Year: <%==clock.getYear() %></UL><% if (Calendar.getInstance().get(Calendar.AM_PM)
== Calendar.AM) { %>Good Morning<% } else { %>Good Afternoon<% } %><%@ include file==“copyright.html” %></HTML>
An HTML Example
<TABLE> <TBODY> <TR> <TH>Name</TH> <TH>City</TH> </TR> <TR> <TD>John Doe</TD> <TD>Atlanta</TD> </TR> </TBODY> </TABLE>
DOM Representation
ID=custName ID=city
Adding ID Attributes
<TABLE> <TBODY> <TR> <TH>Name</TH> <TH>City</TH> </TR> <TR> <TD ID=“custName”>John Doe</TD> <TD ID=“city”>Atlanta</TD> </TR> </TBODY> </TABLE>
Enhydra XMLC
Java DOM Package
• Document: Root of tree
– Provides factory methods for other DOM classes
• Node: Base class of all DOM tree objects
– Contains children and parent links
– Provides methods for manipulating the tree
• Element: Interface for XML tag classes
– Extends Node
– Specific applications may define classes that extend Element (e.g., HTMLTableElement, etc.)
• Text: Nodes that contain the document text
Java DOM HTML Package
• org.w3c.dom.html
– DOM Interfaces for HTML
• HTMLDocument - Root of the HTML hierarchy• HTMLHeadElement - <HEAD>• HTMLBodyElement - <BODY>• HTMLParagraphElement - <P>• HTMLAnchorElement - <A>• HTMLTableElement - <TABLE>• HTMLFontElement - <FONT>• …more…
Simple XMLC ExampleHTML - Hello.html
<H1><FONT ID=“HeadFont” SIZE=“4” COLOR=“red”>Hello World</FONT></H1><P>Hello, my name is <SPAN ID=“CustName”>John Doe</SPAN>
Using the Generated Class HelloHTMLHelloHTML hello = new HelloHTML();HTMLFontElement hfont = hello.getElementHeadFont();hfont.setColor(“Green”);hello.setTextCustName(“Barney Blake”);out.println(hello.toDocument());
Work Flow using Enhydra XMLC
• HTML designer creates a working storyboard/demo page
• The designer tags dynamic elements with HTML 4.0 ID tags, e.g.,
<TD ID=“CustName”>…</TD>
and hands off the page to the programmer
• The programmer compiles the page into a java class which is a DOM tree that can reproduce the document
Development with Enhydra XMLC
welcome.html
xmlc -class myapp.WelcomeHTML welcome.html
javac
myapp.WelcomeHTML
… Work Flow ...
• XMLC generates “getElement<IDName>()” and “setText<IDName>()”methods in the document object, e.g.
getElementCustName()and setTextCustName() for each ID-tagged HTML page element
• At run-time the programmer instantiates the HTML page as an object and manipulates its properties
…Work Flow
• The programmer can use the XMLC-generated methods like getElementCustName()to clone, remove, or otherwise manipulate page elements
• The programmer can also traverse the DOM tree to manipulate its other nodes directly if desired
• Finally toDocument() is called on the page object to stream the page to the web client as a string
Advantages of XMLC
• Object-oriented control of documents
• Layout and flow of control are completely separated
• Page designers and programmers only intersect on defining the dynamic page elements
• Programmers are largely unaware of page layout
...Advantages
• HTML storyboard can be demo’d and modified in parallel with the server-side code
• Business logic and user interface can be developed and tested completely independently of each other
• Enhydra XMLC can serve the presentation layer in any multi-tier java environment, such as BEA WebLogic
XMLC for XML
• XMLC compiles any XML document
– Generic DOMs
– DTD-specific DOMs
• XML intended for display
• XML as data interchange format
• WML - Wireless Markup Language
– HTML-like DTDs for wireless devices
– Many companies using Enhydra XMLC for developing WML applications
Toward J2EE Enhydra
Other Open Source contributions,including on-going Enhydra evolution
JOnAS,BullSoft
Jonathan,France Telecom
Open Source Java/XML Application ServerOpen Source Java/XML Application Server