Jan 30

have you tried rebooting?

Posted by James Netherton | Tuesday 30 January 2007 17:01 PM | In ColdFusion

“Have you tried rebooting?” – The usual first question from any desktop support engineer…..

I’ll probably have to create a category that contains my experiences of trying to debug problems that don’t exist.

Today at work a new server was built to host a Flex project I’ve been working on. Strangely the basic install of ColdFusion was only 7.0 so I went through the process of installing 7.0.1 & 7.0.2.

So I uploaded my code not entirely expecting everything to work first time and up popped the dreaded “send failed” message.

2 hours later I still couldn’t figure out why flex wasn’t talking to the new CF server. I’d messed with services-config.xml, crossdomain.xml and restarted the CF services but nothing worked.

I then used Microsoft Fiddler to see what was going on behind the scenes. The flex app was getting 404’s when it made calls to the server’s flex2gateway. Weird I thought everything seems to have installed ok.

As I was about to give up and go home to research the problem, I decided to reboot the server and sure enough afterwards, my app started to work!

Could have saved myself a couple of hours worth of time wasting…

Jan 29

AMFPHP 1.9 beta 2 released

Posted by James Netherton | Monday 29 January 2007 15:01 PM | In Flex

The beta 2 of AMFPHP 1.9 has been released to the claim of:

amfphp the fastest Remoting implementation ever

The performance figures are truely impressive. Time I started having a mess around with getting PHP talking with Flex 2 methinks…

Jan 29

I never knew that about expandpath…

Posted by James Netherton | Monday 29 January 2007 15:01 PM | In ColdFusion

Bit of a noobish thing but I never realised with the expandpath function that you could use ColdFusion mappings.

Comes in handy if you’ve got a set of resources tucked away under a particular directory.

Jan 21

Performance issue?!?

Posted by James Netherton | Sunday 21 January 2007 14:01 PM | In ColdFusion

Doh!

I just spent the best part of today trying to work out, what I thought, was a performance problem.

I’m working on an application that kicks off a fairly resource intensive batch process but I was surprised to see RAM being gobbled up at an alarming rate.

So I started a process of commenting out various bits of code until I found where I thought where the problem was occurring. Even testing this piece of code in isolation would still causing memory spikes.

I then remembered how frameworks like model-glue and ColdSpring, call lots of cfc methods which can have a big impact on performance when CF debugging is enabled.

Although I had a cfsetting statement turning off debug output, I still had the overall debug setting enabled in the CF administrator. So changed the setting and hey presto! My system resources are no longer being chewed up.

Brian Rinaldi posted something similar last year:

ColdFusion Debugging Performance Hit

Jan 20

Problem with query of queries and flex

Posted by James Netherton | Saturday 20 January 2007 13:01 PM | In ColdFusion

It may be a quirk or just me misunderstanding the way in which query of queries works.

Here’s an example:

<cfscript>
	variables.boyNameList = "James,David,John";
	variables.boyNames    = queryNew("id, name");

	variables.girlNameList = "Jane,Sarah,Betty";
	variables.girlNames    = queryNew("id, name");

	for(i = 1; i lt listLen(variables.boyNameList); i = i + 1)
	{
		queryAddRow(variables.boyNames);
		queryAddRow(variables.girlNames);

		querySetCell(variables.boyNames, "id", i);
		querySetCell(variables.boyNames, "name", listGetAt(variables.boyNameList,i));

		querySetCell(variables.girlNames, "id", i);
		querySetCell(variables.girlNames, "name", listGetAt(variables.girlNameList,i));

	}
</cfscript>

Which produces the following query recordsets:

Record sets

Now create a cartesian product:

<cfquery name="joinNames" dbtype="query">
	SELECT
		boyNames.name   AS boysNames,
	        girlNames.name  AS girlsNames
	FROM
		boyNames,
		girlNames
</cfquery>

Record sets

Even though the column names were aliased, the query metadata hasn’t changed.

Query metadata

Why would this ever be any problem? It turns out that if you were to return this query object back to Flex and bind it to the DataGrid component, only one column titled ‘name’ would be displayed.

It appears that Flex uses the query metadata to determine the query column names, so no matter what aliases exist, they are ignored.

So if one wanted to change the query metadata, how could this be achieved? ColdFusion reperesents query metadata through objects of type coldfusion.sql.QueryTableMetaData. This object exposes a method that allows column names to be set:

