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?

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

Session 9. Deployment Descriptor Http. Reading and Reference. en.wikipedia.org/wiki/http. en.wikipedia.org/wiki/list_of_http_headers

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.

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

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

CS506 Web Design & Development Final Term Solved MCQs with Reference

Unraveling the Mysteries of J2EE Web Application Communications

web.xml Deployment Descriptor Elements

Life Without NetBeans

servlets and Java JSP murach s (Chapter 2) TRAINING & REFERENCE Mike Murach & Associates Andrea Steelman Joel Murach

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

Jakarta Struts: An MVC Framework

Web Application Architecture (based J2EE 1.4 Tutorial)

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

ServletExec TM 4.1 User Guide. for Microsoft Internet Information Server Netscape Enterprise Server iplanet Web Server and Apache HTTP Server

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

SECTION II: JAVA SERVLETS

BlueDragon TM 7.0 Deploying CFML on J2EE Application Servers

Just Get it Written: Deploying Applications to WebLogic Server Using JDeveloper and WLS Console. Don t get it right, just get it written.

The End of the Beginning: Deploying Applications to WebLogic Server Using JDeveloper and WLS Console. Don t get it right, just get it written.

SUN Enterprise Development with iplanet Application Server

Specialized - Mastering JEE 7 Web Application Development

CHAPTER 6. Organizing Your Development Project. All right, guys! It s time to clean up this town!

MAX 2006 Beyond Boundaries

Structure of a webapplication

One application has servlet context(s).

Module 3 Web Component

Customizing ArcIMS Using the Java Connector and Python

Tutorial: Developing a Simple Hello World Portlet

JBoss SOAP Web Services User Guide. Version: M5

Chapter 10 Web-based Information Systems

Going From CF to Java

BlueDragon TM 3.0 Deploying CFML on J2EE Servers

J2EE Interview Questions

Real Life Web Development. Joseph Paul Cohen

SSO Plugin. Installation for BMC AR System. J System Solutions. Version 5.1

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

CSE 336. Introduction to Programming. for Electronic Commerce. Why You Need CSE336

UIMA Simple Server User Guide

MOBILE COMPUTING. Web Applications. (INTRODUCTION, Architecture and Security) Lecture-10 Instructor : Mazhar Hussain

Adobe ColdFusion 11 Enterprise Edition

Advanced Java Programming

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

AppDev StudioTM 3.2 SAS. Migration Guide

WA2018 Programming REST Web Services with JAX-RS WebLogic 12c / Eclipse. Student Labs. Web Age Solutions Inc.

JSF: Introduction, Installation, and Setup

Just Get it Written: Deploying Applications to WebLogic Server Using JDeveloper and WLS Console. Don t get it right, just get it written.

SERVLETS INTERVIEW QUESTIONS

Novell Access Manager authentication class for OpenID authentication

Penetration Testing. James Walden Northern Kentucky University

Detects Potential Problems. Customizable Data Columns. Support for International Characters

Don t get it right, just get it written.

GUJARAT TECHNOLOGICAL UNIVERSITY

Oracle WebLogic Server 11g: Administration Essentials

Adobe ColdFusion (2016 release)

APIs - what are they, really? Web API, Programming libraries, third party APIs etc

Magnolia. Content Management Suite. Slide 1

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

Setting Up the Development Environment

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

How to Publish Any NetBeans Web App

How to use J2EE default server

Enhydra 6.2 Application Architecture. Tanja Jovanovic

BIG-IP Access Policy Manager : Portal Access. Version 12.1

NetBeans IDE Field Guide

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

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

WAS: WebSphere Appl Server Admin Rel 6

Introduction to Servlets. After which you will doget it

Mastering WDK Developer Tips and Tricks. A.J. Whitney

OpenOffice.org as a platform for developers

ByggSøk plan Project Structure And Build Process

HYPERION SYSTEM 9 BI+ GETTING STARTED GUIDE APPLICATION BUILDER J2EE RELEASE 9.2

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

Sentences Installation Guide. Sentences Version 4.0

