MAX 2006 Beyond Boundaries

Similar documents
Adobe ColdFusion level 1 course content (3-day)

Going From CF to Java

CF and JSP/Servlets. Topics Covered. What are they? Developed originally by Robi Sen For the CF UnderGround II Seminar, Apr 2001

Make the Leap to CF8 Application.cfc. MDCFUG February Ajay Sathuluri.

[Course Overview] After completing this module you are ready to: Develop Desktop applications, Networking & Multi-threaded programs in java.

web.xml Deployment Descriptor Elements

White Paper. Executive summary

Fast Track to Java EE 5 with Servlets, JSP & JDBC

Introduction to JSP and Servlets Training 5-days

Topics Augmenting Application.cfm with Filters. What a filter can do. What s a filter? What s it got to do with. Isn t it a java thing?

Classloader J2EE rakendusserveris (Bea Weblogic Server, IBM WebSphere)

Fast Track to Java EE

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Java.. servlets and. murach's TRAINING & REFERENCE 2ND EDITION. Joel Murach Andrea Steelman. IlB MIKE MURACH & ASSOCIATES, INC.

JavaEE Interview Prep

Adobe ColdFusion 11 Enterprise Edition

Java Programming Course Overview. Duration: 35 hours. Price: $900

CS506 Web Design & Development Final Term Solved MCQs with Reference

JAVA. Duration: 2 Months

BlueDragon TM 7.0 Deploying CFML on J2EE Application Servers

Page 1

Java J Course Outline

This course is intended for Java programmers who wish to write programs using many of the advanced Java features.

Advanced Java Programming

SYLLABUS JAVA COURSE DETAILS. DURATION: 60 Hours. With Live Hands-on Sessions J P I N F O T E C H

Enterprise Java Unit 1-Chapter 2 Prof. Sujata Rizal Java EE 6 Architecture, Server and Containers

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

Chapter 2 WEBLOGIC SERVER DOMAINS. SYS-ED/ Computer Education Techniques, Inc.

Agenda. CFMX Hidden Gems. Not as Big, But Promoted. The Big New Things. Cookies Set Before CFLOCATION No Longer Lost!

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

Unit 5 JSP (Java Server Pages)

Java SE7 Fundamentals

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

Vision of J2EE. Why J2EE? Need for. J2EE Suite. J2EE Based Distributed Application Architecture Overview. Umair Javed 1

Couchbase: Ortus Railo Extension

COURSE 9 DESIGN PATTERNS

AN ISO 9001:2008 CERTIFIED COMPANY ADVANCED. Java TRAINING.

Anno Accademico Laboratorio di Tecnologie Web. Sviluppo di applicazioni web JSP

A- Core Java Audience Prerequisites Approach Objectives 1. Introduction

Basic object (component)

JAVA Training Overview (For Demo Classes Call Us )

Adobe ColdFusion Documentation. September 2014

Oracle 10g: Build J2EE Applications

BEAWebLogic Server and WebLogic Express. Programming WebLogic JNDI

Microsoft Exchange and.net Integration in ADOBE COLDFUSION 8

Rational Application Developer 7 Bootcamp

Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p.

Adobe ColdFusion (2016 release)

X100 ARCHITECTURE REFERENCES:

Specialized - Mastering JEE 7 Web Application Development

ColdFusion MX 7, Learning the new features

Techniques for Building J2EE Applications

Course Content for Java J2EE

JAVA. 1. Introduction to JAVA

Agent-Enabling Transformation of E-Commerce Portals with Web Services

Chapter 2 FEATURES AND FACILITIES. SYS-ED/ Computer Education Techniques, Inc.

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

The team that wrote this redbook

BEAWebLogic. Portal. Overview

A Gentle Introduction to Java Server Pages

GlassFish v2.1 & Enterprise Manager. Alexis Moussine-Pouchkine Sun Microsystems

FINALTERM EXAMINATION Spring 2009 CS506- Web Design and Development Solved by Tahseen Anwar

Servlet Fudamentals. Celsina Bignoli

About the Authors. Who Should Read This Book. How This Book Is Organized

Overview p. 1 Server-side Component Architectures p. 3 The Need for a Server-Side Component Architecture p. 4 Server-Side Component Architecture

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

6- JSP pages. Juan M. Gimeno, Josep M. Ribó. January, 2008

JSP. Basic Elements. For a Tutorial, see:

