35
© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. ColdFusion Internals Paul Nibin K J

ColdFusion Internals

Embed Size (px)

DESCRIPTION

Look under the covers at the ColdFusion Internals, given by Adobe engineer Paul Nibin

Citation preview

Page 1: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

ColdFusion InternalsPaul Nibin K J

Page 2: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Introduction

2

Client

Web Server

Page 3: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Agenda

Life of a CFM request

Classloading in ColdFusion

How does RESTful web service work?

3

Page 4: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 4

Life of a request

Page 5: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Life of request in ColdFusion

5

Page 6: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Template Classloader

In filter chain

6

1. Request Validation

• Validates the request.

2. PathResolution

• Resolves absolute CFM Path

3.Application Resolution

• Locates Applicati-on.

• Creates Applicati-on scope.

• Invokes life cycle method

4. Parse

• Parse the CFM file .

• Generate AST using the grammar.

5.Bytecode Generation • Translat

e the AST to java byte code

Page 7: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

1. Request Validation

You are part of request validation too.

7

You can configure the following validations through settings.

Request Size Limits

Request Limits

Page 8: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

2. Path Resolution

8

/employee/addEmployee.cfm

C:\inetpub\wwwroot\employee\addEmployee.cfm

http://localhost/employee/addEmployee.cfm

Absolute

Path

Virtual Path

Request URL

Connector

You can cache the web server path using an admin setting.

Page 9: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

3. Application Resolution

Finds the Application.cfc

9

Creates Application Scope

Invokes Life cycle methods

OnApplicationStart()

OnRequestStart()

OnError()

Page 10: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

3. Application Resolution

Finds the Application.cfc

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

Page 11: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Unnamed applications

11

axis1Test

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/axis1Test/basic.cfc?wsdl

http://localhost/axis2Test/basic.cfc?wsdl

ColdFusion disables the creation of un named applications using an

admin setting.

Page 12: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

4. Parsing

12

<cfscript>

function hello() {

writeOutput("hello");

}

hello();

</cfscript>Template

Reader

Abstract Syntax Tree (AST)

Page 13: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

4. Parsing

13

<cfscript>

function hello() {

writeOutput("hello");

}

hello();

</cfscript>Template

Reader

Abstract Syntax Tree (AST)

Page 14: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Template Reader

Reads the CFM and creates a stream.

14

Encoding?

Page 15: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Automatic encoding identification

15

Start

Use

encoding

Guess

encoding

(icu4j)

Is guess

probability

100%?

Is BOM

present?

End

Yes

Yes

No

Use system

encoding

End

No

<cfprocessingdirective

..>

Save the file with

BOM

-Dfile.encoding=“”

Page 16: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

5. Byte code generation

16

AST

Byte Code

Engineering Library

(BCEL)

Byte Code

<cfusion_Root>\wwwroot\WEB-

INF\cfclasses

Page 17: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Template Classloader

17

Start

Is

class

in

cache

?

Check Last

Modified Date of

CFM

Is

Modifie

d?

End

Parse

Generate

byte code

Load byte

code

Use cached Class

No

Yes

No

Yes

Clear template

cache

Enable trusted

cache

Page 18: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Summary

ColdFusion filter chain has 5 main phases

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

Page 19: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 19

Classloading

Page 20: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Class Loading

-Dcoldfusion.classPath = {application.home}/lib/updates, {application.home}/lib,{application.home}/lib/axis2,{application.home}/gateway/lib/,…

20

In jvm.config

ClassLoader

cfusion/libcfusion/lib/update

s

cfusion/lib/axis

2

Page 21: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Prior to CF10

Create a folder in cfusion\lib.

21

Cons

Conflicts

May hamper normal server functioning.

Any changes in jar files need server restart to take effect.

Copy your jars to the new folder.

Edit jvm.config to add the new folder to the end of coldfusion.classPath

property

Page 22: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

CF10 and afterwards

CF10 introduced enhanced java integration.

Application setting available to specify custom classpath.

<cfset this.javaSettings = {LoadPaths = [".\java_lib\",".\java\myjar.jar"],

reloadOnChange = false}>

22

Pros

Complete isolation

Will not affect server functioning

Allows reloading

Page 23: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 23

RESTful web services

Page 24: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

RESTful web services

The W3C defines a Web service as:

A webservice becomes RESTful when the following 4 constraints are

satisfied.

1. Addressability

2. Multiple Representations

3. Uniform and constrained interfaces

4. Stateless communication

a software system designed to support interoperable

machine-to-machine interaction over a network.

Page 25: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

How does RESTful web service work?

Two logical sections

Registration

Usage

Page 26: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why?

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>

GET /students/112 HTTP/1.1

Host: http://localhost:8500

Accepts: text/html

Traditional web service

RESTful web service

Page 27: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Registration Workflow

Registration is the process of making your service ready for use.

27

Register application

Scanning for REST

CFC

Generate skeleton

Annotate skeleton

Register with Jersey

Inputs: Application Root Path and Service Name

Page 28: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Settings

28

Register application

Scanning for REST

CFC

• restsettings.cfclocation

Generate skeleton

• restsettings.skipCFCWithError

Annotate skeleton

Register with Jersey

Page 29: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Usage Workflow

Inputs: HTTP request

The URL of the request

HTTP Headers

Body of the request

Query params, Cookies, Matrix params etc..

29

Page 30: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Explaning the URL

http:// + localhost:8500 + /rest + /examples + /helloworld

30

• The protocolhttp

• Server address and portlocalhost:8500

• Context path used to identify the request as a REST requestrest

• The application name used during registrationexamples

• restPath defined in the CFChelloworld

Page 31: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Request Workflow

31

Identify REST

request

Identifies application

Identifies CFC

Identifies function

Invokes Function

Page 32: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Settings

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

Page 33: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Summary

RESTful web services introduction

33

Why RESTful web service needs to be registered first?

Registration workflow

o Settings

Request Workflow

Settings

Page 34: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. 34

Q & A

[email protected]

http://blogs.coldfusion.com/

Page 35: ColdFusion Internals

© 2014 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.