New in CFMX 6&7. What did you miss? Charlie Arehart, Independent Consultant

DESIGN AND IMPLEMENTATION OF SAGE DISPLAY CONTROLLER PROJECT

Lotus Exam IBM Websphere Portal 6.1 Application Development Version: 5.0 [ Total Questions: 150 ]

Oracle 1Z Java EE 6 Web Component Developer(R) Certified Expert.

WebSphere Application Server for z/os I'm Not a Dummy But...

Using the VisualAge for Java WebSphere Test Environment

Java Servlets. Preparing your System

Web Applications. and. Struts 2

Chapter 2 Introduction

OAuth 2 and Native Apps

This tutorial will teach you how to use Java Servlets to develop your web based applications in simple and easy steps.

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Web-based File Upload and Download System

Borland Application Server Certification. Study Guide. Version 1.0 Copyright 2001 Borland Software Corporation. All Rights Reserved.

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

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

(Worth 50% of overall Project 1 grade)

PRIMIX SOLUTIONS. Core Labs. Tapestry : Java Web Components Whitepaper

COPYRIGHTED MATERIAL

CodeCharge Studio Java Deployment Guide Table of contents

Java 2 Platform, Enterprise Edition: Platform and Component Specifications

2 Apache Wink Building Blocks

15-415: Database Applications Project 2. CMUQFlix - CMUQ s Movie Recommendation System

Oracle9i Application Server Architecture and Com

DEPLOYING WDK APPLICATIONS ON JBOSS APPLICATION SERVER AND APACHE WEB SERVER VIA MOD_JK PROXY

Transcription:

Topics Augmenting Application.cfm with Filters Charles Arehart Founder/CTO, Systemanage carehart@systemanage.com http://www.systemanage.com What s a filter? What s it got to do with Application.cfm? Template pre-processing tricks Applying them in your environment Finding filters Template post-processing tricks Benefits over CF native approaches 1/10/2003 www.systemanage.com our practice makes you perfect tm 2 What s a filter? What a filter can do Technically: can inspect or transform the content or headers of an HTTP request or response Can record information about a request, redirect access to a different page, and more Simply: Filters can perform actions before a CF page is processed, or manipulate output after it s processed Can augment traditional application.cfm operations They don t typically create output themselves www.systemanage.com our practice makes you perfect tm 3 Examine request coming into page, then: Invoke the resource (i.e., CF, servlet, JSP, HTML page) in the normal manner Invoke the resource with modified request information Invoke the resource but modify the response before sending it to the client Prevent the resource from being invoked and instead redirect to a different resource, return a particular status code, or generate replacement output Separate hi-level access decisions from presentation code www.systemanage.com our practice makes you perfect tm 4 Isn t it a java thing? What s it got to do with Application.cfm? Filters are actually a feature of the Java Servlet API But don t let that scare you! CFMX is built upon a J2EE foundation and includes the full support of the Servlet API Don t need to know Java, or servlets, to use filters Don t even need to write filters to get started Browser Request s FileX.cfm CF Server Application.cfm Filex.cfm www.systemanage.com our practice makes you perfect tm 5 www.systemanage.com our practice makes you perfect tm 6

Input (request) filters run before application.cfm What about OnRequestend.cfm? CF Server CF Server Browser Request s FileX.cfm Servlet Filter Runs First Application.cfm Filex.cfm Browser Request s FileX.cfm Servlet Filter Runs First Application.cfm Filex.cfm OnRequest End.cfm www.systemanage.com our practice makes you perfect tm 7 www.systemanage.com our practice makes you perfect tm 8 Output (response) filters run after OnRequestEnd.cfm Possible combinations Browser Request s FileX.cfm Servlet Filter Runs First Servlet Filter Runs Last CF Server Application.cfm OnRequest End.cfm Filex.cfm Can have either, none, or both of application.cfm/onrequestend.cfm But CF processes onrequestend.cfm only if application.cfm has been processed in same directory Can have either, none, or both of input (request) filter/output (response) filter Can have any combination of all of them Can actually have multiple filters www.systemanage.com our practice makes you perfect tm 9 www.systemanage.com our practice makes you perfect tm 10 Flexible Filters Template pre-processing tricks Filters are defined by mapping them to a URL pattern in a CFMX XML configuration file Can designate filter to be executed for a given URL pattern: All under a given directory/virtual path Implies all subdirs/paths under that In other words, entire application or subset All under root (/) In other words, entire server A specific file What kinds of things could a request filter do? Logging and auditing visits Blocking execution of a page for a given time period (perhaps during a maintenance period) Blocking visitors from given domains Triggering events when a resource is accessed Caching/reusing a page s results Modifying the input request before processing by CF Modifying request character encoding To name a few www.systemanage.com our practice makes you perfect tm 11 www.systemanage.com our practice makes you perfect tm 12

