Apache + Tomcat + ColdFusion + Java

Written on 20 March 2015, 09:24am

Tagged with: , , , ,

Below is a simple ColdFusion application architecture using Apache as web server and Tomcat as JEE application server.

1. Request workflow

Apache: In the Apache configuration file we have a virtual host <VirtualHost host1:80> with DocumentRoot /var/www/theColdFusionApp
Apache receives the request – example: http://123.45.67.89:80.
Hosts file: In /etc/hosts the host host1 is associated with the IP: 123.45.67.89 host1
AJP module: If there is a non-CF request, Apache serves the request itself (ex. html, css, js, image). If there is a CFM request, the AJP module forwards it to Tomcat: ProxyPassMatch ^/(.*\.(cf[cm]|cfml))$ ajp://host1:8080/$1 (Apache config file)
Tomcat has an AJP connector on that port: <Connector port="8080" protocol="AJP/1.3"/>
and an engine to process the requests:

<Engine name="Catalina" defaultHost="host1">
 <Host name="host1"  appBase="webapps">
    <Context path="" docBase="/var/www/theColdFusionApp/"/>
 </Host>

Both entries above are in the Tomcat server.xml config file.
Application folders: In /var/www/theColdFusionApp we have both the CF files (WEB-INF and CFIDE folders) and the actual application folders. More details below.

2. Folder structure and configuration files

(more…)

Random things #7

Written on 2 December 2014, 10:55pm

Tagged with: , , ,

1. Custom templates for request debug output

Use case: you want to temporarily enable debug output in a production environment (ex – to determine the cause of a specific performance problem), but you obviously don’t want the users to see the debug information.
Solutions:
– restrict debug output to your IP only (if you know exactly who is behind your IP), but it will still introduce a performance problem (the IP has to be checked for every request)
– create a custom debug template (*) – example logging.cfm instead of classic.cfm and log all the details you need instead of outputting
– create an empty debug template (silent.cfm), then create a component with a main logging method based on the classic.cfm debug template. Call this main method onRequestEnd to log all the needed details.

(*) A custom debug template can be created and placed in the WEB-INF/debug ColdFusion folder. The classic.cfm template can be used as starting point.
More info: http://www.bennadel.com/blog/116-finding-template-execution-stack-in-coldfusion.htm

2. When a ColdFusion template cannot be found

Use onMissingTemplate and return a 404 HTTP error code. Let the web server handle the error:

<cffunction name="onMissingTemplate">
    <cfargument name="targetPage" type="string" required="true"/>
    <cfheader statuscode="404" statustext="Not Found">
</cffunction>

(more…)