ColdFusion Internals

Post on 04-Jul-2015

923 views 0 download

description

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

transcript

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

ColdFusion InternalsPaul Nibin K J

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

Introduction

2

Client

Web Server

© 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

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

Life of a request

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

Life of request in ColdFusion

5

© 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

© 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

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

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

© 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

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

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

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

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

Template Reader

Reads the CFM and creates a stream.

14

Encoding?

© 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=“”

© 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

© 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

© 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

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

Classloading

© 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

© 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

© 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

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

RESTful web services

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

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

How does RESTful web service work?

Two logical sections

Registration

Usage

© 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

© 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

© 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

© 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

© 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

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

Request Workflow

31

Identify REST

request

Identifies application

Identifies CFC

Identifies function

Invokes Function

© 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

© 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

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

Q & A

pnibinkj@adobe.com

http://blogs.coldfusion.com/

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