Advanced ColdFusion Printing and Reporting

Web Application Architecture (based J2EE 1.4 Tutorial)

Advanced Enterprise Debugging

Peers Techno log ies Pv t. L td. Core Java & Core Java &Adv Adv Java Java

Training topic: OCPJP (Oracle certified professional Java programmer) or SCJP (Sun certified Java programmer) Content and Objectives

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

Java Servlets. Preparing your System

Distributed Multitiered Application

Session 8. Reading and Reference. en.wikipedia.org/wiki/list_of_http_headers. en.wikipedia.org/wiki/http_status_codes

JAVA MICROSERVICES. Java Language Environment. Java Set Up. Java Fundamentals. Packages. Operations

Active Endpoints. ActiveVOS Platform Architecture Active Endpoints

X-S Framework Leveraging XML on Servlet Technology

1Z Oracle. Java Enterprise Edition 5 Enterprise Architect Certified Master

Introduction to Object Oriented ColdFusion

SUN Sun Certified Enterprise Architect for J2EE 5. Download Full Version :

Enterprise Java Unit 1- Chapter 3 Prof. Sujata Rizal Introduction to Servlets

PASSTCERT QUESTION & ANSWER

CFUnited Conference 1

Unraveling the Mysteries of J2EE Web Application Communications

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

Exam Questions 9A0-127

Zero Turnaround in Java Jevgeni Kabanov

Server and WebLogic Express

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

9A0-127 Exam Questions Demo Adobe. Exam Questions 9A Adobe ColdFusion 9 ACE Exam.

Core Java SYLLABUS COVERAGE SYLLABUS IN DETAILS

Advantage of JSP over Servlet

IBM Advanced Rational Application Developer v7. Download Full Version :

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

OBJECTIVES. After completing Concepts, you will be able to:

Chapter 2 Introduction

Transcription:

Overview MAX 2006 Beyond Boundaries Jason Delmore Developing ColdFusion-Java Hybrid Applications October 24 th 2006 ColdFusion is a productivity layer built on the strong foundation of J2EE. ColdFusion is a Rapid Application Development (RAD) environment with a rich feature set already built-in (Flex, Reporting, Document creation, etc). Java has advantages in scalability and has become the language of choice for open source projects. ColdFusion applications can deliver the best of both worlds: the strength of Java and the productivity of ColdFusion. This session will cover the interaction between ColdFusion and Java, and strategies for building powerful hybrid applications. 1 4 Biography Jason J Delmore Senior Product Manager, ColdFusion Adobe Systems Inc. Began developing complex applications with ColdFusion in 1999. Architected and led the development of several enterprise level applications primarily focused on Data collection and management Self-service Reporting E-commerce Integration Very experienced in leveraging Java from within ColdFusion. Why use ColdFusion and Java Together? The problem Although highly productive and easy to develop with, ColdFusion alone may not provide all of the functionality required to develop an enterprise-scale application Java applications typically take longer to develop and many tasks that are trivial to do in ColdFusion are far more complex in a standard Java development environment The solution ColdFusion provides quick and easy application development Java provides a robust solution set for developing enterprise-scale applications Hybrid applications leverage the ease of ColdFusion and the power of Java 2 5 Agenda Enhancing ColdFusion with Java Overview Why Use ColdFusion and Java Together? Enhancing ColdFusion with Java Using Java CFX Tags (APIs, Classes, EJBs, etc.) Using Custom JSP Tags Calling ColdFusion from Java classes? Limitations of Java in ColdFusion Pulling It All Together Some Suggestions Questions and Answers Where to Find Out More Leveraging the Java underpinnings of ColdFusion is easier than you think ColdFusion has been able to leverage Java since ColdFusion 4.5 It is far easier to leverage Java today, with many more capabilities and methods to do so! 3 6 1