What other uses of filters? Evaluate request to detect Whether referer is expected one Whether expected form fields are present Whether expected cookies, authentication, etc. are present Whether incoming form data has HTML (to filter it out to prevent cross-browser scripting) So many more possibilities The catch? They re written in Java Filters are a servlets feature Servlets are written in Java No point looking at them since most here won t know java Will point you to resources for learning more later if you want to write your own But you can find many examples already written Only need to install and configure them www.systemanage.com our practice makes you perfect tm 13 www.systemanage.com our practice makes you perfect tm 14 Finding filters Some examples www.servletsuite.com/servlets.htm JSPTags.com See resources for learning more at end of presentation Cache filter http://www.servletsuite.com/servlets/cacheflt.htm Billing Filter http://www.servletsuite.com/servlets/billflt.htm Profiler Filter (track execution times) http://www.servletsuite.com/servlets/profflt.htm IP Filter (access restriction, load balancing) http://www.servletsuite.com/servlets/ipflt.htm Will see zip filter later www.systemanage.com our practice makes you perfect tm 15 www.systemanage.com our practice makes you perfect tm 16 Applying them in your environment Just 4 simple steps 1. Find or build a filter 2. Place java file for filter in CFMX java file dir 3. Modify CFusionMX\wwwroot\WEB-INF\web.xml to define filter and its mapping 4. Restart CFMX server Finding one sample filter Let s use the timerfilter provided in a java article explaining filters (as listed at the end in the resources section) http://javaboutique.internet.com/tutorials/servl et_filters/filters-demo-source.zip We want the timerfilter in that zip file. www.systemanage.com our practice makes you perfect tm 17 www.systemanage.com our practice makes you perfect tm 18

Placing the java file into CFMX Place java file for filter in CFMX java file dir For.java or.class file, CFusionMX\wwwroot\WEB-INF\classes For.jar file, CFusionMX\wwwroot\WEB-INF\lib Note: if downloaded file is a War (web archive) file, that s just a zip file that can be opened with WinZip, etc. www.systemanage.com our practice makes you perfect tm 19 Understanding Java Packages May need to understand issues of Java packages, to know where to place java files Can typically just place jar in lib directory It holds files in an appropriate internal directory structure For source (.java) files, need to pay attention to possible packaging If filter source code shows use of package as in: package com.kief.filterdemo; Then it expects to be stored in com\kief\filterdemo directory under some directory in classpath Create that under that classes directory on prev slide www.systemanage.com our practice makes you perfect tm 20 Hidden Gem: No need to compile the filters CF can auto compile servlets (and therefore filters) Not suitable for production, as it s a slight performance detriment to watch for changes In [cfmx_home]\wwwroot\web-inf\jrun-web.xml add within the existing <jrun-web-app> element: <reload>true</reload> <compile>true</compile> Restart the server CFMX will now reload classes from [cfmx_home]\wwwroot\web-inf\classes and lib See blog entry: http://cfmxplus.blogspot.com/2002_08_04_cfmxplus_arch ive.html#85325044 www.systemanage.com our practice makes you perfect tm 21 Modifying web.xml to map filter Register the filter for the desired pages Use filter and filter-mapping in web.xml File already exists in Cfusionmx\wwwroot\WEB-INF Add needed xml elements within <web-app> root element www.systemanage.com our practice makes you perfect tm 22 Example Filter mapping options <filter> <filter-name>timer</filter-name> <filter-class>com.kief.filterdemo.timerfilter</filter-class> </filter> <filter-mapping> <filter-name>timer</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> Several possibilities /* means all templates served by server Can do a subpath such as "/secure/*" Or all files of a type, like "*.cfm" Can name a specific file, like "/filtered_page.html Or map to a named servlet as well Same as for <servlet-mapping> block, for those familiar with it www.systemanage.com our practice makes you perfect tm 23 www.systemanage.com our practice makes you perfect tm 24

