Jul 21

ColdFusion 9 ORM Problem – java.lang.NoClassDefFoundError: javax/transaction/Synchronization

Posted by James Netherton | Tuesday 21 July 2009 19:59 PM | In ColdFusion

I have the CF9 Beta deployed as a WAR file under Tomcat 6. I was trying to test out the ORM stuff and hit a strange problem. Whenever I tried to call any of the CF ORM functions, the request would suddenly die. Looking at the application server logs I noticed lots of entries like:

java.lang.NoClassDefFoundError: javax/transaction/Synchronization

For some reason I didn’t seem to have jta.jar (required library for Hibernate), so I added it manually to the CF lib directory and everything started working properly.

Wonder if anyone else has had this problem???

Jan 26

Deploying ColdFusion on Tomcat under Ubuntu

Posted by James Netherton | Monday 26 January 2009 7:00 AM | In ColdFusion, Linux

I spent ages trying to get ColdFusion working properly with Tomcat 6 on Unbuntu. Tomcat wouldn’t start the ColdFusion application sever and the logs were getting full of exceptions moaning about the inability to access certain resources. For example:

java.security.AccessControlException: access denied (java.util.PropertyPermission coldfusion.classPath read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:342)
at java.security.AccessController.checkPermission(AccessController.java:553)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1302)
at java.lang.System.getProperty(System.java:669)

Eventually I came across a solution posted to House Of Fusion in 2007. Open up your catalina.policy file, comment out what’s in there and add the line:

permission java.security.AllPermission;

It’s a bit of a hack – but it works! This is obviously something that you wouldn’t want to do on a production machine!

Aug 05

Call custom tags without cf_ or cfmodule

Posted by James Netherton | Tuesday 05 August 2008 8:08 AM | In ColdFusion

This may be common knowledge but I just stumbled upon it…..

The standard convention for invoking ColdFusion custom tags is to use:

<cf_mytag/>

or

<cfmodule template="mytag.cfm"/>

There’s a way in which you are able to dispense with cf_ prefix and the <cfmodule> call. Browse to your ColdFusion WEB-INF\cftags directory. You should see some files relating to ColdFusion tags such as <cfdump> and <cfsavecontent>. You can add your own custom tag to this directory and invoke it from any CF template. For example:

Custom Tag – mytag.cfm

<cfdump var="#attributes#"/>

Calling Template

<cfmytag attribute1="test1" attribute2="test2"/>

Note that the cf_ or <cfmodule> prefix wasn’t used. Instead the tag call looks like any normal ColdFusion tag invocation.

I doubt this has any real world usage but I thought it was worth blogging anyway.

Jul 08

Reserved ColdFusion function names

Posted by James Netherton | Tuesday 08 July 2008 15:07 PM | In ColdFusion

Most people are aware that you cannot give a name to a ColdFusion function that is equal to the name of one of the ColdFusion "built in" functions.

This started me thinking that as ColdFusion templates and CFC’s are compiled down to Java servlets, there must be additional function names that are ‘reserved’. Each template and CFC page will naturally extend java.lang.Object and therefore inherit all of Object’s public methods.

For example, try the following:

<cffunction name="getClass">
</cffunction>

The result is “The name getClass is the name of a built-in ColdFusion function". You get the same result when declaring a function with the names "wait", "notify" and "equals", all of which are public methods on java.lang.Object.

These are only a few examples, I’m assuming that there must be more reserved function names given the number of classes that ColdFusion template and CFC servlets could potentially extend from.

The getClass method opens up the potential for some fun with ColdFusion:

Get the current template class name

<cfoutput>#getClass().getName()#</cfoutput>

Get the current template class properties

<cfset fields = getClass().getFields()/>

<cfloop array="#fields#" index="field">
	<cfoutput>#field.getName()#<br/></cfoutput>
</cfloop>

Get the current template class methods

<cfset methods = getClass().getDeclaredMethods()/>

<cfloop array="#methods#" index="method">
	<cfoutput>#method.getName()#<br/></cfoutput>
</cfloop>

Get the name of the class that the current template extends from

<cfoutput>#getClass().getSuperclass().getName()#</cfoutput>

Jun 12

Disabling ColdFusion administrator authentication

Posted by James Netherton | Thursday 12 June 2008 6:06 AM | In ColdFusion

I find having to log into the ColdFusion administrator a pain when I’m working on applications in my development environment. You can disable the authentication process by way of the following:

1. Open up WEB-INF\cfusion\lib\neo-security.xml on multiserver installations or cfinsntallationdir\lib\neo-security.xml on standalone installs

2. Edit the admin.security.enabled property so that it appears as follows:

