Mar 30

Importing Firefox RSS bookmarks into Google Reader

Posted by James Netherton | Friday 30 March 2007 10:03 AM | In FireFox

My collection of bookmarked RSS feeds is getting larger and larger. Up until now, I’ve been using Firefox as my RSS reader and everything integrates nicely into the bookmarks toolbar.

Now that the collection of bookmarks has grown, Firefox is becoming a pain to maintain everything. Plus, I have a different collection of bookmarked feeds on my work PC and my home PC.

I’ve decided to make the jump over to Google reader. Google reader has an import feature that requires a OMPL file. Firefox only allows you to export bookmarks to an HTML file. Enter this plugin:

http://www.efinke.com/addons/opml-support/

It adds an option to export Firefox bookmarks to OMPL format. I’ve now imported everything into Google reader. I’m not sure how long I’ll stick with it though, I may check out some of the other online RSS readers.

Mar 30

Consuming ColdFusion webservices from PHP

Posted by James Netherton | Friday 30 March 2007 10:03 AM | In PHP

If you expose a ColdFusion component as a webservice and have arguments or a return type of type struct. In the resulting webservice WSDL, the struct is represented as a complexType.

To see what I mean, I’ve created an example CF webservice component:

<cfcomponent>

	<cffunction name="exampleMethod" access="remote" returntype="struct">
		<cfargument name="personName" type="string"/>
		<cfargument name="personDetails" type="struct"/>

	</cffunction>

</cfcomponent>

Here’s a snippet of how the struct data type is represented within the WSDL:

<!-- Here are the service parameters -->
<wsdl:message name="exampleMethodRequest">
    <wsdl:part name="personName" type="xsd:string"/>
    <wsdl:part name="personDetails" type="apachesoap:Map"/>
</wsdl:message>

Note that the personDetails parameter is of type apachesoap:Map. Here’s the definition for apachesoap:Map:

<complexType name="mapItem">
<sequence>
    <element name="key" nillable="true" type="xsd:anyType"/>
    <element name="value" nillable="true" type="xsd:anyType"/>
</sequence>
</complexType>

As we’d expect, it’s a simple key / value hashmap which is essentially what the CF struct is.

No lets add some simple logic into the webservice method that I showed earlier:

<cfcomponent>

	<cffunction name="exampleMethod" access="remote" returntype="struct">
		<cfargument name="personName" type="string"/>
		<cfargument name="personDetails" type="struct"/>

		<!--- Create a response strcure --->
		<cfset var result = structNew()/>

		<!---
			  Just build up a big list containing the info we
		      got from the personDetails argument
		--->
		<cfset result["personProfile"] = listAppend(result["personProfile"],arguments.personName)/>
		<cfset result["personProfile"] = listAppend(result["personProfile"],arguments.personDetails["age"])/>
		<cfset result["personProfile"] = listAppend(result["personProfile"],arguments.personDetails["gender"])/>
		<cfset result["personProfile"] = listAppend(result["personProfile"],arguments.personDetails["dob"])/>

		<cfreturn result/>

	</cffunction>

</cfcomponent>

Nothing too complicated going on there. The service expects a string argument and a structure which is expected to contain age, gender and dob keys. Creating a webservice call to invoke this service in ColdFusion would be an extremely simple task, but how would one use PHP to invoke this service?

It’s more complicated than you probably think due to the usage of structs and complexTypes. After doing some research, returning structs, arrays and query data types from webservices is not best practice. There are many forum posts from PHP, .NET and Java developers who have encountered problems resolving these data types via webservice calls.

So how would one use PHP to pass the personDetails struct parameter to a ColdFusion webservice?

I’ll be using nusoap to consume the webservice. Here’s the PHP script:

 <?php
//Import the SOAP library

require_once('nusoap.php');

//Get a handle to the webservice

$wsdl=new soapclient('http://myserver/example.cfc?wsdl',true);

/*
	Define a class that represents the parameters being passed into the service:

	- personName     <string>
	- personDetails  <ColdFusion struct>
*/
class complexType{

	//personName is a simple string

	var $personName = 'Homer Simpson';

	//personDetails is a CF struct so define as an associative array

	var $personDetails = array('age'=>'35',
					   'gender'=>'Male',
					   'dob'=>'01/05/1971');
}

//Create an instance of the complexType object

$complex = new complexType;

$proxy = $wsdl->getProxy();

//Call the webservice exampleMethod method and pass in the parameters

$result = $proxy->exampleMethod($complex);

//Display the results contained in the personProfile element

echo($result["exampleMethodReturn"]["personProfile"]);
?> 

Notice that the response is returned in an associative array with the top level element being named ‘exampleMethodReturn’. If you look at the WSDL for the service, you’ll see the definition for this:

 <wsdl:message name="exampleMethodResponse">