Ordering XML elements in web.xml JRun s order of processing Have read that: filter, filter-mapping, servlet, and servletmapping elements must appear in the web application deployment descriptor in that order But have seen it work in CFMX even if not in that strict order JRun orders the execution of filters for each request depending on the URL patterns and servlets that the request URI matches in the web.xml file JRun considers url-pattern matches first in the order that they appear in the web.xml file followed by servlet-name matches in the order that they appear in the web.xml file www.systemanage.com our practice makes you perfect tm 25 www.systemanage.com our practice makes you perfect tm 26 More flexibility in mapping Restart and run Can designate multiple URL patterns for a filter Can designate multiple filters to a given URL pattern Filters can be added without application or filter knowing about each other Can modify filter without modifying application And can apply that change across several apps Restart server Execute page that s mapped to filter to test This filter was set to run for all templates Also writes its output System.out.println commonly used in java apps to write to console No such console So where does CF write such output? www.systemanage.com our practice makes you perfect tm 27 www.systemanage.com our practice makes you perfect tm 28 Where System.out.println writes in CFMX If filter (or servlet) writes to System.out.println, where does it go in CFMX? CFusionMX\runtime\logs\default-out.log Writes in strange order Descending by date (latest date s output at top of file) But within that date, ascending by time Doesn t work? Are you sure you saved all files? Correct mappings in web.xml? Correct location of java files in classes directory? And in subdirectories if filter uses a package Set the option for CF to auto-compile java files? Restarted the server? www.systemanage.com our practice makes you perfect tm 29 www.systemanage.com our practice makes you perfect tm 30

Template post-processing tricks What kinds of things can a response filter do? Logging page execution time Localization (targeting output to a locale) Image conversion XML transformations of XML output Encryption Data compression Examples Again, see previous page listing sites with examples Let s focus on compression filter http://www.servletsuite.com/servlets/gzipflt.ht m Place the gzpflt.jar in the cfusionmx\wwwroot\web-inf\lib directory www.systemanage.com our practice makes you perfect tm 31 www.systemanage.com our practice makes you perfect tm 32 Compression Filter Basically, it zips output of pages to compress them CF pages typically have lots of white space All web pages benefit from some compression Most browser support compression A good compression filter: Only compresses if browser will support it Browsers send accept-encoding header indicating if they support compression Can view that in CF with cgi.http_accept_encoding Doesn t bother if the request output isn t large enough to benefit from compression Haven t explored this one to see how it works www.systemanage.com our practice makes you perfect tm 33 Web.xml configuration <filter> <filter-name>gzipfilter</filter-name> <filterclass>com.cj.gzipflt.gzipfilter</filter-class> </filter> <filter-mapping> <filter-name>gzipfilter</filter-name> <url-pattern>*.cfm</url-pattern> </filter-mapping> www.systemanage.com our practice makes you perfect tm 34 Implementing and testing Follow previous steps to implement Use load testing tool to demonstrate effect Several exist One I like for local testing is paessler.com MS has free tool, not as effective OpenDemand.com has cool web-based tool, but not suitable without net connection Companies like Empirix, Segue, and Mercury Interactive have very expensive (and powerful) alternatives www.systemanage.com our practice makes you perfect tm 35 Paessler WebServer Stress Tool Using their release 6 beta http://www.paessler.com/products/webstress/w ebstressbeta.htm Pretty cheap too prices range from $50 to 999 See http://www.paessler.com/order www.systemanage.com our practice makes you perfect tm 36