<var name="admin.security.enabled">
	<boolean value="false"/>
</var>

3. Save the file and restart ColdFusion

Obviously you would not want to be doing this in a production or publicly accessible environment!

Jun 04

Using jrunx classes in ColdFusion

Posted by James Netherton | Wednesday 04 June 2008 15:06 PM | In ColdFusion

I’ve been screwing around with classes within the jrunx Java package that comes bundled with ColdFusion (not sure if it exists if you aren’t running CF on JRun). There are some useful and interesting utilities and I’ve put together a very brief set of demos for a few of them.


jrunx.util.NetUtil


Lookup an IP address from a DNS string:

<cfset variables.netUtil = createObject("java", "jrunx.util.NetUtil")/>

<cfset variables.ip = variables.netUtil.resolveIp("www.google.com")/>

<cfoutput>#variables.ip#</cfoutput>

Validate an IP address:

<cfset variables.netUtil = createObject("java", "jrunx.util.NetUtil")/>

<cfset variables.hostValid = variables.netUtil.validateHostIp("127.0.0.1")/>

<cfoutput>#variables.hostValid#</cfoutput>

jrunx.util.ZipTool


Zip a directory:

<cfset variables.zipUtil = createObject("java", "jrunx.util.ZipTool")/>
<cfset variables.zipUtil.zipDir("C:/Test", "C:/Test.zip", true)/>

Zip a single file:

<cfset variables.zipUtil = createObject("java", "jrunx.util.ZipTool")/>
<cfset variables.zipUtil.unZipSingleFile("C:/Test.zip", "C:/TestUnzip", "myHTMLFile.html")/>

Unzip an entire archive:

<cfset variables.zipUtil = createObject("java", "jrunx.util.ZipTool")/>
<cfset variables.zipUtil.unzipToPath("C:/Test.zip", "C:/TestUnzip")/>

jrunx.xml.XMLScript


Change an XML entity value within an XML file:
XML Input File

<root>
	<person id="1">
		<name>James</name>
		<age>00</age>
		<occupation>Developer</occupation>
	</person>
	<person id="2">
		<name>Bob</name>
		<age>00</age>
		<occupation>Developer</occupation>
	</person>
</root>
<cfset variables.xmlScript = createObject("java", "jrunx.xml.XMLScript").init()/>

<cfset variables.inputFile = expandPath("./input.xml")/>
<cfset variables.outputFile = expandPath("./output.xml")/>

<cfset variables.args = arrayNew(1)/>

<cfset variables.args.add("-i")/>
<cfset variables.args.add(variables.inputFile)/>
<cfset variables.args.add("-o")/>
<cfset variables.args.add(variables.outputFile)/>
<cfset variables.args.add("-s")/>
<cfset variables.args.add("/root/person[@id='1']/name/text()")/>

<cfset variables.args.add("Joe")/>

<!--- Hackery to create a java string array --->

<cfset variables.dummyString = repeatString(" : ", arrayLen(variables.args) - 1)/>
<cfset variables.stringArray = variables.dummyString.split(":")/>

<cfloop from="1" to="#arrayLen(variables.args)#" index="i">
	<cfset variables.stringArray[i] = variables.args[i]/>
</cfloop>

<cfset variables.xmlScript.command(variables.stringArray)/>

XML Output File

<?xml version="1.0" encoding="UTF-8"?>
<root>
	<person id="1">
		<name>Joe</name>
		<age>00</age>
		<occupation>Developer</occupation>
	</person>
	<person id="2">
		<name>Bob</name>
		<age>00</age>
		<occupation>Developer</occupation>
	</person>
</root>

Admittedly that’s a very lame example, there’s a proper overview of what the class can really do on the Adobe Jrun guide
There’s a full overview of jrunx classes and packages here.

May 04

Converting Unix timestamp values in ColdFusion

Posted by James Netherton | Sunday 04 May 2008 11:05 AM | In ColdFusion

I’ve been working on an application that integrates with a third party payment gateway solution. The payment service sends back a transaction timestamp after a purchase is successfully completed in the unix time format.

I spent some time trying to figure out how to covert this into a ‘normal’ date format with ColdFusion. The solution is pretty simple as the following code sample demonstrates.

<!--- Unix Timestamp representing 4th May 2008 00:00:00 AM --->
<cfset variables.unixTimeStamp = "1209859200"/>

<cfoutput>#dateAdd("s", variables.unixTimeStamp, "01/01/1970")#</cfoutput>

Apr 15

Run ColdFusion on GlassFish

Posted by James Netherton | Tuesday 15 April 2008 15:04 PM | In ColdFusion

