ColdFusion Internals 
Paul Nibin K J 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Introduction 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
2 
Client 
Web Server
Agenda 
 Life of a CFM request 
 Classloading in ColdFusion 
 How does RESTful web service work? 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
3
Life of a request 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 4
Life of request in ColdFusion 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
5
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
Template Classloader 
In filter chain 
6 
1. 
Request 
Validation 
• Validates 
the 
request. 
2. Path 
Resolution 
• Resolve 
s 
absolute 
CFM 
Path 
3.Application 
Resolution 
• Locates 
Applicati 
-on. 
• Creates 
Applicati 
-on 
scope. 
• Invokes 
life cycle 
method 
4. Parse 
• Parse 
the CFM 
file . 
• Generat 
e AST 
using the 
grammar 
. 
5.Bytecod 
e 
Generatio 
n • Translat 
e the 
AST to 
java byte 
code
1. Request Validation 
 You are part of request validation too. 
 You can configure the following validations through settings. 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
7 
 Request Size Limits 
 Request Limits
2. Path Resolution 
http://localhost/employee/addEmployee.cfm 
/employee/addEmployee.cfm 
C:inetpubwwwrootemployeeaddEmployee.cfm 
Request URL 
Virtual Path 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
8 
Absolute 
Path 
Connector 
You can cache the web server path using an admin setting.
3. Application Resolution 
 Finds the Application.cfc 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
9 
 Creates Application Scope 
 Invokes Life cycle methods 
 OnApplicationStart() 
 OnRequestStart() 
 OnError()
3. Application Resolution 
 Finds the Application.cfc 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
10 
 Creates Application Scope 
 Invokes Life cycle methods 
 OnApplicationStart() 
 OnRequestStart() 
 OnError() 
Start 
Check for the 
Application.cfc in 
current directory. 
Found 
Application.cf 
c? 
Found Application 
Check for the 
Application.cfc in 
parent directory. 
Yes 
No 
Setting to specify till what level 
ColdFusion should search for 
Application.cfc
Unnamed applications 
http://localhost/axis1Test/basic.cfc?wsdl 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
axis1Test 
11 
Application.cfc 
<cfcomponent> 
<cfset this.wssettings.version.publish=“1”> 
</cfcomponent> 
basic.cfc 
axis2Test 
Application.cfc 
<cfcomponent> 
<cfset this.wssettings.version.publish=“2”> 
</cfcomponent> 
basic.cfc 
http://localhost/axis2Test/basic.cfc?wsdl 
ColdFusion disables the creation of un named applications using an 
admin setting.
4. Parsing 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
12 
<cfscript> 
function hello() { 
writeOutput("hello"); 
} 
hello(); 
</cfscript> 
Template 
Reader 
Abstract Syntax Tree (AST)
4. Parsing 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
13 
<cfscript> 
function hello() { 
writeOutput("hello"); 
} 
hello(); 
</cfscript> 
Template 
Reader 
Abstract Syntax Tree (AST)
Template Reader 
 Reads the CFM and creates a stream. 
Encoding? 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
14
Automatic encoding identification 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
15 
Start 
Use 
encoding 
Is BOM 
present? 
Guess 
encoding 
(icu4j) 
Is guess 
probability 
100%? 
End 
Yes 
Yes 
No 
Save the file with 
BOM 
<cfprocessingdirective 
..> 
Use system 
encoding 
End 
No 
-Dfile.encoding=“”
5. Byte code generation 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
AST 
<cfusion_Root>wwwrootWEB-INF 
16 
Byte Code 
Engineering Library 
(BCEL) 
cfclasses 
Byte Code
Template Classloader 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
17 
Start 
Is 
class 
in 
cache 
? 
Check Last 
Modified Date of 
CFM 
Is 
Modifie 
d? 
Parse 
Generate 
byte code 
Load byte 
code 
End 
Use cached Class 
No 
Yes 
No 
Yes 
Clear template 
cache 
Enable trusted 
cache
Summary 
 ColdFusion filter chain has 5 main phases 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
18 
1. Request Validation 
o Settings in administrator 
2. Path Resolution 
o Cache web server path setting 
3. Application Resolution 
o Finding Application.cfc 
o Unnamed applications 
4. Parsing 
o File encoding 
5. Bytecode generation 
o Template Classloader
Classloading 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 19
Class Loading 
 -Dcoldfusion.classPath = {application.home}/lib/updates, 
{application.home}/lib,{application.home}/lib/axis2,{application.home}/gat 
eway/lib/,… 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
20 
 In jvm.config 
ClassLoader 
cfusion/lib 
cfusion/lib/update 
s 
cfusion/lib/axis 
2
Prior to CF10 
Create a folder in cfusionlib. 
Copy your jars to the new folder. 
Edit jvm.config to add the new folder to the end of coldfusion.classPath 
property 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
21 
Cons 
 Conflicts 
 May hamper normal server functioning. 
 Any changes in jar files need server restart to take effect.
