Adam Tuttle

Entries Tagged as ColdFusion

Jakarta Redirect Error when adding new IIS Websites to an existing ColdFusion 10 Install

Does this look familiar to you?

IIS HTTP Error 404 jakarta/isapi_redirect.dll

I spent a few hours on 3 different days trying to figure out what was wrong, here. I was trying to add a new website to an existing CF10 installation on a Windows Server Box with IIS7.5. The other sites were working fine.

What led me astray was that as part of the initial setup of this new site, I also added a web.config file with a port of the old .htaccess URL Rewriting rules from the site's previous hosting. This whole time I was chasing what I thought were edge cases in Rewrite rules, when in fact the answer was so obvious that "if it was a snake, it would have bit me" (to borrow a phrase from my mom)...

I thought it was a problem with the rewrite rules, and the presence of the "isapi_rewrite.dll" in the error reinforced this assumption. If I had only remembered that as of ColdFusion 10, we now have to add a "jakarta" Virtual Directory in IIS that points to the wsconfig path (in my case: C:\ColdFusion10\config\wsconfig\1\). I think this is taken care of for you if/when you run the web-server connector tool, but I hadn't done that.

So there you go. Just add your virtual directory named "jakarta" and you'll be on your way.

Published 2014-08-12 @ 10:30 in ColdFusion

ColdFusion Bug with image functions on OSX with Java7

Yesterday afternoon I found myself getting the very same exception message as this bug report from May 2014: java.lang.ClassNotFoundException: javax.media.jai.util.ImagingException

What sort of horrible monstrosity of code was I attempting to slip by ColdFusion?

var img = imageRead( imagePath );

Oh, the humanity.

So, what crimes am I guilty of, thus causing this error? I'm using Java 7 (build 1.7.0_60-b19, to be precise) on OSX Mavericks (10.9.4 build 13E28, to be precise).

Let's see:

I guess my JDK is slightly ahead of the officially supported version, but something tells me that downgrading my JDK would be a waste of my time: I doubt it would work on 1.7.0_15. Here's the download, if anyone wants to try it, though. The reason I believe it would be a waste of my time is that the issue is marked Unverified and otherwise has had no adobe contact, at all.

If you also happen to be a ColdFusion developer that uses a Mac with OSX 10.9 (Mavericks), could you maybe lend a hand and go vote for this bug? I'd appreciate it.

Published 2014-08-12 @ 08:00 in ColdFusion

To Scope, or Not To Scope

Adam Cameron has another of his surveys going, about your personal taste in variable scoping. It's something I've written about in the past, but my approach has evolved since then, so I figure it's worth writing about again.

Previously my position was that all references (if-statements, display, etc.) should be scoped, while it was not strictly necessary for variable definition (foo=42) — unless required to actually put the variable where you want it, e.g. in Request scope. I still think this approach has merit, and for the same reasons (you never find yourself asking, "ok, but WHERE is the variable foo coming from?") but its primary drawback is verbosity.

Since then, CFScript has matured (which is not to say that it "is mature"), and I find myself writing more JavaScript than CFML/CFScript, anyway. So, it's only natural that my personal style when writing CFML/CFScript is starting to take on the appearance of my JavaScript, too.

This means that I am tending to use traditional var foo = 42; statements in my CFCs over my previously-preferred style of var local = {}; local.foo = 42;. I preferred the latter because of its explicitness. As of CF9 we no longer needed the var local = {}; but I still find littering my code with dozens of local. prefixes to be a bit verbose, cumbersome, and at times distracting.

Another part of the evolution of my style has been that my code gets smaller and more decoupled (and in many cases, functional), which means the surface area of any given function is smaller and more manageable, so we don't need as much brain power to keep everything in our heads at once. Since I've got some additional brain bandwidth available from that change, I find myself preferring the more terse var-scoped approach, because I love terseness. This sort of creates a feedback loop: By writing smaller, more discrete functions, I'm able to use a more terse syntax, which takes up less space (mentally and physically), which itself makes the functions smaller and more manageable.

In the end, my preference is still that if you can't look at a variable and immediately know where its value was set — even when reviewing the code 2 years later — then you need to be more explicit. It's just that my tooling and my general style have enabled me to reduce the amount of time that extreme specificity is required.

Tools help! I can look at a FW/1 controller and tell you that a variable named rc.foo is input from the user: a form or url variable. Likewise, this means that things not prefixed with rc. are not user-generated and are then more likely to be var-scoped. My controllers don't use anything variables-scoped except injected services, so those service methods are prefixed by the service name: fooService.getFoos();. I could write variables.fooService.getFoos() but what's the point? All in all, those controllers are very easy to follow. (Well done, Sean!)

Likewise, my FW/1 services use injected service dependencies and no other variables-scoped data. If I need a config setting, it's available through my configService. So knowing this, all unscoped variables inside my functions are (better be!) var-scoped locals.

But that's just my personal style. What is yours like? (And hey, take a minute to fill out Adam Cameron's Survey, too!)

Published 2014-07-24 @ 09:33 in Best Practices ColdFusion

Idiosyncrasies of using CFContent to send files to the client in ColdFusion

I've found some idiosyncrasies in using CFContent to deliver files to the browser with ColdFusion (e.g. shielded downloads), so I thought I would share them here.

I have only tested what I'm about to share in ColdFusion 10, but I have no reason to believe that it will be any different with other versions, as it appears to be entirely how things are handled client-side.

I can never remember what the appropriate header name is for specifying the file name, so the first thing I did was google for it. That took me to Ben Nadel's blog post on streaming files -- a slightly different matter, but it had the answer I was after:

<cfheader name="content-disposition" value="attachment; filename='filename.xlsx'" />

This worked great, at first, in Chrome. When I got around to various browser tests, I found that if my file name contained a space, as in file name.xlsx then Firefox would save it as 'file (no extension -- nothing after the space). Equally as odd, Safari got the name correct (file name.xlsx) but appended .html.

Changing the single quotes to double quotes fixes FireFox's quirk, and adding a Content-Type header fixes Safari's, so the final result looks like this:

<cfheader name="Content-Disposition" value="attachment; filename=""#rc.fileName#""" />
<cfheader name="Content-Type" value="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />
<cfcontent reset="true" file="#rc.filePath#" deletefile="true" />

It's 2014... We can make an almost-convincing hoverboard hoax but we still need to test everything in every browser on every platform.

Published 2014-07-18 @ 09:05 in ColdFusion