I thought this was worthy of blogging seeing as it’s not often that ColdFusion gets mentioned on The Server Side.

Damon Gentry has posted an article on how to get ColdFusion running on Sun’s open source JEE application server, GlassFish.

As JRun is no longer being actively developed, maybe it’s time to start looking at some of the alternative application servers to deploy ColdFusion onto…..

Feb 17

ColdFusion 8 – Custommenu.xml

Posted by James Netherton | Sunday 17 February 2008 7:02 AM | In ColdFusion

In previous versions of ColdFusion you were able to add custom menu items to the ColdFusion administrator by creating a template named extensionscustom.cfm and placing this within the cfadministrator directory.

Peek within the cfadministrator directory under CFIDE within ColdFusion 8 and you should see a file named custommenu.xml. By adding entries into this file you can replicate the behaviour offered by extensionscustom.cfm.

The XML file has the following structure:

<?xml version="1.0" encoding="iso-8859-1"?>
<menu>
	<submenu label="My Custom Menu">
		<menuitem href="href" target="content">Custom Resource</menuitem>
	</submenu>
</menu>

You can have as many submenu or menuitem elements as you wish. Once you have made your changes, head over to the ColdFusion administrator and you should see your custom menu items appended to the end of the main navigation menu.

Feb 04

ColdFusion webservice debugging

Posted by James Netherton | Monday 04 February 2008 18:02 PM | In ColdFusion

Debugging webservices can sometimes be a painful experience. ColdFusion provides some help via the getSoapRequest and getSoapResponse functions, which enable you to view the SOAP request / response XML.

Suppose you want to see all SOAP requests and responses sent to the ColdFusion server. This can be achieved by making a simple change to the client-config.wsdd file. On my multi server ColdFusion 8 installation, the file is located in:

[Installationdrive]\JRun4\servers\cfusion\cfusion-ear\cfusion-war\WEB-INF

The beginning of the file has the following declarations:

<globalConfiguration>
  <!-- Give ColdFusion the ability to log the request and the response SOAP message -->
  <!-- Not recommended for production -->
<!--
  <requestFlow>
   <handler type="log"/>
  </requestFlow>
  <responseFlow>
   <handler type="log"/>
  </responseFlow>
-->

  <!-- Change for CFMX 7: Turn off multirefs -->
  <parameter name="sendMultiRefs" value="false"/>
 </globalConfiguration>

Uncomment the lines around the requestFlow and responseFlow tags. Save the file and restart ColdFusion. You should then see SOAP requests and responses being written out to the cfusion-out.log file.

Note the warning in the snippet above about not enabling SOAP logging in a production environment. For obvious reasons it makes sense not to leave logging enabled for long periods in production.

Dec 18

Missing jrunserver.store file when installing ColdFusion 8 with Apache

Posted by James Netherton | Tuesday 18 December 2007 16:12 PM | In ColdFusion

A small problem I just experienced when installing ColdFusion 8 on my mac and choosing to integrate it with the Apache install that ships with OS X.

ColdFusion would not serve any requests and reported:

JRun will not accept request. Check JRun web server configuration and JRun mappings on JRun server

A closer look at the Apache error log revealed:

could not open serverstore /Applications/ColdFusion8/runtime/lib/wsconfig/1/jrunserver.store

It turns out that there was no jrunserver.store file. The simple solution is to create the file and add:

proxyservers=127.0.0.1:51011

Nov 25

ColdFusion webservices on shared hosting

Posted by James Netherton | Sunday 25 November 2007 9:11 AM | In ColdFusion

ColdFusion security in a shared hosting environment can be a pain. Different hosts handle security in different ways, some disable certain tags / functions and use sandboxing. Other hosts do neither and allow users to access potentially security compromising functions such as createObject.

Something struck me after I tested a webservice that I had deployed on my host. The WSDL location would be listed under the web services section within the ColdFusion administrator. No big deal you may think and it usually isn’t if you’re on a shared host that forbids calls to the createObject function.

On a server that allows access to createObject, you can do something like the following. I omitted the code that gets the service details for CF7 as the getWebservice method takes far more parameters than its equivalent in CF 8.

CF 8:

<cfscript>
	serviceFactory = CreateObject("java", "coldfusion.server.ServiceFactory");
	webservices = serviceFactory.getXmlRpcService().getMappings();
</cfscript>

<cfdump var="#webservices#"><br/><br/>

<cfloop collection="#webservices#" item="key">
	<cfoutput><br/>#webservices[key]#<br/></cfoutput>
	<cfset map = structNew()/>
	<cfset map[key] = webservices[key]/>
	<cfdump var="#serviceFactory.getXmlRpcService().getWebservice(key, map)#">