Using Java CFX Tags ColdFusion Extension (CFX) tags were the first tool for integrating ColdFusion with Java Java CFX API (cfx.jar) available for development Allowed developers to extend the functionality of ColdFusion pages beyond CFML Using Java CFX Tags Example - HelloColdFusion (Continued) Create a CFM that uses the tag <cfx_hellocoldfusion name="inigo Montoya"/> Output is Hello, Inigo Montoya 7 10 Using Java CFX Tags Using Java CFX Tags Example - HelloColdFusion Let s write some simple code that uses the CFX API. Limitations of Java CFXs (there are many!) They are not standalone applications, they are created and invoked by the ColdFusion server This makes debugging more difficult This also makes the code less re-useable They must be registered within the ColdFusion Administrator They have poor datatype support (only strings and queries) They have no protection a poorly written CFX can crash the server 8 11 Using Java CFX Tags Example - HelloColdFusion (Continued) Compile the code javac -classpath C:\CFusionMX7\wwwroot\WEB-INF\lib\cfx.jar MyHelloColdFusion.java Register the CFX in the CF Administrator J2SE & J2EE APIs are available in ColdFusion by default Accessed using <CFOBJECT>, <CFINVOKE> or CreateObject() Static members available by default Instance members available after calling reserved init() method, or Instance members available after calling non-static method without calling init() (implicitly created with default constructor) 9 12 2

<CFOBJECT> Tag to load a Java classes <CFINVOKE> Tag to invoke methods If you do not create an object before calling a function with CFINVOKE, the tag will create a class object for just that method call and then throw the object away. CreateObject() Same as CFOBJECT but can be used in CFSCRIPT or CFSET Just My Opinion: Always use CreateObject()! Read file with an input stream - FileReader.cfm Reading from a large file one line at a time <cfset BufferSize = "8192"/> <cfset FileInputStream = CreateObject("java","java.io.FileInputStream")/> <cfset FileInputStream.init("C:\CFusionMX7\wwwroot\examples\fileToRead.txt")/> <cfset InputStreamReader = CreateObject("java","java.io.InputStreamReader")/> <cfset InputStreamReader.init(FileInputStream, "UTF-8")/> <cfset BufferedReader = CreateObject("java","java.io.BufferedReader")/> <cfset BufferedReader.init(InputStreamReader, BufferSize)/> <cfset BufferedReader.mark(BufferSize)/> <cfloop condition="bufferedreader.read() neq -1"> <cfset BufferedReader.reset()/> <cfoutput>#bufferedreader.readline()#</cfoutput><br/> <cfset BufferedReader.mark(BufferSize)/> </cfloop> <cfset BufferedReader.close()/> <cfset InputStreamReader.close()/> <cfset FileInputStream.close()/> 13 16 Example - StringBuffer Creating a StringBuffer object <!--- instantiate a StringBuffer class ---> <cfset StringBuffer = createobject("java","java.lang.stringbuffer")/> <!--- create a StringBuffer instance, analog to java new() ---> <cfset StringBuffer.init("Hello ")/> <!--- append to the buffer ---> <cfset StringBuffer.append("World!")/> <cfoutput>#stringbuffer.tostring()#</cfoutput> Serialize a ColdFusion Object - SerializeDeserialize.cfm Serialize and Deserialize ColdFusion objects (Not CFCs) Struct Array Query Any object that implements the java.io.serializable interface <!--- reverse the buffer ---> <cfset StringBuffer.reverse()/> <cfoutput>#stringbuffer.tostring()#</cfoutput> 14 17 Example - StringBuffer Output from example Hello World!!dlroW olleh An Enterprise Java Bean (EJB) is a java object that is managed by the container in which it is hosted, and provides Scalability features (clustering, pooling, caching, etc) Transaction management Fine-grained security And more EJBs in ColdFusion ColdFusion cannot host EJBs; however, it can use EJBs hosted by the J2EE server it is deployed on Hidden feature: A ColdFusion String extends java.lang.string and so it responds to all of the functions for java.lang.string! 15 18 3