CF10 and afterwards 
 CF10 introduced enhanced java integration. 
 Application setting available to specify custom classpath. 
 <cfset this.javaSettings = {LoadPaths = [".java_lib",".javamyjar.jar"], 
reloadOnChange = false}> 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
22 
Pros 
 Complete isolation 
 Will not affect server functioning 
 Allows reloading
RESTful web services 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 23
RESTful web services 
 The W3C defines a Web service as: 
a software system designed to support interoperable 
machine-to-machine interaction over a network. 
 A webservice becomes RESTful when the following 4 constraints are 
satisfied. 
1. Addressability 
2. Multiple Representations 
3. Uniform and constrained interfaces 
4. Stateless communication 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
How does RESTful web service work? 
 Two logical sections 
Registratio 
n 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
Usage
Why? 
Traditional web service 
POST /students/StudentsService HTTP/1.1 
Host: http://localhost:8500 
Content-Type: soap/xml 
<Envelope> 
<Header></Header> 
<Body> 
<GetStudent> 
<Id>112</Id> 
</GetStudent> 
</Body> 
<Envelope> 
RESTful web service 
GET /students/112 HTTP/1.1 
Host: http://localhost:8500 
Accepts: text/html 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
Registration Workflow 
 Registration is the process of making your service ready for use. 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
27 
Register 
application 
Scanning 
for REST 
CFC 
Generate 
skeleton 
Annotate 
skeleton 
Register 
with Jersey 
 Inputs: Application Root Path and Service Name
Settings 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
28 
Register 
application 
Scanning 
for REST 
CFC 
• restsettings.cfclocatio 
n 
Generate 
skeleton 
• restsettings.skipCFCWithE 
rror 
Annotate 
skeleton 
Register 
with Jersey
Usage Workflow 
 Inputs: HTTP request 
 The URL of the request 
 HTTP Headers 
 Body of the request 
 Query params, Cookies, Matrix params etc.. 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
29
Explaning the URL 
 http:// + localhost:8500 + /rest + /examples + /helloworld 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
30 
http • The protocol 
localhost:8500 • Server address and port 
• Context path used to identify the request as a 
REST request rest 
examples • The application name used during registration 
helloworld • restPath defined in the CFC
Request Workflow 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
31 
Identify 
REST 
request 
Identifies 
application 
Identifies 
CFC 
Identifies 
function 
Invokes 
Function
Settings 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
32 
Identify 
REST 
request 
• Change context 
path in web.xml 
Identifies 
application 
• Can make 
application default if 
needed 
Identifies 
CFC 
Identifies 
function 
Invokes 
Function 
• use custom 
serializer to modify 
response
Summary 
 RESTful web services introduction 
 Why RESTful web service needs to be registered first? 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 
33 
 Registration workflow 
o Settings 
 Request Workflow 
 Settings
Q & A 
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 34 
pnibinkj@adobe.com 
http://blogs.coldfusion.com/
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