</cfloop>

CF 7:

<cfscript>
	serviceFactory = CreateObject("java", "coldfusion.server.ServiceFactory");
	webservices = serviceFactory.getXmlRpcService().getMappings();
</cfscript>

<cfdump var="#webservices#"><br/><br/>

As you should see in the output, you can discover what services are registered with the CF administrator, the CF 8 example even outlines the method names, return type and required parameters. You could of course just browse to the service WSDL address and determine the same information, assuming of course the service is unsecured.

So, if you’re exposing any web services that return sensitive data on a shared host (which you shouldn’t be!), make sure they are secured appropriately!

Nov 17

Converting BlogCFC to Wordpress

Posted by James Netherton | Saturday 17 November 2007 9:11 AM | In ColdFusion

I’ve been experimenting with Wordpress recently and I wanted a way of migrating all of my posts and comments across from BlogCFC. Wordpress does have an RSS import feature which does an Ok job but I wanted to preserve data such as posts that had not been released, comments disabled etc.

There’s already a couple of migration tools written by some ColdFusion folks. Unfortunately it looks like the Wordpress database schema has changed significantly since they were written. Therefore, I decided to hack together my own utility.

Some disclaimers before I introduce the tool:

- It’ll only run on ColdFusion 8, although it would be easy to alter it to run on other versions.

- It’ll only work with MySQL databases.

- I haven’t tested it with the latest version of BlogCFC.

- Tested with Wordpress 2.3 only

Here’s a small guide to get started……

1. Download the utility from the link below and extract the zip archive somewhere under your web root.

BlogCFCConvert.zip

2. Configure two ColdFusion data sources. One for your BlogCFC database and another for the Wordpress database (assuming you have created the Wordpress database of course).

3. Make some edits to Application.cfm:

- Change request.blogcfcDSN to equal the BlogCFC data source name

- Change request.wpDSN to equal the Wordpress data source name

- You may have installed Wordpress with the option to use a database table prefix. If you did this, set the prefix value in request.wpTablePrefix.

- Set the GMT offset hour value to be applied onto post and comment dates in request.GMTOffset.

- Set request.blogURL to your current BlogCFC root URL. Do not add a trailing ‘/’ character!

- Wordpress lets you define your own URL format which makes it possible to keep all of your old BlogCFC post links in tact for SEO purposes. Uncomment the request.blogURLFormat variable if you wish to do this.

4.Execute index.cfm from wherever you extracted the code to, and the migration process will run. It will display a summary of categories, posts and comments imported when finished.

If everything has gone according to plan you should be able to fire up your Wordpress blog and you’ll be presented with all of your BlogCFC posts, categories and comments.

If you chose to uncomment the request.blogURLFormat variable in Application.cfm, browse to the permalinks administration area and set a custom structure of:

/blog/index.cfm/%year%/%monthnum%/%day%/%postname%/

You’ll then be able to browse your Wordpress blog using BlogCFC style URL’s.

Some remaining tasks might be:

- Migrate across any images and attachments

- Redirect RSS traffic

I’ve not done a massive amount of testing with this so if there’s any bugs or issues, let me know.

Nov 11

New ColdFusion community website

Posted by James Netherton | Sunday 11 November 2007 8:11 AM | In ColdFusion

Nick Tong has just launched coldfusioncommunity.org, a new community website for ColdFusion developers.

It looks pretty cool, there’s forum discussion, articles and video content on offer. Hopefully this will be another excellent resource for the CF community.

Sign up here.

Sep 15

Deploying smith on JBoss

Posted by James Netherton | Saturday 15 September 2007 0:09 AM | In ColdFusion

Following on to my previous smith post, here’s a simple run down of how I deployed the application on JBoss.

Navigate to /server/default/deploy. Create a new directory named ’smith.ear’. Switch into ’smith.ear’ and create another directory named ’smith.war’. Place the WAR file that you hopefully compiled (or maybe downloaded) into this directory. Extract the WAR file using the Jar command from the command line or by using an archive management application like WinRar.

Move the META-INF directory up one level into ’smith.ear’. Finally create an application.xml file within the META-INF directory. It should look something like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN" "http://java.sun.com/j2ee/dtds/application_1_2.dtd">
<application id="Application_ID">
   <display-name>Smith</display-name>
   <description>Smith</description>
      <module id="WebModule_1">
	<web>
	    	<web-uri>smith.war</web-uri>
	    	<context-root>smith</context-root>
	</web>
      </module>
</application>

Start JBoss and hopefully you’ll be able to browse to http://server/smith/IDE/admin.html where you’ll be presented with the administration login page.