Select Page

OnRequestStart() / OnRequest() Methods Invoked Even If Requested Template Doesn’t Exist In Lucee CFML

Published: January 29, 2023

While setting up my ColdFusion and Hotwire Demos project, I stumbled upon an application behavior that is unique to Lucee CFML (as opposed to Adobe ColdFusion). Historically, with ColdFusion, attempting to request a .cfm file that doesn’t exist would result in a “Missing Template” error; or, if defined, would trigger the onMissingTemplate() event handler. This was true regardless of the method defined in your Application.cfc framework component. In Lucee CFML, however, it seems that the onRequestStart() and onRequest() life-cycle method will be invoked even if the requested template doesn’t exist. Which is awesome!

ASIDE: It turns out, this is documented in the Lucee CFML docs. I just never saw it (especially since this is a rather esoteric deviation from Adobe’s implementation).

To test this in isolation, I started up two CommandBox servers: one using the latest Lucee CFML and one using the latest Adobe ColdFusion. Then, I created a directory with nothing but this single Application.cfc file in it:

	output = false
	hint = "I define the application settings and event handlers."
	// Define the application settings. = "OnRequestTest";
	this.applicationTimeout = createTimeSpan( 1, 0, 0, 0 );
	this.sessionManagement = false;
	this.setClientCookies = false;
	// ---
	// ---
	* I get called once to initialize the request processing.
	public void function onRequestStart() {
		writeDump([ "Handled by onRequestStart() event-handler." ]);
	* I get called once to fulfill the request.
	public void function onRequest() {
		writeDump([ "Handled by onRequest() event-handler." ]);
	* I get called once to fulfill the request for a CFML template that doesn't exist.
	public boolean function onMissingTemplate() {
		writeDump([ "Handled by onMissingTemplate() event-handler." ]);
		return( true );

As you can see, there’s no logic in this ColdFusion application component other than some simple logging. And, there’s no index.cfm template – or any other ColdFusion templates, for that matter, in this directory.

Now, if I make a request to ./does-not-exist.cfm in both ColdFusion engines, I get the following output:

One request to Lucee CFML showing that both the onRequestStart() and onRequest() event-handlers were invoked. Another request to Adobe ColdFusion showing that only the onMissingTemplate() event-handler was invoked.

As you can see, in the Lucee CFML engine, both the onRequestStart() and the onRequest() event-handlers were invoked despite the fact that the requested template doesn’t exist. On the other hand, in the Adobe ColdFusion engine, only the onMissingTemplate() method was invoked.

ASIDE: In the Lucee CFML engine, if the onRequest() method is commented-out, then both the onRequestStart() and the onMissingTemplate() methods are invoked. And, if the onMissingTemplate() method is commented-out, then the onRequstStart() method is invoked, followed by a thrown missinginclude error.

This is really cool! And, I believe that Lucee CFML represents the behavior that most ColdFusion developers actually wanted to happen.

As a final note, keep in mind that this only applies to ColdFusion requests (ie, those that the server knows to wire-through to the CFML runtime). If you make a request to does-not-exist.html (note the .html extension), then both server runtimes serve-up a 404 Not Found.

Want to use code from this post?
Check out the license.