<wsdl:part name="exampleMethodReturn" type="apachesoap:Map"/>
</wsdl:message>

And that’s all there is to it!

Mar 24

Blog broken in IE 6

Posted by James Netherton | Saturday 24 March 2007 9:03 AM | In Blogging

A post to remind me to get my arse in gear and fix the site layout in IE 6. I know the main body content appears waaaaay down the page. I changed something a while back and haven’t been able to pin down what is causing the problem.

Hopefully I’ll get it sorted soon, or get someone with better CSS skills than me to fix it!

Mar 24

Microsoft has the most secure OS

Posted by James Netherton | Saturday 24 March 2007 9:03 AM | In Windows

According to Symantec anyway, as they released their 11th internet security report.

There’s a nice run down here . Needless to say it’s caused its fair share of controversy. There’s been some pretty intense flaming happening on a forum I belong to and the article has made its way onto Digg.

I’m just going to stay tight lipped and let everyone else fight it out :)

Mar 22

The “Works on My Machine” Certification Program

Posted by James Netherton | Thursday 22 March 2007 11:03 AM | In Funny

No doubt we’ve all said at some point to our business users “Well it worked on my machine!”. Well, now you can join the certification program!

Mar 21

CFHTTP Caches DNS Lookup

Posted by James Netherton | Wednesday 21 March 2007 15:03 PM | In ColdFusion

I seem to be getting my fair share of weird issues to solve at work lately. Today I came across some odd behavior with CFHTTP. I was hooking into a XML HTTP service and everything was working fine until I migrated the application to a production web server which runs CFMX 6.1.

Then, the CFHTTP call to the XML service stopped working. I couldn’t get any response other than “connection failure”. I was totally baffled as I tested the application on other servers and verified the web server could resolve the URL that I was using.

To cut a long story short, using the target ip address in place of the DNS name, solved the problem. I did some searching around to see what may have been the issue and came across these articles:

CFMX and DNS caching

Changing CFHTTP DNS Caching Behavior

Adobe tech note

So you can see, Java caches the DNS lookup forever, until you recycle the ColdFusion service.

Something to be aware of when using CFHTTP.

Mar 19

First steps with Apollo

Posted by James Netherton | Monday 19 March 2007 16:03 PM | In AIR

After a 20 minute hack with Apollo I’ve written an extremely simple application which takes some HTML input and renders it using an HTML component. There’s the option to save the file to a plain text .HTML file as well.

Here’s the code:

<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

	<mx:Script>
		<![CDATA[
			import flash.filesystem.*;

			public function saveHTMLFile():void
			{
				var file:File = File.desktopDirectory;
				file = file.resolve("myHTML.html");

				var stream:FileStream = new FileStream();
				stream.open(file, FileMode.WRITE);
				stream.writeUTFBytes(HTMLText.text);
				stream.close();
			}

		]]>
	</mx:Script>

	<mx:VBox height="100%" width="100%">
		<mx:TextArea id="HTMLText"
			         width="100%"
			         height="100%"/>

		<mx:HTML htmlText="{HTMLText.text}"
				 width="100%"
				 height="100%"/>

		<mx:ControlBar>
			<mx:Button label="Save HTML Document"
					   click="saveHTMLFile()"
					   enabled="{HTMLText.text != ''}"/>
		</mx:ControlBar>

	</mx:VBox>

</mx:ApolloApplication>

I can’t wait to have a proper experiment with everything. Download the Apollo runtime from the Adobe labs site and check out the sample applications.

My list of technologies to experiment with grows ever larger. So much to learn so little time!

Update: Freaky, I didn’t realise Ray Camden posted a similar application before me. It appears there’s some others out there that do pretty much the same thing, except for the save function. Looks like several people all had the same idea for their first Apollo application.

Mar 19

Environment Variables With ColdFusion

Posted by James Netherton | Monday 19 March 2007 15:03 PM | In ColdFusion

I came across this today by accident. I never knew that ColdFusion was able to pick up any environment variables that are set within the host operating system. Here’s how I came across this behavior…

I was hacking together a sort algorithm and naughtily, for the purposes of being able to quickly see things working, I did not scope my variables. One of my variables was named temp. I started getting some freaky errors, you’ll understand why if you run this code on a Windows system:

<cfoutput>#temp#</cfoutput>

Which will produce something like “C:\windows\temp”.

What’s interesting is that the variable exists within the CGI variable scope. But, CFDUMP the CGI scope and they’ll be no sign of a variable named “temp”.

What’s happening is that ColdFusion is picking up my system environment variables and is making them available via the CGI scope. Here are some of the environment variables configured on my home PC:

Environment Variables

So I should no be able to do something like the following:

<cfoutput>#cgi.os#</cfoutput>

Produces :- Windows_NT

<cfoutput>#cgi.number_of_processors#</cfoutput>

Produces :- 2 (I have a dual core CPU).

