Jul 30, 2009

CFMail in script with ColdFusion 9

cfmail is script is easy but as the docs are still a bit lacking and there is no mention of the attributes for using mail in script I had a look in the CF9 install directory and in

/opt/ColdFusion9/CustomTags/com/adobe/coldfusion

You will find the cfc's Adobe made to extend script support. I opened up the mail.cfc and worked out how to use the function. Here is a small example.

Of course to, from, subject etc can be strings they don't have to be variables.

Jul 28, 2009

ColdFusion 9 and the ORM a simple example.

The ORM in ColdFusion 9 makes things easy. Now lets consider a website that has a section on the side displaying current news items
and lets say it always displays the last 2 most recent news items. As a query this would be:
This works great in Microsoft SQL server but what about MYSQL?
OK now I have 2 set's of code. More Database Support means more code but ColdFusion should = less code. Here is where the ORM can make this sort of thing a breeze:

So this 1 line of code :
can now replace:
Here is the code used for testing. With the ORM is simply a matter of creating an empty datasource with the database of your choice setting the dialect in Application.cfc and the ORM will even make the table for you you don't even need to load up Enterprise manager or phpmyadmin. I tested this on both MSSQL and MYSQL.
index.cfm
indexcfm
NewsItem.cfc
newsItemcfc
Application.cfc
applicationcfc - Copy

The final result:

d

Oh and here is the link to the excellent docs at Adobe

Also make sure if you write your own constructors to specify default values or the ORM will cause some errors about not passing in values when it creates the objects behinds the scenes.

Jul 27, 2009

ColdFusion 9, Linux, Debian and Vmware - It's Easy

ColdFusion 9 is now officially supported on Ubuntu 9.04 I think this is great news. For a while we knew that it did work really easily on Ubuntu and Debain but it's now good to know its officially supported. You can see Adobes ColdFusion 9 Requirements here

Ubuntu is great but for some simple testing is can be quite heavy. If you have been thinking about trying ColdFusion 9 on Linux I might recommend Debian. I like the Debian net install because it's a minimal install of a basic system. The download is ~150meg and installs lean and quickly.

I used VMware EXSi on an old spare PC but Virtualbox, VMware server or Parallels will also work if you don't have a spare machine. Create a new Virtual machine and allocate 512mb ram. For testing and trying the new features this will be totally fine to run the slim Operating system and ColdFusion 9 even mySQL. When you start configuring your virtual machine make sure the network is set to "Bridged" so its connected directly to the physical network so it gets a real IP address from your DHCP server or router.

After the install there are a few commands and updates I usually run:

#Update the apt repository's
apt-get update

#insall some additions to VI ( simple text editor ) that make is more
#usable on Debian
apt-get install vim-nox

#install a ssh server so we can connect over putty and over sftp with ColdFusion #builder
apt-get install ssh

#you may wish to install apache even if you don't its impressive how easy it is
#with apt
apt-get install apache2

Run ifconfig ( if not ip as in windows ) to find the ipaddress ( presuming you selected dhcp )

At this point I drop out of a direct console session and continue the install with putty.

Download the linux .bin file ( 64 or 32 bit depending on the edition of debian you choose )

Use scp to move the file across. As my main machine is currently running Windows 7 I use CoreFTP which has scp support. You can just drop the .bin file to the root home directory.

Start up putty and ssh to the ip of the VM and log in.

The rest of the install I made a short screen capture pausing out the delays.



Once ColdFusion is installed and started you can test it out. In this short screencast I complete the install and log into the ColdFusion admin and setup a connection over SFTP in ColdFusion Builder create a test file and make sure CF9 is working.



This is a simple testing environment so I paid no attention to security and simply logged in as root. This is a simple demonstration how in less then half an hour you can have a slim OS running ColdFusion 9 in linux and edit your files from ColdFusion Builder. This example also uses the inbuilt ColdFusion webserver rather then connecting to apache which is also an option as part of the CF9 install.


Added an entry on installing mySQL here:

Jul 21, 2009

ColdFusion 9 and my favorite improvement!

