Tag Archives: coldfusion

Fixing minor issues moving code from Railo to Lucee ColdFusion

I have a couple of personal projects at a host that offers the ColdFusion web programming language. I have a soft spot for ColdFusion as its my first programming language and I still find it very easy to put together sites in it as it comes with easy to use functionality the other server side language I use a lot, PHP, only gets through frameworks where they’ve been added by others.

Adobe, current owners of the official ColdFusion engine, charge rather a lot for licenses and that has a knock on effect on the price of hosting. So, I use Viviotech, who offer the open source engines that run the ColdFusion language. The popular one of those was Railo and is now Lucee. Viviotech recently shifted my sites onto Lucee, which I’d been meaning to try as Railo is old and now discontinued.

I hit a couple of problems:

Gotcha 1: No CGI.PATH_INFO

In the project, I redirect all requests through a single routing file. Within that file, I was using CGI.PATH_INFO to get the path of the page being requested. That stopped working, which turns out to be because the host is using Nginx and that doesn’t have PATH_INFO turned on by default. There are ways of making it work, but I didn’t want to be doing support requests to do that and it may not have been accepted for my cheap-as-chips hosting package.

Instead, I make the redirect in the .htaccess file send the path through for me.

My redirect went from this:
RewriteRule ^(.*)$ ./routing.cfm/$1 [L]
To this:
RewriteRule ^(.*)$ /routing.cfm?path=$1 [NC,L,QSA]
Which gives me the URL of the page being requested in URL.path (apart from the / that is normally at the start, which I needed in part of my URL detection, so I added it on.)

I re-wrote my code to use the new URL.path (with added /) instead of CGI.PATH_INFO and that got it working again.

Gotcha 2: Saving files needs permissions set

In one of the sites, I get an image from an API that makes screenshots, and save it locally so I don’t have to use the API over and over. That means getting the image using CFHTTP, then saving it using CFFILE.

That worked, but I couldn’t open the files. The fix was to use MODE=”644″ within CFFILE. This set the file permissions so the image file can be read by the world, and show up on a web page.

<cffile
action = "write"
file = "<path><filename>"
output = "#cfhttp.fileContent#"
mode="644">

Improvement: Can read SSL protected RSS feeds

Railo couldn’t read RSS feeds that were protected by Let’s Encrypt SSL certificates and some of the other cheap/free SSL providers. Lucee can.

That’s great, as I made a very basic proxy (not really worthy of the word) to go request the SSL protected RSS feed through a PHP script I had on some other hosting, which would then send it through without SSL. Not great for security (although these are all public posts it is reading.) So the update to Lucee let me remove the ‘proxy’, which has simplified my code and maintenance.

Now I have my sites working again, I’m looking forward to delving into Lucee some more.

ColdFusion Admin “Cron service not available” error

Recently on a client site where we’re using an old version of ColdFusion I tried logging in to the admin area and rather than the login prompt, it was showing me the error message “Cron service not available”

After running around various pages that were all a duplicate of this Adobe forums thread saying the problem was with the <ColdFusion directory>\lib\neo-cron.xml file being corrupt, I tracked down the file on the server and checked it. The file was empty, well, it was full of spaces or tabs and not much else. I tried renaming it and re-starting the ColdFusion service and was still getting the error. Then I tried making an empty file called neo-cron.xml and restarting the service, no difference. I didn’t have a ready backup of the file so thought I was stuck, but tried a copy of the one from my more recent test server version of ColdFusion. Another service restart and it worked.

In case you’re stuck like me, here is the contents of the default neo-cron.xml from CF v11, it worked for my client’s server which is an earlier CF version:

<wddxPacket version='1.0'><header/><data><array length='4'><struct type='coldfusion.server.ConfigMap'></struct><boolean value='false'/><string></string><string>log,txt</string></array></data></wddxPacket>

You will need to re-make your scheduled tasks using the CF Admin, or CFSchedule in code.

Note: Depending on the age of your ColdFusion install, the neo-cron.xml directory could be in <your ColdFusion directory>\lib\ or <your ColdFusion directory>\cfusion\lib\

Good luck with your problem, I hope this helps.

Sending a push notification to your browser or mobile with ColdFusion and Push Engage

Push Engage is a service which lets you easily send push notifications to a browser or mobile phone, using a little code on your website. It’s very easy to set up and they currently have a very generous free account, allowing you to send a notification to up to 2,500 browsers/devices.

