Solved: Strange sun.awt.X11.XToolkit exception with Mach-II/Railo/Tomcat/Ubuntu

ColdFusion, Ubuntu, Technology, Linux, Java, Mach-II

I am running a BER version of Railo to experiment with the Hibernate ORM functionality for a new project.  I set up a Mach-II app from the 1.8 skeleton using Mach-II 1.8.1 on Railo under Tomcat6 on Ubuntu... whew!  That's a mouthful huh?

The simple skeleton came up just fine, but after a little bit of customization, I ran across a strange issue.  I had created an event, in which a listener pulled a new entity from a ColdSpring bean, and persisted it using EntitySave().  Somewhere in that process, I started getting exceptions related to sun.awt.X11.XToolkit. 

The first time the error would occur, I would see this:

Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.

 /var/lib/tomcat6/webapps/railo-orm/MachII/properties/HtmlHelperProperty.cfc: line 142

    140: <!--- Configure auto-dimensions for addImage() --->
    141: <cfif StructKeyExists(serverInfo, "productLevel") AND serverInfo.productLevel NEQ "Google App Engine">
    142: <cfset variables.AWT_TOOLKIT = CreateObject("java", "java.awt.Toolkit").getDefaultToolkit() />
    143: <cfelse>
    144: <!--- Some hosts (such as GAE) do not support java.awt.* package so replace with mock function --->

On subsequent requests, I would get the following:

Could not initialize class sun.awt.X11.XToolkit again with the specitic exception pointed to HtmlHelperProperty.cfc: line 142.

After some Googling I came across a similar sounding issue in which a guy had added params to his app server.  I added it to mine, and the error went away.  If you come across this yourself, try adding: -Djava.awt.headless=true to the JAVA_OPTS (in catalina.sh for Tomcat).

 

 

 

Roof rack installation on my Jeep CJ5

Jeep

About 9 years ago I bought a Confer roof rack for a CJ7 I had at the time. I ended up modifying the rear and replaced the stock tail lights with slim LEDs and there wasn't enough sheet metal left in the rear to use the Confer brackets.



Along with a few other projects that never came to be, I just stuck the kit along the side wall in my garage and figured I would put it up on craigslist eventually. This past year I picked up a CJ5 which I am driving a lot more than I ever guessed that I would. I want to be able to throw my backpack, tent, and canoe up on top and go with ease, so I decided I would mod the CJ7 rack to fit on the CJ5 and install it. To be perfectly honest, I am a little on the fence about how I feel about roof racks on open-top Jeeps, but functionality wins over form with me for the most part.



The first immediate problem was that the rear brackets are designed to mount flush up against the tub sandwiched by the tail lights. On my CJ5, there is no tailgate, and instead there is a support that is raised out from the tub about an 1" that was creating interference. If I were to cut that support to make it fit, I still had an issue that it would block the bottom of the soft top slot and I would have a hell of a time getting the rear of the top fastened like that. I opted to space the tail lights back 1" using some square tube like this:



(All pics click to larger resolutions)











The next problem was the somewhat obvious one in that the lengths of the CJ7 and CJ5 are about 10-ish inches different. The lateral tubes are round, but flattened on each end where the bolts go through. I initially thought about taking out a section in the middle, leaving both ends intact, but I decided I would just try cutting off an end, and crushing the open end flat using my vice. Here is the first piece that I cut off.







After flattening the open end on the longer piece using the vice, drilling the, hole and doing a test fit, I confirmed that my mod was going to work perfectly. Here is a shot of a couple of the flattened ends.







Overall, the finished product came out pretty well, although I am still not sure how I feel about racks on CJs in general! Here are some pics:











How to install a Mac theme for Windows

Tips and Tricks, Windows, Technology
I was just delivered a new laptop from my company. It is a smoking smoking Dell E6500 duo core processor with a sweet solid stated drive and.... Windows XP (booo!).

While it is a very stable system, I can't help but have flashbacks to the early 2000's when I look at the XP windows manager. It just looks so dated by today's standards. After about 20 minutes I just couldn't take it any more and had to modify the look. I came across a great looking Mac theme for XP and I have to say that overall I am pretty pleased with the look and feel now. Here is a screenshot of what it looks like now:

(click for full-size)