The other thing I learnt was that you can use any nonsense (so long as it’s a valid ColdFusion variable name) with the CGI scope:

<cfoutput>#cgi.var_that_does_not_exist#</cfoutput>

Interesting!

Mar 10

Which platform at Clapham Junction?

Posted by James Netherton | Saturday 10 March 2007 11:03 AM | In Blogging

Clapham Junction, one of Britain’s busiest, largest and most confusing stations.

Here’s a guide as to where each of the 17 platforms lead to:

Clapham Junction Platform Guide

This post is more for my reference where I end up lost when I’m coming back from visiting my girlfriend :)

Mar 09

Windows taskkill

Posted by James Netherton | Friday 09 March 2007 4:03 AM | In Windows

One thing I like about ‘nix systems is that it’s pretty easy to kill off specific or a list of processes via the command line using pipes and grep.

The Windows command line has the taskkill command:

Examples:
    TASKKILL /S system /F /IM notepad.exe /T
    TASKKILL /PID 1230 /PID 1241 /PID 1253 /T
    TASKKILL /F /IM notepad.exe /IM mspaint.exe
    TASKKILL /F /FI "PID ge 1000" /FI "WINDOWTITLE ne untitle*"
    TASKKILL /F /FI "USERNAME eq NT AUTHORITY\SYSTEM" /IM notepad.exe
    TASKKILL /S system /U domain\username /FI "USERNAME ne NT*" /IM *
    TASKKILL /S system /U username /P password /FI "IMAGENAME eq note*"

So say you had multiple instances of notepad open. You could kill them all off using:

taskkill /F /IM notepad*

You can also use filters on things like image name, process ID and CPU time. For example, you could attempt to kill all process names that didn’t equal notepad.exe:

TASKKILL /F /FI "IMAGENAME ne notepad.exe"

Or kill all processes with id’s greater than 1000:

TASKKILL /F /FI "PID gt 1000"

Use the command sparingly and with caution of course ;-)

Mar 08

Cairngorm Eclipse Plugin

Posted by James Netherton | Thursday 08 March 2007 15:03 PM | In Flex

This looks awesome!

Introducing Cairngorm Plugin

If only this were around a few months ago! It would have made development of a Flex application I’m working on, a breeze! Check out some of the screen shots over at the site.

Mar 08

Remember CFHTMLHEAD ?

Posted by James Netherton | Thursday 08 March 2007 15:03 PM | In ColdFusion

I imagine it’s a tag that doesn’t get a great deal of usage (if any) in most people’s applications. But it helped me turn what would have been a lengthy and laborious task, into a 1 minute fix.

I had a request to add some JavaScript code into the head section on a particular website. Trouble was, most of the pages were static and the page header content was hard coded across some 50 templates.

Naturally I didn’t want to insert the same chunk of code into all of those templates, there’s also so the potential to make mistakes with so many pages to alter.

Enter cfhtmlhead. The tag lets you insert content into the head section within a web page. So within my Application.cfm (or .cfc) I ended up with the following:

<cfhtmlhead text="<script language=""javascript"" type=""text/javascript"">my code here</script>"/>

The script then appears on all of my site pages. Obviously it’s pretty simple to exclude the code from being output when you don’t want it to be.

I know there are loads of other ways I could have achieved this but it seemed the most trouble and pain free at the time :)

Mar 01

var scoped variables uncovered

Posted by James Netherton | Thursday 01 March 2007 16:03 PM | In ColdFusion

I was messing around with some of the ColdFusion coldfusion.runtime.NeoPageContext methods which can be utilised via the getPageContext() method.

One of the methods is getActiveFunctionLocalScope(), which, as it’s name suggests, returns the active locally scoped variables within a CF function.

For example:

<cffunction name="test" returntype="void">
	<cfset var a = "I'm a"/>
	<cfset var b = "I'm b"/>
	<cfset var c = "I'm c"/>

	<cfset localScope = getPageContext().getActiveFunctionLocalScope()/>
	<cfdump var="#localScope#">

</cffunction>

<cfset test()/>

Produces the output:

Local scope structure

What would be cool is if you could add variables to the local scope on-the-fly without declaring them. It must be possible so I’ll have a look at some of the other methods.

Mar 01

A couple of blasts from the past

Posted by James Netherton | Thursday 01 March 2007 8:03 AM | In Programming

I stumbled upon a couple of Visual Basic apps that I wrote just after I started programming in 2001:

http://www.a1vbcode.com/author.asp?name=James+Netherton

I was learning VB at college and fiddling around with windows API stuff.

The first application demonstrates window enumeration and lets you manipulate all of the windows that are currently loaded.

The second application was supposed to be a utility that allowed you to add commonly used applications to a list which could be accessed via the systray. There’s a bad bug in it which means it crashes when it first runs!

Happy to say I’ve learned from my mistakes 6 years on :)