20
Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

Embed Size (px)

Citation preview

Page 1: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

Deploying CFMLon J2EE Servers

Vince BonfantiPresident

New Atlanta Communications, LLC

Page 2: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 2

Introduction

Vince Bonfanti President and co-founder of New Atlanta

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)

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: 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

Page 3: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 3

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

Page 4: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 4

Why CFML on J2EE?

Many companies are standardizing on J2EE for their web application infrastructure (Internet and intranet)

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

Existing CFML applications can be migrated to J2EE 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

Page 5: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 5

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 source file gets compiled to byte code .class file

Java Servlets are the core presentation-layer technology for J2EE

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

Page 6: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 6

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( "<html>" ); out.print( "<head><title>Today</title></head>" ); out.print( "<body>" ); out.print( "<h1>Today is " + java.util.Calendar.getInstance().getTime() + "</h1>" ); out.print( "</body>" ); out.print( "</html>" );}

}

Page 7: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 7

DateServlet Output

Page 8: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 8

What are JavaServer Pages?

JSP is a scripting-based technology 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

JSP scripting language is Java 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

Page 9: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 9

JSP Elements

Scripting Elements<%= expression %><% scriptlet %><%! declaration %>

Standard Actions<jsp:useBean/> <jsp:getProperty/><jsp:include/> <jsp:setProperty/><jsp:forward/> <jsp:param/>

Page Directives<%@ page . . . %><%@ include . . . %><%@ taglib . . . %>

Page 10: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 10

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>

Page 11: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 11

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();

Page 12: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 12

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 ); } }}

Page 13: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 13

JSP Tag Libraries

JSP custom tags (taglibs) allow Java programmers to add CFML-like tags to JSP

Like Java CFX, but more powerful Theoretically, taglibs can eliminate Java code from JSP pages

JSP Standard Tag Library (JSTL) 1.0 released in June 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>

Page 14: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 14

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>

Page 15: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 15

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

Page 16: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 16

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.)

Page 17: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 17

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

Page 18: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 18

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

Page 19: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 19

Demonstration

The world’s simplest J2EE webapp Manually creating a WAR file

The BlueDragon webapp template Developing webapps that contain CFML pages

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

Page 20: Deploying CFML on J2EE Servers Vince Bonfanti President New Atlanta Communications, LLC

MDCFUG – September 10, 2002 Deploying CFML on J2EE Servers 20

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