If you want your Windows XP machine to look like that, then do the following. First you will need to run a patch utility that allows you to install non-Microsoft approved themes such as this. Given the restrictive nature of Microsoft software, this is surprisingly easy to do. Download the UXtheme Multi-patcher for free from softpedia.com.  Inside the zip file you will find a single executable file.  Run it and follow the instructions. 

When that step is complete, you have now freed yourself to be able to install any theme you like.  You can find lots of themes at places like deviantArt and  WinCustomize.com.  The former is where I found the Mac Panther theme that we will be using.  Download that theme and unzip the contained "Panther" folder to C:\WINDOWS\Resources\Themes.  Once you do this, go into that folder and double-click the file Panther.msstyles.  With this step, you have now installed the theme.  To finish the look though, I took a few other steps.

First, I moved my start bar to the top of the screen.  If you can't drag yours, you may need to right-click on the task bar and un-check "Lock the Taskbar".  After I moved it, I found that it left an undesirable border line on the bottom of the bar that I corrected by rechecking "Lock the Taskbar". 

So what about that background?  I found a pretty nice looking version of that Mac inspired wallpaper here.

And lastly, it is time to create that launcher that you see at the bottom of the screen.  RocketDock is an really clean (and free!) application launcher for windows.  Download RocketDock from here and install.  Customize the options as you see fit and you are done!

So here is the bottom line... Is this whole idea a little bit goofy?  Perhaps.  However, it is far less goofy than a default XP theme for damn sure.  It gives it a really clean feel and I am no longer quite as bitter about having XP. :)

Need a "rock star" ColdFusion speaker for 7/30/2010 event in Dallas

ColdFusion, General, Technology, Conferences, CFML
Last year was the second annual Dallas TechFest, which is a 1-day multi-platform event centered around programming.  They approached me at that time about bringing ColdFusion into the event, and giving us a dedicated track in one of the rooms.  I made a optimistic claim that we could bring in 50+ CFML devs from the area, and low and behold, we ended up with 70+ people that registered with the discount code from our user group.  It was very successful and had a good buzz with the local community.  Additionally, we blew the PHP and Ruby groups out of the water! :)  

For 2010, the organizers have offered a travel and expenses budget to to each track (CF being one of those) to pay for travel and expenses to get one "rock star" from each of the technologies. Based on last year's attendees, I would say that a large percentage were beginner-intermediate, with our regular core of advanced guys around as well.  The event will be on Friday July 30, in Addison.  Unfortunately this falls during the same week as CFUnited, which obviously zaps a number of speakers from the pool of availability, but if you are interested in speaking, please let me know!  I am dshuck pretty much everywhere... gmail, twitter, facebook, etc.

UDF: pcase() - Captilize first letter of each word in a string

ColdFusion, Tips and Tricks, Technology, CFML, UDF
This is a UDF that I keep on hand for converting strings to "proper case", such as a person's name.  For instance, in a database we might have a name stored like DAVID B. SHUCK, but when they log into our site and we welcome them, we don't necessarily want to shout it at them!   Saying "Hello David B. Shuck..." would hopefully be a bit less abrasive. 

Enter the user-defined function pcase().  Through the use of regular expressions we are doing a search for word patterns and capitalizing the first letter in each word.  Enjoy!




<cffunction name="pcase" access="public" output="false" returntype="string">
    <cfargument name="string" type="string" required="true" />
    <cfreturn REReplaceNoCase(LCase(arguments.string),"(^[a-z*]|[ *][a-z*])","\U\1\E","all") />
</cffunction>

Implicit constructor and CF9 style implicit accessors without ColdFusion 9

ColdFusion, Tips and Tricks, Technology, CFML
One of the broadly welcomed features of ColdFusion 9 has been the addition of implicit getters and setters to CFCs.  What this means is that you no longer have to hand code the repetitive boiler plate getXXX() and setXXX() methods for each property in your model objects. However, you don't need ColdFusion 9, (or even ColdFusion for that matter) to enjoy the benefits of the new implicit accessors with the version 9 release.  Since ColdFusion 8, developers have had access to the OnMissingMethod() method which makes tasks like this very simple to implement on your own.  The OnMissingMethod is also available in current versions of OpenBlueDragon and Railo.

