Archive for May, 2011

cfmodule tag duplicating data

Wednesday, May 11th, 2011

This is a quick note on using the cfmodule tag in Coldfusion. Personally, I don’t use this tag. However, I was working on an application built on the Fusebox framework. The application essentially uses the cfmodule tag to call certain fuse action templates. I was writing a new action and, following suit implemented, the call to the action via the cfmodule tag. Running the application I noticed that the content executed by the action was duplicated.

So I began plugging in some logging to determine where the duplication was beginning and try to narrow it down. I noticed essentially that my action was being executed twice, but still no idea why. When coding I have a tendency to always close out any CF tags that do not have a closing tag. So for example I write cfset tags as

<cfset variables.myVar = "" />

Notice the closing ‘/>’.

Well, I now know that you shouldn’t do this with the cfmodule tag. The reason is because it is a wrapping tag. If it does not have a closing tag it will execute the template parameter. So let’s say I have two files: ‘index.cfm’ and ‘content.cfm’. Let’s look at index.cfm.

(more…)

Using Ref Cursor with Oracle’s ThinClient JDBC driver and Coldfusion via .Net

Tuesday, May 10th, 2011

So it’s a known issue that Coldfusion does not support returning a ref cursor as an out parameter of a stored procedure when using the Oracle Thin Client drivers. Since I have experienced this problem in the past I thought I would post a solution that uses C# to manage the Oracle stored procedure and return the result set to Coldfusion. So this solution will use Coldfusion’s ability to create object instances of a C# class using the ‘cfobject’ tag or the ‘createObject()’ function. Also keep in mind that if Coldfusion is returned a type DataTable from the C# method it will automatically convert it into a Coldfusion Query object that can then be handled like normal. So with this in mind let’s take a quick look at a basic Oracle stored procedure and the C# class that will execute the procedure and return a DataTable object.

Oracle Stored Procedure

create or replace
PROCEDURE "SP_TEST_CF9"
(
      arg_ArgumentOne IN NVARCHAR2,
      l_cursor OUT sys_refcursor
)
AS 

BEGIN

      OPEN l_cursor FOR
      SELECT column_name, column_id
      FROM  column_table
      WHERE column_argument_one = arg_ArgumentOne;

END SP_TEST_CF9;

(more…)

Using Selenium 2.0 with Python 3.2 doesn’t work well yet

Wednesday, May 4th, 2011

So I recently set up a testing environment using the Selenium webdriver and Python 3.2. I had some initial issues with getting it to just generally run which I resolved and blogged here. Nonetheless, I’ve since had a chance to dig a little deeper and it turns out that there are still things in the code that did not convert well from Python version 2 to 3 using the 2to3.py utility.

As such, I’ve uninstalled Python 3.2 and reinstalled version 2.7. I’ve run some of the tests that were failing while I had 3.2 installed and everything seems to be passing. So that’s good news. I’ll keep an eye out on and updated Python binding for Selenium 2 and give it another shot once there is an update.

Using Selenium 2.0 with Python 3.2

Wednesday, May 4th, 2011

Currently the Python Bindings for Selenium are not completely compatible with Python 3.2. I’ll show here how to make the python files compatible with version 3.2 using the python 2to3 utility. I am assuming here that you have Python installed and running, you have downloaded and installed Selenium 2.0, and that you have downloaded the Python Bindings and dropped the ‘selenium’ directory into your python ‘Lib’ directory to be used as a module.

So if you have all of this installed and you run the following line in the Python IDLE

from selenium import webdriver

you will most likely (considering that the Binding code has not been updated between now and then) get an error indicating a syntax error on line 193 or thereabouts. This syntax error is occurring because the Binding code is written for python version 2.7.

Good news though. Python 3.2 comes with a utility in the ‘Tools’ directory that will convert any .py file or files from version 2 to version 3.

If you want to find the actual file you can find it in the Python32/Tools/Scripts directory. It is named 2to3.py.