I’m using it as part of some alerts in the background of a client’s website. They’re using ColdFusion, so I needed to work out the code to send the alert from them, the API documentation on Push Engage has an example in PHP, but it’s very simple to convert. Here’s a CFHTTP call that will send a notification:

<cfset api_key = “(your API key here)”>

<cfhttp method=”Post”
url=”https://www.pushengage.com/apiv1/notifications”>

<cfhttpparam type=”header”
value=”#api_key#”
name=”api_key”>

<cfhttpparam type=”Formfield”
name=”notification_title”
value=”The text for the alert title”>

<cfhttpparam type=”Formfield”
name=”notification_message”
value=”The smaller text of the message of the notification”>

<cfhttpparam type=”Formfield”
name=”notification_url”
value=”http://www.example.com/”>
</cfhttp>

I’ve already followed their steps for adding Javascript to a page on the website, visiting it using a browser on my computer and my phone and accepting notifications from the site. Now, when I trigger the page with this on, I get a notification a few moments later. Lovely!

Thanks to Dave Child for introducing me to Post Engage.

 

Setting up ColdFusion 11 and SQL Server Express 2014 on Windows 8

Recently I installed Windows 8.1 in a virtual machine so I could set up IIS, ColdFusion (Developer version) and SQL Server (Express), which would match some of my client’s hosting well enough to use as a test environment.

SQL Server Express and ColdFusion developer edition can be used for free by developers, which makes this a nice, low cost development environment.

I hit big problems trying to get ColdFusion to talk to SQL Server Express, so I thought I ought to document the setup process for next time I tried and hit these problems. Sorry if you’re reading this and some of the notes are not detailed enough, I’ve set up ColdFusion and SQL Server enough times that the basics have stuck, if you need more help you might find it useful to search YouTube for help videos.

Setting up SQL Server Express 2014

Download SQL Server Express 2014 and running the installer. This all worked fine so just Google for wherever Microsoft are putting the installers now (which is a different place whenever I look, which is several years apart.) Try to find out if you’ve got a 32bit or 64bit version of Windows first, as you need to download the version which matches your Windows.

Setting up IIS

Go in to Windows settings > Control Panel > Programs > Turn Windows features on and off

I’m not sure I needed all of these, but I ended up turning them on while trying to solve problems:

Tick all of these (where nested, tick the ones inside the nest, not just to install everything):

.Net framework 3.5
.Net framework 4
Within Internet Information Services:
– Web Management Tools:
– – IIS 6 Management Compatibility
– – – IIS Metabase and IIS 6 configuration compatibility
– – IIS Management Console
– – IIS Management Service
– World Wide Web Services:
– – Application Development Features:
– – – .Net Extensibility 3.5
– – – .Net Extensibility 4.5
– – – ASP.NET 3.5
– – – ASP.NET 4
– – – CGI
– – – ISAPI Extensions
– – – ISAPI Filters
– – Common HTTP Features:
– – – Default Document
– – – Directory Browsing
– – – HTTP Errors
– – – HTTP Redirection
– – – Static Content
– – Health and Diagnostics:
– – – HTTP Logging
– – Performance Features:
– – – Dynamic Content Compression
– – – Static Content Compression
– – Security:
– – – Request Filtering

Setting up ColdFusion 11

Download from http://coldfusion.adobe.com

Run the installer

Choose the option to install a standalone web server, then, later in the install options you can choose to connect it up to IIS.

Setting up a database user in SQL Server Express 2014

In SQL Server Management Studio

Create a database:

Right click on Databases in the left column ‘Object Explorer’ > ‘New Database…’ and run through the short form

Create a user:

In left column ‘Object Explorer’, click on Security, right click on ‘Logins’ > ‘New Login…’

Add a new user, e.g. ‘CFUser’

Choose SQL Server authentication, give it a password.

Uncheck ‘Enforce password policy’

In the ‘Default Database’ drop down, change it to your new database

On the left hand ‘Select a page’ click on ‘User Mapping’

Tick the your new database, further down add them as a type of user to the database – ‘db_datareader’ & ‘db_datawriter’

Configuring Windows Firewall to allow access to SQL Server

As per these instructions from Microsoft I ran WF.msc then set up an Inbound Rule to allow TCP on port 1433 for local use.

Configuring security to allow ColdFusion to get data from SQL Server Express 2014

Apparently by default, SQL Server Express doesn’t allow remote connections, but configuring it to allow a remote connection so ColdFusion could get data from it was very hard, as the 2014 version of SQL Server Express is more locked down than previous versions. I wouldn’t have got it working without this Stackoverflow question about SQL Server Express 2012.