For my implementation of this, I use a standard BaseBean class in a number of my projects which is extended by all of my model class objects.  By leveraging the OnMissingMethod() in this BaseBean, I create these implicit accessors, in addition to an implicit constructor init() method as well.

There are multiple examples on the internet that show how you can use OnMissingMethod(), but for the most part, the examples that I have come across do not protect the class from being having infinite previously undefined properties added to it from the outside.  For instance, I could have a class named Person.cfc with define properties of "firstName" and "lastName", but nothing would stop someone from doing Person.setThisIsNotAProperty(true) and that value would be dynamically added to the Person instance.  While some might argue that the flexibility that this approach offers is a positive thing, I prefer to lock my classes down just a bit more.  For instance I like the fact that I can open up a model class and see exactly what properties it can contain with clearly defined <cfproperty/> tags.   From a maintainability standpoint the idea of "mystery" dynamic properties strike me as just wrong.

For my implicit constructor, I take an approach where I loop through any named arguments that were passed, and if the name matches a property that I have defined with <cfproperty/>, then it will be passed to a setter method.  Any arguments that are passed that are not defined as a property are discarded.

So let's take a look at what this looks like.  First I will paste the entire BaseBean, and below we will break it apart to discuss what is going on.
<cfcomponent output="false">
	
		
	<cffunction name="init" access="public" output="false" returntype="BaseBean">
		<cfset var i = "" />
		<cfset initializePropertyList() />
		<cfloop list="#this.propertyList#" index="i">
			<cfif StructKeyExists(arguments,i)>
				<cfset set(i,arguments[i]) />
			</cfif>
		</cfloop>		
		<cfreturn this />
	</cffunction>
	
	
	<cffunction name="initializePropertyList" access="private" output="false" returntype="void">
		<cfset var i = "" />
		<cfif NOT StructKeyExists(this,"propertyList")>
			<cfset this.propertyList = "" />
			<cfif ArrayLen(GetMetadata(this).properties)>
				<cfloop from="1" to="#ArrayLen(GetMetadata(this).properties)#" index="i">
					<cfset this.propertyList = ListAppend(this.propertyList,GetMetadata(this).properties[i].name)>
				</cfloop>
			</cfif>
		</cfif>		
		<cfreturn />	
	</cffunction>


	
	<cffunction name="onMissingMethod" access="public" output="false" returntype="any">
		<cfargument name="missingMethodName" type="string" required="true" />
		<cfargument name="missingMethodArguments" type="struct" required="true" />
		
		<cfset var property = "" />
								
		<cfif ReFindNoCase("^[gs](et)",arguments.missingMethodName)>
			<cfset property = ReReplaceNoCase(arguments.missingMethodName,"^[gs](et)","") />
			<cfset initializePropertyList() />

			<cfif ListFindNoCase(this.propertyList,property)>
				<cfif StructIsEmpty(arguments.missingMethodArguments)>
					<cfreturn get(property) />
				<cfelse>
					<cfset set(property,arguments.missingMethodArguments[1]) />
					<cfreturn this />
				</cfif>	
			<cfelse>
				<cfthrow message="The class #GetMetadata(this).name# does not have a property named #property# so the implicit #arguments.missingMethodName#() method is not available." />		
			</cfif>

		</cfif>	
		<cfreturn />	
	</cffunction>
	
	<cffunction name="get" access="public" output="false" returntype="any">
		<cfargument name="property" type="string" required="true" />
		<cfset var value = "" />
				
		<cfset value = variables[arguments.property] />
			
		<cfreturn value />	
	</cffunction>
	
	<cffunction name="set" access="public" output="false" returntype="void">
		<cfargument name="property" type="string" required="true" />
		<cfargument name="value" type="any" required="true" />
		
		<cfset variables[arguments.property] = arguments.value />
		
		<cfreturn />
	</cffunction>
	
</cfcomponent>

Before we walk through the actual flow, I would like to point out the method initializePropertyList() that you see here:
<cffunction name="initializePropertyList" access="private" output="false" returntype="void">
	<cfset var i = "" />
	<cfif NOT StructKeyExists(this,"propertyList")>
		<cfset this.propertyList = "" />
		<cfif ArrayLen(GetMetadata(this).properties)>
			<cfloop from="1" to="#ArrayLen(GetMetadata(this).properties)#" index="i">
				<cfset this.propertyList = ListAppend(this.propertyList,GetMetadata(this).properties[i].name)>
			</cfloop>
		</cfif>
	</cfif>		
	<cfreturn />	