public void setColumnLabel(String colLabel[])
{
	column_label = colLabel;
}

Change the metadata:

<cfset newColumnNames = "boysNames,girlsNames">
<cfset joinNames.getmetaData().setColumnLabel(newColumnNames.Split(","))>

And the query metadata has changed:

Query metadata

Jan 18

Do certifications matter?

Posted by James Netherton | Thursday 18 January 2007 9:01 AM | In ColdFusion

An interesting article has been posted on Codinghorror.com about the usefulness of certification in the software world.

This sentence rings true for me:

You should be spending your time building stuff, not studying for multiple choice tests. But that doesn’t mean they’re worthless, either. I don’t think certifications get in the way, as long as you can demonstrate an impressive body of work along with them

Certainly it’s worth getting certified in most disciplines (including ColdFusion) but you should always be able to back it up with some sort of portfolio of work.

Some employers seem to blindly take for granted that certification is the mark of a good programmer, when in reality, some certified individuals can’t program their way out of a wet paper bag.

Jan 14

Permanent ComboBox Prompt in Flex 2

Posted by James Netherton | Sunday 14 January 2007 17:01 PM | In Flex

One of the things that bugs me about the flex combo box component is that if you set a default option, or prompt, it disappears once the user selects a value from the drop list.

The permanent flex combo box prompt was recently posted Adobe Flex Cookboox site to solve the problem.

Jan 14

Invoking a webservice using CFHTTP

Posted by James Netherton | Sunday 14 January 2007 16:01 PM | In ColdFusion

ColdFusion provides a simple method invoking and consuming web services via the CFINVOKE tag or CreateObject function. It’s also possible to use CFHTTP to send and receive SOAP messages although you loose the advantage of ColdFusion handling all of the request and response data for you.

So why would you ever want to use CFHTTP over the friendlier methods above???

One example is when a third party was trying to hook into some web services that had been written at work and the service call was constantly sending back HTTP 500’s. In the end I decided to replicate what the other party was doing by using CFHTTP and posting raw SOAP to ColdFusion.

Here’s an example of how this might work:

First an example of a simple ColdFusion webservice:

<cfcomponent output="false" style="rpc">

	<cffunction name="addNumbers" access="remote" returntype="numeric" output="false">
		<cfargument name="firstNumber" type="string" required="true"/>
		<cfargument name="secondNumber" type="string" required="true"/>

		<cfreturn arguments.firstNumber + arguments.secondNumber/>

	</cffunction>

</cfcomponent>

Now the webservice calling code with CFHTTP

<!--- You'd need to strip any whitespace before passing to CFHTTP --->
<cfsavecontent variable="soap">
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
	<ns1:addNumbers soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://directorypath">
		<firstNumber xsi:type="xsd:string">100</firstNumber>
		<secondNumber xsi:type="xsd:string">10</secondNumber>
	</ns1:addNumbers>
   </soapenv:Body>
</soapenv:Envelope>
</cfsavecontent>

<!--- Note that there's no ?wsdl appendage to the url --->
<cfhttp url="http://myserver/webservice.cfc" method="post">
	<cfhttpparam type="header" name="content-type" value="text/xml">
	<cfhttpparam type="header" name="SOAPAction" value="">
	<cfhttpparam type="header" name="content-length" value="#len(soap)#">
	<cfhttpparam type="header" name="charset" value="utf-8">
	<cfhttpparam type="xml" name="message" value="#trim(soap)#">
</cfhttp>

<!--- Dump out a nice representation of the SOAP response --->
<cfdump var="#xmlParse(cfhttp.FileContent)#">

The result should be contained within a tag named something like addNumbersReturn.

And that’s it! Hopefully it’ll be of use to somebody somewhere.

Jan 14

Jumping on the blog bandwagon

Posted by James Netherton | Sunday 14 January 2007 13:01 PM | In Blogging

Well I’ve finally decided to bow to the inevitable and have started my own blog. Primarily I’ll be posting about ColdFusion, Flex and general technology related items. Hopefully some people will find my ramblings useful.

I’m still trying to tweak the CSS, so if some things look a little weird, it’s because I haven’t got around to fixing the styling yet.

Thanks to Ray Camden for blogcfc and open source web design for the base layout templates & styling.