Software Architecture for ColdFusion Developers Unit 4: Application Events and Global Variables.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

Advanced Web Metrics with Google Analytics By: Carley Brown.
Error Handling With Fusebox Presentation By Eron Cohen.
 Copyright Wipro Technologies JSP Ver 1.0 Page 1 Talent Transformation Java Server Pages.
The Web Warrior Guide to Web Design Technologies
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
1 Chapter 12 Working With Access 2000 on the Internet.
An introduction to Java Servlet Programming
Chapter 16 Dynamic HTML and Animation The Web Warrior Guide to Web Design Technologies.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Copyright W. Howden1 Lecture 19: Intro to O/O Components.
Week 2 IBS 685. Static Page Architecture The user requests the page by typing a URL in a browser The Browser requests the page from the Web Server The.
Client State Management & Application Security  Client State Management  Concept  ASP Examples  Application Security  Database Based Approach 
JSP Architecture  JSP is a simple text file consisting of HTML or XML content along with JSP elements  JSP packages define the interface for the compiled.
TIBCO Designer TIBCO BusinessWorks is a scalable, extensible, and easy to use integration platform that allows you to develop, deploy, and run integration.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
UNIT-V The MVC architecture and Struts Framework.
CVSQL 2 The Design. System Overview System Components CVSQL Server –Three network interfaces –Modular data source provider framework –Decoupled SQL parsing.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
1 CIS336 Website design, implementation and management (also Semester 2 of CIS219, CIS221 and IT226) Lecture 9 JavaServer Pages (JSP) (Based on Møller.
Exception Handling MDCFUG 6/12/2007 David Lakein Programmer / Analyst TeraTech Inc.
Using JavaBeans and Custom Tags in JSP Lesson 3B / Slide 1 of 37 J2EE Web Components Pre-assessment Questions 1.The _____________ attribute of a JSP page.
Data File Access API : Under the Hood Simon Horwith CTO Etrilogy Ltd.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
© 2006 IBM Corporation IBM WebSphere Portlet Factory Architecture.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Week 7 IBS 685. Displaying an Image using CFOUTPUT 1.Save images in a folder under wwwroot directory 2.Create a database column and name it e.g. imagefilename.
Introduction to Model-Glue Rachel Lehman Perpetual Intermediate Designer-Developer Introduction to Model-Glue.
Chapter 8 Cookies And Security JavaScript, Third Edition.
JAVA SERVER PAGES. 2 SERVLETS The purpose of a servlet is to create a Web page in response to a client request Servlets are written in Java, with a little.
1 ® Copyright 2009 Adobe Systems Incorporated. All rights reserved. Adobe confidential. 1 Building Portlets with ColdFusion Pete Freitag Foundeo, Inc.
16-Oct-15 JSP Implicit Objects. 2 JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
1 Maryland ColdFusion User Group Session Management December 2001 Michael Schuler
March 12 & 13, 2007 IIS 7.0 for CFML Developers Deploying on IIS 7.0 with Adobe ColdFusion and New.
Chapter 6 Server-side Programming: Java Servlets
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
Navigation Framework using CF Architecture for a Client-Server Application using the open standards of the web Kedar Desai presented by.
Advanced ColdFusion: Error Handling Mosh Teitelbaum evoch, LLC.
Application.cfm tips and Tricks Michael Smith President TeraTech, Inc ColdFusion, database & VB custom development and training.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
CF101: Welcome to ColdFusion Simon Horwith CTO, Etrilogy Ltd.
Caching for Performance Jeff Tapper Tapper.net Consulting.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
Using Derrick Rapley Maryland CFUG January 8, 2002.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
CSI 3125, Preliminaries, page 1 SERVLET. CSI 3125, Preliminaries, page 2 SERVLET A servlet is a server-side software program, written in Java code, that.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP (COMPONENTS) Active Server Pages (cont..) 1. global.asa file The Global.asa file is an optional file that can contain declarations of objects, variables,
ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
Overview of Previous Lesson(s) Over View  ASP is a technology that enables scripts in web pages to be executed by an Internet server.  ASP.NET is a.
IMS 3253: Validation and Errors 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Validation and Error Handling Validation.
Introduction to Javascript. What is javascript?  The most popular web scripting language in the world  Used to produce rich thin client web applications.
Navigation Framework using CF Architecture for a Client-Server Application using the open standards of the Web presented by Kedar Desai Differential Technologies,
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
Using Structures With CFCs By Selene Bainum. June 27 th - 30 th 2007www.cfunited.com Why Am I here? Familiar with structures Familiar with ColdFusion.
Introduction to Macromedia Coldfusion MX 7, Part III Gateways, Charting, Searching, and other new goodness Presented by the Mid-Michigan Coldfusion User’s.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
111 State Management Beginning ASP.NET in C# and VB Chapter 4 Pages
National College of Science & Information Technology.
Pre assessment Questions
Topics Introduction to File Input and Output
Nate Nelson I*LEVEL, Inc.
Knowledge Byte In this section, you will learn about:
Pre-assessment Questions
Topics Introduction to File Input and Output
Presentation transcript:

Software Architecture for ColdFusion Developers Unit 4: Application Events and Global Variables

Unit Objectives At the end of this unit, students will: –Understand the Application framework in ColdFusion MX 7 and how it differs from that of prior versions –Be comfortable defining applications and application event handlers in Application.cfc –Be able to describe the various global variable scopes and their uses

Unit Overview Application Framework Overview Application.cfc Global Variable Scopes Application Events

Application Framework Overview Once you have a database and application design, and the directory structure is in place, use the application framework to: –Define application settings –Handle application events –Create and/or manipulate global variables application variables session variables request variables

Application Framework Overview cont’d Before ColdFusion MX 7 –Application.cfm ran before each request –OnRequestEnd.cfm ran after each request –When a page is requested, ColdFusion: looked in the local directory for Application.cfm If no Application.cfm is found it traverses up the directory structure to the root drive, looking for one on each pass The first time Application.cfm is found, it is processed before the page being requested and CF stops looking If an Application.cfm was found, after the requested page runs, CF looks in the same directory as Application.cfm for a file named OnRequestEnd.cfm and, if found, runs it

Application Framework Overview cont’d In ColdFusion MX 7 –ColdFusion still looks in the current directory and then traverses to the root, but now it first looks for Application.cfc –If no Application.cfc is found, it looks in that directory for Application.cfm –If Application.cfc is found, ColdFusion creates an instance of the component and uses it’s data and methods –If no Application.cfc is found but Application.cfm is found, ColdFusion behaves as it did in prior versions (including Application.cfm, then the requested page, then OnRequestEnd.cfm if one exists in that directory)

Application.cfc – What is it? Application.cfc is a ColdFusion Component! This component contains: –Application settings definitions –Method definitions to handle application events –Any other code that’s valid inside a CFC

Defining Application Settings Prior to ColdFusion MX 7 application settings were defined with the tag <cfapplication name="myApp" applicationtimeout="#createTimeSpan(2,0,0,0) #" sessionmanagement="true" sessiontimeout="#createTimeSpan(0,0,20,0)#">

Defining Application Settings cont’d In CFMX 7 these settings retain the same names as the attributes but are defined in the Application.cfc “this” scope outside of any methods this.name = "myApp"; this.applicationtimeout = createTimeSpan(2,0,0,0); this.sessionmanagement = true; this.sessiontimeout = createTimeSpan(0,0,20,0);

Global Variable Scopes Use the application scope for data values and component instances that rarely change and are shared by all users Use the session scope for data values and component instances that must persist or rarely change and are user (session) specific Use request scope for data values and component instances that change frequently or have no need to persist

Application Events Application Starts for the first time User sends first request – session starts Request begins Request is processed Request ends Eventually, the session expires Eventually, the application expires due to inactivity or a server restart During any of the above, errors can occur in pages!

Application Event Handlers A special function name is used for a method to handle each of the application events: –onApplicationStart() –onSessionStart() –onRequestStart() –onRequest() –onRequestEnd() –onSessionEnd() –onApplicationEnd() –onError() These methods are thread safe - locking is not necessary!

Events Prior to ColdFusion MX 7 Prior to ColdFusion MX 7: –Application.cfm mimics onRequestStart() –onRequestEnd.cfm mimics onRequestEnd() –Conditional logic in Application.cfm mimics onSessionStart() –CFERROR in Application.cfm mimics onError() –Accessing the servlet response buffer in onRequestEnd.cfm ‘kind of’ mimics onRequest() –There is no good way to mimic onSessionEnd()!!

Application Events – onApplicationStart() Code that is run only when an application initializes is contained inside a function named “onApplicationStart” ReturnType: Boolean (optional if no returntype is specified in the function definition) Arguments: None Application doesn’t start if false is returned or error thrown Popular Uses –Set global variables and cached queries in the application scope –Contact Administrator ( /SMS)?

onApplicationStart() Code Sample var done = false; // set some application scope variables application.dsn = "myDSN"; application.dbUser = "myDBUser"; application.dbPass = "myDBPass"; done = true;

Application Events – onApplicationEnd() Code that is run only when an application expires (due to activity timeout or elegant server shutdown) is contained inside a function named “onApplicationEnd” ReturnType: void Arguments: ApplicationScope (struct) This method cannot access session or request scopes and can only access application scope as an argument – server scope is accessible Popular Uses –Clean-up application data and/or processes –Contact Administrator ( /SMS)?

onApplicationEnd() Code Sample var logMsg = "Application shut down with the following keys in the application scope: " & structKeyList(arguments.appScope); #logMsg#

Session Events – onSessionStart() Code that is run the first time a user makes a request is contained inside a function named “onSessionStart” ReturnType: None Arguments: None Popular Uses –Initialize session variables –Authentication and other user security-related code –Write to log file or database

onSessionStart() Code Sample session.objUser = createObject("component", "user");

Session Events – onSessionEnd() Code that is run when a session ends just prior to the session being removed from memory (due to activity timeout or closing the browser if using J2EE sessions) is contained inside a function named “onSessionEnd” ReturnType: void Arguments: SessionScope (struct), ApplicationScope (struct) Application and session scopes only accessible as arguments, server scope accessible, request scope unavailable Popular Uses –Clean-up session data and/or processes –Write to log file or database

onSessionEnd() Code Sample var logMsg = "Session ID " & arguments.sessionScope.jSessionID & "ended";

Request Events – onRequestStart() Code that is run when a request begins (just prior to the requested page being executed) is contained inside a function named “onRequestStart” ReturnType: Boolean (optional if no returntype is specified in the function definition) Arguments: targetPage (string) Request isn’t processed if false is returned or error thrown Popular Uses –Any business logic that needs to be performed on every request, such as user authorization or setting request specific variables

onRequestStart() Code Sample var allow = session.objUser.allowAccess(arguments.target);

Request Events – onRequestEnd() Code that is run after a request is processed but before the output is returned to the client is contained inside a function named “onRequestEnd” ReturnType: void Arguments: TargetPage (string) Popular Uses –Any business logic that needs to be performed after every request, such as performing data clean-up or performance metrics analysis of some sort

onRequestEnd() Code Sample

Request Events – onRequest() Code that must intercept a request is contained inside a function named “onRequest” ReturnType: void Arguments: TargetPage (string) Using this method intercepts the requested page and makes the CFC the request – i.e. you must manually include any resource to send back to the client. Using this method makes the variables scope of any requested page that’s included visible to other Application.cfc methods Do not use this method if there are CFCs accessed via SOAP or remoting that are effected by Application.cfc Popular Uses –In order to intercept and/or manipulate the output stream (the output generated by the requested page) generated by a requested resource – for example, you could append/prepend text, replace specific characters or words, etc. by including the resource requested in a and could manipulate that content before returning it to the client

onRequest() Code Sample var retText = ""; retText = replaceNoCase(retText, "Simon", "King Simon", "All"); writeOutput(retText);

Error Events – onError() Code that is run whenever an unhandled exception occurs is contained inside a function named “onError” ReturnType: void Arguments: Exception (struct), EventName (string) Event name argument holds name of Application.cfc event that threw exception – is an empty string if onRequest() isn’t used and the error wasn’t thrown by an event method Overrides any or CFAdmin error settings Cannot display anything to users if the error occurred in onApplicationEnd() or onSessionEnd() If onError() throws an exception, it’s handled by tags in the Application.cfc initializatoin block and by CFAdmin error pages Popular Uses –Error handling

onError() Code Sample

Other Information You can add other methods to Application.cfc Application.cfc can extend other components You can manually call Application.cfc methods – one great use for this is manually resetting a session If you manually call an event – the scope is not locked

Summary The first code you write in an application should be to define the application, handle events, and set global variables Application.cfc is a ColdFusion Component with 8 reserved method names for handling events Prior to CFMX 7, Application.cfm was used to implement a more limited application framework Application settings are stored in the Application.cfc “this” scope Global variables are defined in application events, as is any code that must execute when an application event occurs

Q&A Questions?