Example Calling an EJB from a ColdFusion page <!--- Create the InitialContext ---> <cfset context = CreateObject("java", "javax.naming.initialcontext")/> <!--- Locate the EJB and obtain a reference ---> <cfset home = context.lookup("employee")/> <!--- Create an instance of the EJB ---> <cfset employee = home.create()/> Create a CFC that makes your calls to the Java API Create a custom tag for accessing that CFC its much easier than you think Just drop a CFM defining the tags actions in the cfroot/customtags directory Now you can call it via tag syntax, or call the CFC directly! (CFC syntax can be used in CFSCRIPT) <!--- Get the name for a given employee ---> <cfset employeename= employee.getname("12345")/> 19 22 Any Java API or Java class can also be used in ColdFusion Classes must be available to either the JVM classpath or the ColdFusion classpath By default CF ClassLoader will load cfroot/lib cfroot/gateway/lib The J2EE container will load cfroot/web-inf/lib cfroot/web-inf/classes My Suggestion: Add you own directory to the CF Classpath Leveraging JExcel API to build Excel Documents in ColdFusion Files Involved cfroot/wwwroot/com/delmore/jxl.cfc CFC that calls JXL API cfroot/customtags/jxl.cfm Custom Tag CF_JXL cfroot/customtags/jxlparam.cfm Custom Tag CF_JXLPARAM cfroot/wwwroot/examples/usejxlcfc.cfm Template calling CFC cfroot/wwwroot/examples/usejxltag.cfm Template calling Tags 20 23 Adding your own classpath to ColdFusion For ColdFusion Standalone: In the ColdFusion administrator, click on "Java and JVM", then add the absolute paths to your jar or class files in the "Class Path" field. For JRun Deployment: Open up the JRun Management Console and under the default server, click on settings, then add your classes to the class path list. For other app servers or when in doubt, you can edit cfroot/runtime/bin/jvm.config. # Arguments to VM java.args= -Dcoldfusion.classPath={application.home}/../lib/updates Add your path to the coldfusion.classpath not the java.class.path. The PageContext class is an abstract class designed to be extended and implemented for specific JSP engine runtime environments Provides facilities to: Write output to the client Manage scoped namespaces Manage session usage by page Redirect requests to another resource Include other pages within the same request Handle exception processing 21 24 4

List the members of the PageContext class - DumpPageContext.cfm <!--- List the members of PageContext ---> <cfdump var="#getpagecontext()#" /> Accessing a JSP page from a ColdFusion page - JSPInclude.cfm <!--- Include the Header ---> <cfset getpagecontext().include("header.jsp") /> <!--- Include Body for content ---> <cfinclude template="body.cfm"/> <!--- Include the Footer ---> <cfset getpagecontext().include("footer.jsp")/> 25 28 List the HTTP headers for the current request - GetHeaders.cfm <!--- Get the ServletRequest from PageContext ---> <cfset servletrequest = getpagecontext().getrequest()/> <!--- Get an Enumeration of Header names ---> <cfset names = servletrequest.getheadernames()/> <p>request Headers</p> <cfloop condition="#names.hasmoreelements()#"> <cfset next = names.nextelement() /> <cfoutput> <b>#next#</b> - #servletrequest.getheader(next)# </cfoutput> </cfloop> To access a servlet that exposes the same functionality, you use the same code. For example, to run a servlet called HelloWorldServlet put the servlet class file in the serverroot/web-inf/classes directory refer to the servlet with the URL /servlet/helloworldservlet <!--- Include the servlet ---> <cfset getpagecontext().include("/servlet/helloworldservlet")/> Note: You do NOT have to modify web.xml for this to work. 26 29 ColdFusion pages, JSP pages and Servlets can interoperate in several ways ColdFusion pages can invoke JSP pages and Servlets JSP pages and Servlets can invoke ColdFusion pages ColdFusion pages, JSP pages and Servlets share data in the Request, Session, and Application scopes (Note: Shared Request scope variable names in JSP pages or servlets must be all-lowercase.) Accessing a ColdFusion page from a JSP page - CallingCF.jsp <jsp:include page="header.cfm"> <jsp:param name="title" value="coldfusion-java Hybrid"/> </jsp:include> <!--- Get the body Content from Header.cfm file ---> <p><%= request.getattribute("bodycontent") %></p> <!--- Include the Footer ---> <%@ include file="footer.jsp" %> <!--- Header.cfm ---> <cfsetting showdebugoutput="no"/> <html> <head><title><cfoutput>#url.title#</cfoutput></title></head> <body> The title is <cfoutput>#url.title#</cfoutput> <cfset request.bodycontent = "Here is the body content."/> 27 30 5