Open ‘SQL Server Configuration Manager’ (by searching for ‘SQL Server configuration’ on the Start screen.)

Under ‘SQL Server Network Configuration’ > ‘Protocols for SQLEXPRESS’:

Change ‘Named Pipes’ to ‘Enabled’ (by right clicking) (I’m not sure this step is necessary, as I found it in a bit of advice while I was still trying to get everything working.)

Change ‘TCP/IP’ to ‘Enabled’, then right click again and choose ‘Properties’

Under ‘IP2’ set the IP address to be that of the computer’s IP address on the local subnet (I found this out by running ‘netstat -a’ on the command line and looking down for port 1433 while I was trying something else, I’m sure there’s an easier way of finding it.)

Scroll down to the settings for IPAII.

Make sure ‘TCP Dynamic Ports’ is blank (not the 5 digit number that mine had in there by default.)

Make sure the ‘TCP Port’ is set to ‘1433’ (mine was blank by default.)

You may also need to go to ‘Services’ (by searching for it in Windows) and turning on the SQL Server Browser service (and setting it to run automatically) – I already had mine turned on during other debugging, I’ve read different advice on whether it should be on or off.

Some of the settings for SQL Server don’t take until you’ve re-started the SQL Server service. I think in the end I restarted Windows to be sure things were going to take long-term.

After all of this, I was able to go in to ColdFusion administrator and successfully set up a datasource using the database user I’d set up. Just getting SQL Server and ColdFusion to talk to each other was 3-4 hours of messing about with my settings, hence writing up these notes to make it easier next time.

5K App: Portal Me

I enjoyed building my first 5K App, the Twitter Biorhythm bot, so much I started building another app. In fact, I started building the second app. before I’d even finished the bot because it was so easy to put together.

This app. was inspired by Jeremy Keith’s talk at the £5 App meet in February about HuffDuffer, his podcast creation service. Within HuffDuffer Jeremy uses Google’s ‘Social Graph‘ API to help broaden the usefulness of the site without bothering the person using it. For instance, if you give it your Twitter name it will use your Twitter icon as your icon on Huffduffer, and it will also offer links to other popular services that it’s found you on using the Social Graph. You can see this at work on the ‘Elsewhere’ section of a profile, the links are created by looking up where else you have profiles via the Social Graph API.

In the past I have thought it would be useful to be able to put someone’s name in to a web page, and get back a set of their posted information from various sites. This is a bit cyber-stalking like, but it’s helpful to be able to get a quick picture of someone’s online life, especially if you’ve just met them as a potential client or through networking.

The Social Graph information would give me a simple way of looking up at least some information about someone. After a poke around in the documentation I found I could easily build a URL that included the URL of a page about someone that could be included in the graph, e.g. their blog or Twitter page. Giving this to the API and asking for ‘otherme’ information meant it would give me back a bunch of XML which includes profile pages on sites registered to that person, including the URL of RSS/Atom feeds from  those pages. I could take those feed URLs and make a page of posts from the person from various sites.

As this was to be a 5K App, I started knocking the code up in ColdFusion, which only needs a very small amount of code for parsing RSS and Atom feeds using the CFFEED function, and it’s XML parsing is pretty short too.

I got a prototype working and it only needed a couple of K’s worth of code. As I had so much spare, I decided to add some basic caching so it wouldn’t request the RSS feeds every time the page was refreshed.

The caching first checks a directory where feeds are saved. If it can’t find a feed, or the saved one is over an hour old, it goes on to request the feed and save it in to the cache directory. Then it reads the feed out of the cache.

Finally, a bit of styling, giving away the fact that I’m not a designer, and it was finished. The code is 4041 bytes, and you can try it out for yourself here: Portal Me.

It works best with people who have several sites which are registered in the Social Graph, and it only works for sites which are tied to the person by using the ‘rel=”me”‘ microformat code on the link (places like Flickr and Twitter do this automatically for you.)

Here’s a Portal for Jeremy Keith from his website address, and one for my friend Josh Russell based on his Twitter account.

One problem with Portal Me is that the Social Graph isn’t perfect, and if you haven’t tied your accounts together properly it shows some odd effects. For instance, if you make a portal for me based on my Twitter account you get less results than if you look me up via my main website address. I’ve only recently started making sure all of my various profiles link to the same site, and also that the site links back to tie them all together, so it may be sorted out over time.

I’ll put some coments in the code and put it up for downloading soon.

Try Portal Me for yourself.