ColdFusion Internals

  • 1.
    ColdFusion Internals PaulNibin K J © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  • 2.
    Introduction © 2014Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 2 Client Web Server
  • 3.
    Agenda  Lifeof a CFM request  Classloading in ColdFusion  How does RESTful web service work? © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 3
  • 4.
    Life of arequest © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 4
  • 5.
    Life of requestin ColdFusion © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 5
  • 6.
    © 2014 AdobeSystems Incorporated. All Rights Reserved. Adobe Confidential. Template Classloader In filter chain 6 1. Request Validation • Validates the request. 2. Path Resolution • Resolve s absolute CFM Path 3.Application Resolution • Locates Applicati -on. • Creates Applicati -on scope. • Invokes life cycle method 4. Parse • Parse the CFM file . • Generat e AST using the grammar . 5.Bytecod e Generatio n • Translat e the AST to java byte code
  • 7.
    1. Request Validation  You are part of request validation too.  You can configure the following validations through settings. © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 7  Request Size Limits  Request Limits
  • 8.
    2. Path Resolution http://localhost/employee/addEmployee.cfm /employee/addEmployee.cfm C:inetpubwwwrootemployeeaddEmployee.cfm Request URL Virtual Path © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 8 Absolute Path Connector You can cache the web server path using an admin setting.
  • 9.
    3. Application Resolution  Finds the Application.cfc © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 9  Creates Application Scope  Invokes Life cycle methods  OnApplicationStart()  OnRequestStart()  OnError()
  • 10.
    3. Application Resolution  Finds the Application.cfc © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 10  Creates Application Scope  Invokes Life cycle methods  OnApplicationStart()  OnRequestStart()  OnError() Start Check for the Application.cfc in current directory. Found Application.cf c? Found Application Check for the Application.cfc in parent directory. Yes No Setting to specify till what level ColdFusion should search for Application.cfc
  • 11.
    Unnamed applications http://localhost/axis1Test/basic.cfc?wsdl © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. axis1Test 11 Application.cfc <cfcomponent> <cfset this.wssettings.version.publish=“1”> </cfcomponent> basic.cfc axis2Test Application.cfc <cfcomponent> <cfset this.wssettings.version.publish=“2”> </cfcomponent> basic.cfc http://localhost/axis2Test/basic.cfc?wsdl ColdFusion disables the creation of un named applications using an admin setting.
  • 12.
    4. Parsing ©2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 12 <cfscript> function hello() { writeOutput("hello"); } hello(); </cfscript> Template Reader Abstract Syntax Tree (AST)
  • 13.
    4. Parsing ©2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 13 <cfscript> function hello() { writeOutput("hello"); } hello(); </cfscript> Template Reader Abstract Syntax Tree (AST)
  • 14.
    Template Reader Reads the CFM and creates a stream. Encoding? © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 14
  • 15.
    Automatic encoding identification © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 15 Start Use encoding Is BOM present? Guess encoding (icu4j) Is guess probability 100%? End Yes Yes No Save the file with BOM <cfprocessingdirective ..> Use system encoding End No -Dfile.encoding=“”
  • 16.
    5. Byte codegeneration © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. AST <cfusion_Root>wwwrootWEB-INF 16 Byte Code Engineering Library (BCEL) cfclasses Byte Code
  • 17.
    Template Classloader ©2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 17 Start Is class in cache ? Check Last Modified Date of CFM Is Modifie d? Parse Generate byte code Load byte code End Use cached Class No Yes No Yes Clear template cache Enable trusted cache
  • 18.
    Summary  ColdFusionfilter chain has 5 main phases © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 18 1. Request Validation o Settings in administrator 2. Path Resolution o Cache web server path setting 3. Application Resolution o Finding Application.cfc o Unnamed applications 4. Parsing o File encoding 5. Bytecode generation o Template Classloader
  • 19.
    Classloading © 2014Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 19
  • 20.
    Class Loading -Dcoldfusion.classPath = {application.home}/lib/updates, {application.home}/lib,{application.home}/lib/axis2,{application.home}/gat eway/lib/,… © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 20  In jvm.config ClassLoader cfusion/lib cfusion/lib/update s cfusion/lib/axis 2
  • 21.
    Prior to CF10 Create a folder in cfusionlib. Copy your jars to the new folder. Edit jvm.config to add the new folder to the end of coldfusion.classPath property © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 21 Cons  Conflicts  May hamper normal server functioning.  Any changes in jar files need server restart to take effect.
  • 22.
    CF10 and afterwards  CF10 introduced enhanced java integration.  Application setting available to specify custom classpath.  <cfset this.javaSettings = {LoadPaths = [".java_lib",".javamyjar.jar"], reloadOnChange = false}> © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 22 Pros  Complete isolation  Will not affect server functioning  Allows reloading
  • 23.
    RESTful web services © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 23
  • 24.
    RESTful web services  The W3C defines a Web service as: a software system designed to support interoperable machine-to-machine interaction over a network.  A webservice becomes RESTful when the following 4 constraints are satisfied. 1. Addressability 2. Multiple Representations 3. Uniform and constrained interfaces 4. Stateless communication © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  • 25.
    How does RESTfulweb service work?  Two logical sections Registratio n © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Usage
  • 26.
    Why? Traditional webservice POST /students/StudentsService HTTP/1.1 Host: http://localhost:8500 Content-Type: soap/xml <Envelope> <Header></Header> <Body> <GetStudent> <Id>112</Id> </GetStudent> </Body> <Envelope> RESTful web service GET /students/112 HTTP/1.1 Host: http://localhost:8500 Accepts: text/html © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.
  • 27.
    Registration Workflow Registration is the process of making your service ready for use. © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 27 Register application Scanning for REST CFC Generate skeleton Annotate skeleton Register with Jersey  Inputs: Application Root Path and Service Name
  • 28.
    Settings © 2014Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 28 Register application Scanning for REST CFC • restsettings.cfclocatio n Generate skeleton • restsettings.skipCFCWithE rror Annotate skeleton Register with Jersey
  • 29.
    Usage Workflow Inputs: HTTP request  The URL of the request  HTTP Headers  Body of the request  Query params, Cookies, Matrix params etc.. © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 29
  • 30.
    Explaning the URL  http:// + localhost:8500 + /rest + /examples + /helloworld © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 30 http • The protocol localhost:8500 • Server address and port • Context path used to identify the request as a REST request rest examples • The application name used during registration helloworld • restPath defined in the CFC
  • 31.
    Request Workflow ©2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 31 Identify REST request Identifies application Identifies CFC Identifies function Invokes Function
  • 32.
    Settings © 2014Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 32 Identify REST request • Change context path in web.xml Identifies application • Can make application default if needed Identifies CFC Identifies function Invokes Function • use custom serializer to modify response
  • 33.
    Summary  RESTfulweb services introduction  Why RESTful web service needs to be registered first? © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 33  Registration workflow o Settings  Request Workflow  Settings
  • 34.
    Q & A © 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 34 pnibinkj@adobe.com http://blogs.coldfusion.com/
  • 35.
    © 2014 AdobeSystems Incorporated. All Rights Reserved. Adobe Confidential.