Results without compression Results with compression: 4:1 reduction in bytes sent to browser! www.systemanage.com our practice makes you perfect tm 37 www.systemanage.com our practice makes you perfect tm 38 Running tests of compression Be aware, when testing this way, or with CFHTTP, that you need to send a header to the server (as a browser would) indicating that you accept Gzip compression See cgi.http_accept_encoding Set with accept-encoding:gzip,deflate in load testing tool Or <cfhttpparam type="cgi" name="accept- Encoding" value="gzip,deflate"> on CFHTTP See my blog: http://cfmxplus.blogspot.com/2002_11_24_cfmxplus_a rchive.html#85712370 Key difference between filters and OnRequestend OnRequestEnd processing does not occur if CFABORT is executed Makes it unreliable for some end of request processing Response filters, if designated, will always be executed regardless of CF processing Response filters apply to ALL files matching the given URL: CF, JSP (enterprise), servlets, and even static files (HTML) and graphics! Flash as well, if there s some benefit to doing so www.systemanage.com our practice makes you perfect tm 39 www.systemanage.com our practice makes you perfect tm 40 Benefits of filters over CF native approaches Can apply to more than just application A file, or entire server Don t need to modify multiple application.cfm s to effect behavior across several applications Can change filter without changing CF template(s) More about filters There are more topics worth exploring Accessing the servlet context in filter Using initialization parameters (to modify filter behavior at deployment time) Modifying the request scope to pass to template Chaining of multiple filters Disabling the invoker servlet Equally compelling are event listeners Can track/respond to session creation/modification/expiration www.systemanage.com our practice makes you perfect tm 41 www.systemanage.com our practice makes you perfect tm 42

Learning more about filters Beware: tend to be oriented toward java developers Sun article, The Essentials of Filters http://java.sun.com/products/servlet/filters.ht ml Samples at http://java.sun.com/products/servlet/filters.zip O reilly article, Writing Servlet 2.3 Filters http://www.onjava.com/lpt/a/826 Learning more about filters Java Boutique s Writing Servlet Filters http://javaboutique.internet.com/tutorials/servl et_filters/ Code: http://javaboutique.internet.com/tutorials/servl et_filters/filters-demo-source.zip JRun 4 Programmer s Guide, Chapter 7 http://livedocs.macromedia.com/jrun4docs/pro grammers_guide/filters.jsp www.systemanage.com our practice makes you perfect tm 43 www.systemanage.com our practice makes you perfect tm 44 Learning more about filters Marty Hall s More Servlets and JSP Chapter 9 Servlet and JSP Filters Available online in PDF form http://developer.java.sun.com/developer/books/j avaserverpages/servlets_javaserver/servlets_java server09.pdf My blog (cfmxplus.blogspot.com) Fun with Filters and Listeners http://cfmxplus.blogspot.com/2002_09_01_cfmx plus_archive.html#85411326 Summary Filters are powerful And relatively easy to use Don t need to know java If you can find existing filters Just need to know about where to put filters, how to setup web.xml file They offer far more power than application.cfm and onrequestend.cfm Hope you enjoyed this introduction! www.systemanage.com our practice makes you perfect tm 45 www.systemanage.com our practice makes you perfect tm 46 Excerpted from One Day Seminar This is one section of a day-long seminar on Java/CFMX integration Understanding Java/J2EE Integration in CFMX, For Those With No Java Experience More at http://www.systemanage.com/seminars/ Offered to public at $249 per attendees Available onsite at $2499, flat fee for all attendees Seminars are lecture format, like this talk No need for computers Hundreds of slides like these details provided www.systemanage.com our practice makes you perfect tm 47 Contact Information Happy to answer questions related to talk Email: carehart@systemanage.com Phone: 301 604 8399 Web: www.systemanage.com Also available for Training (custom or pre-written) CF, DB, JRun/J2EE, Javascript, wireless, and more Consulting (very short-term) best practices, architecture, setup Developer Group Mentoring www.systemanage.com our practice makes you perfect tm 48