So we’ll execute this utility from the command line. So if on windows do Start/Run – type cmd to open the prompt. On mac use Applications/Utilities/Terminal.

(more…)

“Can’t Find Class” when calling a .Net .dll with Coldfusion

Tuesday, May 3rd, 2011

**Synopsis (in case you don’t want to read my story below) :: If you’re running CF9 and .Net Framework 4 and getting an error that indicates that the given class cannot be found in the given assembly it is likely that you need to upgrade your Coldfusion to 9.01 and restart both CF and .Net services.

I’ve been doing some ongoing research lately concerning the ability of CF to execute .Net classes. I’m running CF9 and .Net Framework 4. I began by calling the built-in .Net method GetHostName() that simply returns a string of basically the computer name.

Calling a Built-In .Net Class

<cfobject type=".NET" name="variables.test" class="System.Net.Dns" action="create" />
<cfset variables.hostName = variables.test.GetHostName() />
<cfoutput>
	#variables.hostName#
</cfoutput>

Worked perfect. What a great start! I’ve essentially just executed a .Net method with Coldfusion in less lines of code than I could have done writing a C# class. Excellent. So at this point I thought it was time to execute a class written and compiled by myself. I can’t remember my exact test, but it was something very simple that just returned a string like the following.

Simple C# Class

namespace testClass
{
    public class Test
    {
        public String returnName()
        {
           return "Matt";
        }
    }
}

I compiled the class into a .dll and saved it to somewhere easy to get to like the desktop. I then wrote a similar cfobject tag to call this like the following.

Coldfusion Caller

<cfset variables.pathToDll = "/Desktop/classLibrary/myClass.dll" />

<cfobject 	type = ".NET"
			name = "variables.test"
			protocol = "tcp"
			class = "testClass.Test"
			assembly = "#variables.pathToDll#"
			action = "create"
			secure = "false" />

Executing this code returned an error indicating that the class ‘Test’ could not be found in the selected Assembly. This was good news and bad news. The good news was that it found my Assembly. The bad news, obviously it couldn’t find the class.

After several hours of trying things and research I finally found that the .Net Framework 4 support was introduced in the CF9 Update 1. A quick check revealed that I was indeed not running 9.01. I upgraded, restarted both CF and .Net services and everything worked!

Accessing local Coldfusion development sites from multiple devices

Sunday, May 1st, 2011

Although it’s difficult to fit the entire idea in a single title, the point of this article is explain how to setup a local Coldfusion development site that can be access by any machine or device on the local network without having to upload to a web server.

So just to be clear what I’m working with is Coldfusion 9 on Mac OSX Snow Leopard using MAMP. At a very high level configuring this setup includes a Coldfusion instance setup to use an Apache webserver and a root directory of /Users/~User/Sites/. Here ‘~User’ is whatever your machine user name is.

I’m not going to go into detail on how to set this up since there are some really good tutorials already out there:
Setting Up a Solid Local Development Environment using ColdFusion 9, Apache, and MySQL on Mac OS X
Fixing Apache connection issues between MAMP Pro and ColdFusion 9

One note of caution. If after installing MAMP and CF and you have trouble getting the Apache server to start pay particular attention to the ‘Fixing Apache connection issues between MAMP Pro and ColdFusion 9′ video. In this video he explains how to get an uncorrupted mod_jrun20.so file from the installer package. You can also get the file from an extracted wsconfig.jar file, but it appears that the file is also corrupted in this archive as well. At least it was for me during my installation attempts. Nonetheless, the mod_jrun20.so file pulled from the installation package worked perfect.

Another note of caution. The ‘Webservice Connector Utility’ that can be launched from either the CF Launcher or the wsconfig.jar would create the webserver configuration, but would not create the jrunserver.store file. If you find this to be the case for you as well you can just create this file and add ‘proxyservers=51800′ if you are using CF9 and drop it into the /runtime/lib/wsconfig/1/ directory.

(more…)