Using Custom JSP Tags Using Custom JSP Tags Custom JSP tags allow functionality to be boxed and reused across applications Example - Jakarta String Tag Library - JSPTagLib.cfm Output from example Custom JSP tags: Can be customized via attributes from the calling page Have access to shared scopes Can modify the response generated by the calling page Can communicate with each other (Create a variable that refers to a bean in one tag and then use the same bean in another tag) Can be nested within one another Are a lot like ColdFusion tags! 31 34 Using Custom JSP Tags Using Custom JSP Tags To use a custom tag Put the tag library, consisting of the taglibname.jar file, and the taglibname.tld file, if one is supplied, in the web_root/web-inf/lib directory. The JSP custom tag library must be in this directory for you to use the cfimport tag. Restart ColdFusion. In the ColdFusion page that uses a JSP tag from the tag library, specify the tag library name in a cfimport tag; for example: <cfimport taglib="/web- INF/lib/random.jar" prefix="random"> Why use custom JSP tags vs. ColdFusion custom tags? Leverage existing expanse of publicly available JSP tag libraries (Jakarta Taglibs Project and others) Leverage JSP tag libraries already developed within your organization Interoperate with existing J2EE systems within your organization that implement JSP tag libraries Note: The cfimport tag must be on the page that uses the imported tag. You cannot put the cfimport tag in Application.cfm. Use the custom tag using the form <prefix:tagname> 32 35 Using Custom JSP Tags Calling ColdFusion from Java classes? Example - Jakarta String Tag Library Importing and using a JSP Tag Library in ColdFusion First, put taglibs-string.tld, taglibs-string.jar, and commons-lang-2.1.jar in WEB-INF/lib <!--- JSPTagLib.cfm---> <!--- Import the tag library ---> <cfimport taglib="/web-inf/lib/taglibs-string.jar" prefix="string"> <string:capitalize>capitalize the first letter of each word for me</string:capitalize><br/> <string:split var="splitstring" separator=" ">split my string</string:split><br/> <cfdump var="#splitstring#"/><br/> <string:split var="splitstring" separator=" ">split my string</string:split> <string:wordwrap width ="20" delimiter="<br/>">word-wrap a String. This involves formatting a string to fit in character width of page.</string:wordwrap> Starting with ColdFusion 7.0.1, you can call ColdFusion Components (CFCs) from Java classes using the CFCProxy API. To call a CFC, the class must be in the ColdFusion Classpath (set in the Administrator/jvm.config) To compile, you will need cfusion.jar in your classpath javac.exe -classpath C:\CFusionMX7\lib\cfusion.jar CFCInvoker.java 33 36 6

Calling ColdFusion from Java classes? Calling a CFC from a Java class Files Involved cfroot/wwwroot/com/delmore/cfcinvoker.java cfroot/wwwroot/com/delmore/cfcinvoker.class Java source file Java class file cfroot/wwwroot/com/delmore/dataholder.cfc CFC that returns a struct cfroot/wwwroot/invoker.cfm Template that instantiates CFCInvoker Putting It All Together What we already knew ColdFusion is the tool of choice for developing feature rich applications quickly and easily! Java provides a solid set of tools for developing powerful, enterprisescale applications What we ve learned ColdFusion provides many ways of leveraging Java and related technologies! Hybrid applications are powerful! They leverage the productivity and richness of ColdFusion as well as the strength and ubiquity of Java 37 40 Calling ColdFusion from Java classes? Caveats This is not a well documented feature It s for advanced users only There are some situations where this can be very useful but in general there are less complex ways to achieve the same goal. Beware the configuration the java class must be in the ColdFusion classpath and you must compile with the same JVM version the server is running. Some Suggestions Keep it Easy! Abstract the Java! Use CFCs as wrappers to your Java API calls If you want to use your functionality as a custom tag, add a CFM that passes on the tag attributes to a function in your CFC Use createobject() Create an init function in your CFCs, have it return this Set a coding standard for variable names that includes how to handle case Use Application.cfc 38 41 Limitations of Java in ColdFusion Questions and Answers There are some limitations of Java in ColdFusion Object construction init() method conflicts Overloaded methods, resolving ambiguity with JavaCast() ColdFusion case insensitivity For example, JSPs must use all lowercase characters to refer to all request scope variables shared with CFML pages. You can use any case on the CFML page, but if you use mixed case to all uppercase on the JSP page, the variable will not get its value ColdFusion page. Changes to compiled Java classes or.jar files require restart Got a question? Now s the time! 39 42 7

Where to Learn More ColdFusion Developer Center Java and J2EE Architecture http://www.adobe.com/devnet/coldfusion/java_j2ee.html LiveDocs Integrating J2EE and Java Elements in CFML Applications http://livedocs.macromedia.com/coldfusion/7/htmldocs/00001557.htm Reality ColdFusion: J2EE Integration http://www.forta.com/books/0321129482/ 43 44 8