</cffunction>

By using the GetMetadata() function, we are able to introspect our instance and create a list of property names which we can reference in our other methods.  This is what enables us to enforce the rules that I described above in which we make sure that a property exists before setting it in the constructor or through an implicit accessor.  You will see in both the init() and OnMissingMethod() methods that we call this method to ensure the list of properties is available before testing against it.

With that established, let's take a look at the init() constructor method:
<cffunction name="init" access="public" output="false" returntype="BaseBean">
	<cfset var i = "" />
	<cfset initializePropertyList() />
	<cfloop list="#this.propertyList#" index="i">
		<cfif StructKeyExists(arguments,i)>
			<cfset set(i,arguments[i]) />
		</cfif>
	</cfloop>		
	<cfreturn this />
</cffunction>

After making sure that our propertyList has been initialized, we loop through that list and if there is a matching named argument, we call the set() method which sets that value into the variables scope.

So with the object initialized, let's take a look at our accessors.  For our example, let's say that we have a Person object and we are doing to set our firstName property like this: person.setFirstName("Dave").  Since that setter method doesn't exist in our Person class, the OnMissingMethod() below will be invoked. 
<cffunction name="onMissingMethod" access="public" output="false" returntype="any">
	<cfargument name="missingMethodName" type="string" required="true" />
	<cfargument name="missingMethodArguments" type="struct" required="true" />
	
	<cfset var property = "" />
							
	<cfif ReFindNoCase("^[gs](et)",arguments.missingMethodName)>
		<cfset property = ReReplaceNoCase(arguments.missingMethodName,"^[gs](et)","") />
		<cfset initializePropertyList() />

		<cfif ListFindNoCase(this.propertyList,property)>
			<cfif StructIsEmpty(arguments.missingMethodArguments)>
				<cfreturn get(property) />
			<cfelse>
				<cfset set(property,arguments.missingMethodArguments[1]) />
				<cfreturn this />
			</cfif>	
		<cfelse>
			<cfthrow message="The class #GetMetadata(this).name# does not have a property named #property# so the implicit #arguments.missingMethodName#() method is not available." />		
		</cfif>

	</cfif>	
	<cfreturn />	
</cffunction>

We are then doing a regular expression test to see if the missing method names starts with either "get" or "set".  If so, we derive the name of the target property by stripping the "get" or "set" off of the string.  After making sure that our propertyList has been defined, we then look in that list to see if the target property actually exists in the instance.  If it does, the request is then routed on to either the getter or the setter depending on whether arguments were passed to it.  Otherwise an exception will be thrown to let the developer know that he or she has attempted to access an undefined property.

One thing you might notice is that when our conditional block routes the request to the setter, we return an instance of the class itself.  This allows us to do method chaining like this:  person.setFirstName("Dave").setLastName("Shuck").  it should be noted that this is not the approach that Adobe took with ColdFusion 9.

So let's take a look at it in action.  Here is our Person.cfc class.
<cfcomponent output="false" extends="BaseBean">
	
	<cfproperty name="id" type="string" />
	<cfproperty name="firstName" type="string" />
	<cfproperty name="lastName" type="string" />
	
</cfcomponent>

As you can see in the <cfcomponent/> tag, we are extending our BaseBean which is all that we need to have a workable domain class object.

When we put this together and access it in our code, we can do this:
<cfset person = CreateObject("component","Person").init(id=7,firstName="Dave", lastName="Shuck") />

<cfdump var="#person#" />



Once we have an instance, we can modify those properties like so:
<cfset person.setId(8).setFirstName("Johnny").setLastName("Rotten") />



I have not actually tested this on Railo, but I can confirm that it works in OpenBlueDragon (including GAE version), and ColdFusion versions 8 and 9. 



Search

Various Links

HikeTheCanyon.org - Rim-to-Rim hike of the Grand Canyon.
Dave Shuck on Twitter - Follow me on Twitter.
Scriptalizer - Minify your Javascript and CSS