Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC Introduction Vince Bonfanti President and co-founder of New Atlanta Member of the Java Servlet and.
Download
Report
Transcript Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC Introduction Vince Bonfanti President and co-founder of New Atlanta Member of the Java Servlet and.
Deploying CFML
on J2EE Servers
Vince Bonfanti
President
New Atlanta Communications, LLC
Introduction
Vince Bonfanti
President and co-founder of New Atlanta
Member of the Java Servlet and JSP Expert Groups
Sun-sponsored Java Community Process for defining Java specs
Today’s presentation is one in a series:
ServletExec, a Java Servlet/JSP web application server (1997)
JTurbo, a Type 4 JDBC driver for Microsoft SQL Server (1998)
BlueDragon, a CFML/JSP web application server (2002)
Integrating CFML and J2EE Web Applications (CFNorth, May 2002)
Intro to JSP for CFML Developers (Atlanta CFUG, July 2002)
Deploying CFML on J2EE Servers
[email protected]
Mention MDCFUG in subject or message body
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
1
Overview
Motivation: Why CFML on J2EE?
What are Java Servlets?
What are JavaServer Pages (JSP)?
What is a J2EE Web Application (webapp)?
BlueDragon Architecture
Developing webapps that contain CFML pages
Deploying a webapp in an open directory on Tomcat
Configuring datasources
Deploying webapps that contain CFML pages
Using the BlueDragon WAR Deployment Wizard
Creating CFML compiled binaries (deploying without CFML source!)
Deploying a WAR file onto BEA WebLogic
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
2
Why CFML on J2EE?
Many companies are standardizing on J2EE for their
web application infrastructure (Internet and intranet)
Existing CFML applications can be migrated to J2EE
In-house corporate developers may be faced with top-down
corporate decision to migrate to J2EE
CFML consultants and solutions providers may be faced with client
demands for J2EE-compatible solutions
ColdFusion servers can be retired without rewriting CFML to JSP
Benefits of J2EE scalability, robustness, reliability, portability can be
realized immediately for CFML applications
CFML is a legitimate presentation-layer technology for
J2EE development
CFML is superior to JSP in many ways
CFML can provide full integration with J2EE technologies
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
3
What are Java Servlets?
Java Servlets are alternatives to CGI and NSAPI/ISAPI
web server extensions
Java Servlets are compiled code, but are loaded
dynamically
Java Servlets are the core presentation-layer
technology for J2EE
.java source file gets compiled to byte code .class file
JavaServer Pages (JSP) are built on Java Servlet “plumbing”
Velocity template engine is a Java Servlet
XML/XSLT transformation engines are implemented as servlets
Compiled Java Servlets (.class) are fully portable
across J2EE servers and servlet/JSP engines
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
4
A Simple Java Servlet
public class DateServlet extends HttpServlet
{
public void service( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException
{
response.setContentType( "text/html" );
PrintWriter out = response.getWriter();
out.print(
out.print(
out.print(
out.print(
out.print(
out.print(
"<html>" );
"<head><title>Today</title></head>" );
"<body>" );
"<h1>Today is " + java.util.Calendar.getInstance().getTime() + "</h1>" );
"</body>" );
"</html>" );
}
}
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
5
DateServlet Output
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
6
What are JavaServer Pages?
JSP is a scripting-based technology
JSP scripting language is Java
Similar to ASP and PHP, different than CFML tag-based approach
JSP taglibs allow programmers to create CFML-like custom tags
JSP Standard Tag Library (JSTL) recently reached 1.0 status
Do you have to know Java to write JSP pages? YES!
Theoretically can support other scripting languages, but never will
JSP is translated to a Java Servlet, compiled, executed
.jsp --> .java (servlet) --> .class (servlet)
JSP is “another way to write servlets”
JSP (.jsp) is portable across J2EE servers
Generated servlet (.java/.class) is NOT standard, but is
proprietary to the servlet/JSP container that created it
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
7
JSP Elements
Scripting Elements
<%= expression %>
<% scriptlet %>
<%! declaration %>
Standard Actions
<jsp:useBean/>
<jsp:include/>
<jsp:forward/>
<jsp:getProperty/>
<jsp:setProperty/>
<jsp:param/>
Page Directives
<%@ page . . . %>
<%@ include . . . %>
<%@ taglib . . . %>
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
8
Example JSP Page
<!-- This JSP pages produces output that is exactly equivalent to
the DateServlet example above -->
<%@ page language="java" contentType="text/html" %>
<html>
<head>
<title>Today</title>
</head>
<body>
<h1>Today is
<%=java.util.Calendar.getInstance().getTime()%></h1>
</body>
</html>
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
9
Generated Java Servlet
import com.newatlanta.servletexec.JSP10HttpJspPage;
import com.newatlanta.servletexec.JSP10Servlet;
public final class _today_xjsp extends JSP10HttpJspPage
{
public void _jspService( HttpServletRequest request, HttpServletResponse response )
throws ServletException, java.io.IOException
{
response.setContentType( "text/html" );
JspFactory na_jsp_factory = JspFactory.getDefaultFactory();
PageContext pageContext = na_jsp_factory.getPageContext( this, request, response,
"null", true, 8, true );
ServletConfig config = pageContext.getServletConfig();
ServletContext application = pageContext.getServletContext();
Object page = this;
JspWriter out = pageContext.getOut();
HttpSession session = pageContext.getSession();
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
10
Generated Servlet (cont.)
try {
out.print( "<html><head><title>Today</title></head><body><h1>Today is " );
out.print( String.valueOf( java.util.Calendar.getInstance().getTime() ) );
out.print( "</body></html>" );
} catch ( Throwable t ) {
pageContext.handlePageException( t );
} finally {
out.flush();
na_jsp_factory.releasePageContext( pageContext );
}
}
}
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
11
JSP Tag Libraries
JSP custom tags (taglibs) allow Java programmers to
add CFML-like tags to JSP
JSP Standard Tag Library (JSTL) 1.0 released in June
Like Java CFX, but more powerful
Theoretically, taglibs can eliminate Java code from JSP pages
Variable creation and display (expression language)
Flow control: conditional statements, loops
SQL Database access
XML processing
XML-compliance sometimes leads to awkward syntax
JSTL can’t do <CFIF> … <CFELSEIF> … <CFELSE> … </CFIF>
JSTL can’t do <CFIF variable EQ value>
JSTL can’t do <CFSET variable=value>
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
12
JSTL – SQL example
<%@ taglib prefix="sql" uri="http://java.sun.com/jstl/sql" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<sql:query var="films"
dataSource="jdbc:odbc:ows,sun.jdbc.odbc.JdbcOdbcDriver">
SELECT * FROM Films
</sql:query>
<html>
<head><title>SQL Query Example</title></head>
<body>
<ul>
<c:forEach var="film" items="${films}">
<li><c:out value="${film.MovieTitle}"/>
</c:forEach>
</ul>
</body></html>
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
13
What is a J2EE Webapp?
“A web application is a collection of servlets, html
pages, classes, and other resources that make up a
complete application on a web server. The web
application can be bundled and run on multiple
containers from multiple vendors.”
-- Java Servlet Specification Version 2.3
A J2EE webapp is characterized by a specific directory
structure and a configuration file named web.xml
A J2EE webapp can be bundled and deployed as a
single component within a Web ARchive (WAR) file
Just a ZIP file containing the webapp with the “.war” extension
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
14
Webapp Directory Structure
A J2EE webapp consists of a single directory into
which all content files (HTML, GIF, JPEG, JSP, CFML)
are placed
This is referred to as the webapp “top-level” directory
May contain arbitrary subdirectories to hold content
The WEB-INF subdirectory contains files that will not
be served to the client
The web.xml deployment descriptor is placed within
the WEB-INF subdirectory
The WEB-INF/classes and WEB-INF/lib
subdirectories contain Java .class and .jar files
(these could contain servlets, JSP tag libraries, JDBC
drivers, etc.)
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
15
Webapp Context Path
When deploying a webapp, the J2EE server needs to
know two things:
The location of the webapp directory or WAR file
The URL Context Path used to specify the webapp
The URL Context Path is similar to a virtual directory
All URLs that start with the Context Path are mapped
to the webapp for processing:
http://www.newatlanta.com/contextPath/index.jsp
Using Context Paths allows multiple web applications
to be deployed on a single J2EE server
Web applications are completely independent
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
16
BlueDragon Architecture
BlueDragon is CFML runtime that is implemented as a
standard Java Servlet
The BlueDragon runtime servlet can be built into a
standard J2EE webapp
web.xml is configured to direct processing for all “.cfm” pages to
the BlueDragon servlet
Just add CFML (“.cfm”) pages and deploy!
BlueDragon compiles CFML pages into an internal
representation that is cached and executed from RAM
Compiled CFML pages can be stored and deployed in
files called BlueDragon Archives (BDA)
No need to deploy CFML source files
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
17
Demonstration
The world’s simplest J2EE webapp
The BlueDragon webapp template
Developing webapps that contain CFML pages
Manually creating a WAR file
Deploying as an open directory on Tomcat
Configuring datasources
Deploying webapps that contain CFML pages
Using the BlueDragon WAR Deployment Wizard
Creating compiled BDA archives
Deploying a WAR file on BEA WebLogic
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
18
BlueDragon vs CFMX
Demonstration shows four things that BlueDragon/J2EE
can do today that CFMX/J2EE cannot:
Deploy on Tomcat
Create a WAR file that can be deployed onto any standard J2EE
application server
Create CFML compiled binary archives (BDA) that can be deployed
instead of CFML source files
Deploy WAR files to BEA WebLogic
MDCFUG – September 10, 2002
Deploying CFML on J2EE Servers
19