Recently I have spent alot of time blogging on Railo and haven't had a chance to talk about some of the excellent new features of ColdFusion 9. Probably the most anticipated feature for me is full script support I'm so glad they decided to implement this. Another excellent feature is how they have fixed up the need to call init() on components as a "semi" constructor.

Check out what you can do now:





Notice the use of the implicit setters love this aswell properties are protected and are accessible only by getters() and setters().

It's not a real constructor we are used to in actionscript, java, c++ ect ( method name the same as the object ) but its pretty close and apart from the name, functions the same way.

I love the new syntax the code feels clean and there less of it.



......Update
After a quick chat with Justin Carter we can actually specify the name on the method we want to use as the constructor. Awsome no more init() methods needed.

Jul 19, 2009

ColdFusion builder introspects implicit getters and setters for us

Sweet ColdFusion builder introspects implicit getters and setters for us!

This works for both script and tag based implementations.





I have been enjoying working with ColdFusion builder but I recommend making Adam's suggestions on memory tweeks I felt CFB was faster to load and smoother after the changes the post can be seen here

BTW I'm running CFB under Windows 7 64 bit.

Jul 17, 2009

ColdFusion 8, 9 and Railo Object creation speed test

While reading Kevan Stannard's article on ColdFusion 9 object creation improvements post I was curious as too how Railo would stand up on the exact same test. The results are interesting:

( Seconds to create 100k objects and Objects created per second )

ColdFusion 8:



ColdFusion 9:



Railo 3.1.0.22:

OpenBD:


I could not achieve the figures Kevan achived perhaps an environment difference?

My setup is ColdFusion 8 and 9 are 64 bit on Windows 7 dev editions with 512mb ram assign in CFadmin. Railo was just Railo express. This is on my main work machine ( Dell XPS 1530 4g ram Windows 7 64bit ).

Now the interesting thing to note is that CF8 and 9 took well over 500mb of ram in task manager and Railo express was less then 100mb.

I'm not knocking CF9 as we haven't had any big issues even with 8 with our applications but I thought the results were interesting enough to share.

And yes we will be upgrading to CF9 and I can't wait!

PS someone with OpenBD should run this perhaps later tonight I'll install the express version and run the same test.

** Update I used the stable version on OpenBD ready to run on the same system and got excellent results.

PPS Do not laugh at me using IE it just had the least amount of addins and I used it so the screen shots would be cleaner.

Code:
test.cfc


speed.cfm

Jul 13, 2009

IPtables for your ColdFusion/Railo VPS

With all the talk about security recently I thought I would add a quick post on some precautions to take when setting up a VPS. Most servers ( Windows and Linux ) I work on are behind a hardware firewall but a few of my smaller VPS's don't have that luxury and are totally open when you are first given access. I'm not going to go into detail on configuring the correct directory permissions, users services are run as or best practice for file uploading but simply mention one of the first things you should do on your shiny new linux VPS's ( Windows aswell of course but not covered here ) and that is settign up IPtables.

First I need to think about what do I want to expose to the net. Port 80 ( web ), 443 ( ssl ), and 22 ( ssh ). Now this server also has mySQL ( port 3306 ) but I'm happy to leave that closed and use a ssh tunnel when I need to use a admin tool from my local PC.

My server for this setup is Debian ( 5.0 - Lenny ) but these instructions should be almost the same on any distribution and exactly the same on Ubuntu. Jamie Krug has an excellent set of instructions on setting up Railo on Ubuntu and while my setup differs ( I use resin rather then tomcat ) his IP tables rule list is extremely handy and an excellent place to start.

One thing to note is that applying the rules manually without loading them at boot time means that if you accidentally lock your self out you can use your control panel to simply reboot the server and the rules will be unloaded. Handy while your just starting out.

Also note that for every website running under Railo gets it's own administrator so adding re-write rules to "hide" the admin pages is worth while to try avoid brute force password attempts ( you could also restrict this to a specific IP ).



( apache mod rewrite and Helicon ISAPI rewrite for windows will accomplish this )

Nothing I have mentioned is specifically applicable to Railo or ColdFusion and I protect my non CFML machines in the same way and with the price of unmanaged VPS's coming down greatly in price recently I thought this was worth a mention.

If anyone has any other improvements or suggestions let me know.