The amazing adventures of Doug Hughes

Archive for March, 2007

I Got FDS Working!

As my recently blog entries have explained, I’m working on a few tests related to Flex, Flash Data Services and the Flex Messaging event gateway. Yesterday I was able to successfully send a message from a Flex client to ColdFusion, but I was completely unable to send a message from ColdFusion back to the Flex client.

After much pain and suffering and Googling I tried something a little crazy. I didn’t find any documentation telling me to do this, but I copied the entire sample messaging configuration from the config samples over the messaging configuration I had been hacking.

To clarify, I copied C:fds2resourcesconfigmessaging-config.xml over C:fds2jrun4serversdefaultsamplesWEB-INFflexmessaging-config.xml.

I had been hacking randomly at the messaging-config.xml and I must have done something wrong, though I have no idea what. Because, once the new messaging-config.xml was in place FDS restarted and, much to my amazement, I was able to send messages both ways!

Woo Hoo!

Now I need to figure out why Flex wants me to build my applications under the FDS server itself.

On top of that, I need to figure out how Flex knows what to connect to from the client. In the same I’ve been working with there are the following few lines of code which seem to setup all of the messaging infrastructure:

public var pro:mx.messaging.Producer;
public var con:mx.messaging.Consumer;

public function initApp():void {
pro = new mx.messaging.Producer();
pro.destination = "ColdFusionGateway"
consumer.subscribe();
}

This is quite nice, but I can only assume the client has the localhost hard coded into it somewhere. If not, then I have no clue how it works.

More as I learn more!

From LCDS to FDS

As I’ve been blogging lately, I’m trying to jump headfirst into Flex and Flex Data Services with ColdFusion. Actually, I had been trying to use Live Cycle Data Services, since it’s the newest shiniest version of FDS. But, it’s also beta and I’m not familiar enough with the previous versions to know where the beta really begins and ends. As a result I decided it was probably in my best interest to work with FDS express for now.

So, I uninstalled LCDS and installed FDS and began on my merry way. The first real problem I ran into (besides not having the faintest clue how to get started) was, well, getting started.

And I might joke about needing to know how to get started before I get started, but seriously, that was a problem. Eventually after reading a few articles on Adobe.com I stumbled across the Flex documentation in LiveDocs. (Brilliant!) Under the Getting Started with Flex 2 lessons (who would have thought!) I found "Use ColdFusion Event Gateway Adaptor".

This chapter was the most clear of any other information I found on getting started. It walked me through several steps of creating a Flex app that could send a message to ColdFusion and how to use ColdFusion to "push" data back up to Flex clients.

The first thing the instructions had me do is edit the FDS messaging-config.xml file. For some reason which is not yet clear to me, I’ll need to edit configuration files all the time with FDS. I believe that this is because although FDS is a server, it’s treated like a framework or an API. For instance, a lot of people gripe about having to create and edit Reactor’s XML file. I suspect that it’s the same basic concept. Before it can do anything, the server needs to be told what and how to do it. IOC, baby.

After attempting to get FDS setup I created an instance of the Flex Messaging event gateway in ColdFusion. Honestly, I don’t have any experience with this either. I couldn’t explain why, but I’ve always boycotted event gateways. I think my logic was that if I can’t use them across the board on any instance of ColdFusion then they’re too much trouble. That, and I hate needing to use the ColdFusion admin to setup event gateways!

(Now anyone who’s been paying attention may have noticed my contradiction: I hate editing XML to configure FDS and I hate using the UI to configure ColdFusion. That’s right! I want both of them to magically just know what I want without any extra effort on my part. Seriously though, I’d like configuration to be a part of my application, not stored in some external server. But, given the option between a UI and XML, I’d choose XML, so long as I understood it well.)

So, getting back on topic, I created a new instance of the Flex Messaging event gateway. And, from what I can tell, it doesn’t take a lot of work. You just give it an ID, point it at a CFC, and turn it on. Fun!

From there the docs took me through the process of creating a Flex UI for sending an email. The documentation provides all the code, which I simply copied and pasted into my app. As a part of this, you create instances of a messaging Producer and Consumer objects. These objects know how to create and listen for messages from the Flex server.

So, when I’m using the UI to send an email, when I click a send message button it runs some Actionscript that creates a message to send, it populates the message with important information an then uses the message Producer to send the message on down to FDS. FDS then presumably broadcast the exact same message out to all other clients that have an interest. Because of this, the Flex Messaging event gateway receives the message and passes it on down to the CFC I configured it to use.

The CFC that receives the message has a method, onIncomingMessage, which I assume is an interface requirement defined by the Flex Messaging event gateway. The CFC the docs had me write receives the message as a part of the arguments passed into this method. I use information pulled out of the message to send an email and, once that’s done, I send a message back to the Flex Messaging event gateway.

This is where it goes south for me. If I run my application I can type in all the details of the email in the Flex client and, when I click to send the email I can watch the message as it gets spooled by CF and sent out. However, CF never successfully makes the call back to the FDS server.

I’m running both FDS and ColdFusion from the command line so I can watch the resulting messages for debugging purposes. Initially the CF server was reporting an error related to the gateway message. I was able to work around that. (I don’t remember exactly what I did, but I think I shut down both servers and restarted Flex then ColdFusion.) Once that issue was fixed I saw another warning being reported by FDS:

[Flex] [WARN] HttpFlexSession has not been registered as a listener in web.xml for this application so no events will be dispatched to FlexSessionAttributeListeners or FlexSessionBindingListeners. To correct this, register flex.messaging.HttpFlexSession as a listener in web.xml.

Because this is a warning and not an error I probably would typically ignore this. However, my Flex client was not receiving messages sent from ColdFusion. Based on the error message, the fact that CF is sending the message without errors and that the Flex client isn’t getting the message, I suspect that there’s a configuration problem where FDS won’t send messages to clients served over HTTP.

I haven’t yet been able to work though this. I’m not familiar enough to know what it means to register HttpFlexSession in the web.xml. First off, there are no less than four web.xml files in the FDS folder under JRun. Two of these have this block of XML in them:

<!-- Http Flex Session attribute and binding listener support -->
<listener>
     <listener-class>flex.messaging.HttpFlexSession</listener-class>
</listener>

Not knowing what I’m looking at, it’s easy to assume that flex.messaging.HttpFlexSession is already registered. But, I don’t know! Googling any of this doesn’t result in anything useful.

So, that’s where I’m stuck. I can send messages to CF from a Flex client, but not the other way. As I work this out I’ll blog more and maybe it’ll be of use to someone in the future.

Getting Started With Flex, LiveCycle Data Services and ColdFusion (or Not)

I’ve taken it upon myself to “learn a little Flex”. It took me a few years, but I finally have an idea for an application that, if I knew how the heck to use FDS, wouldn’t take that long to write and would help me get my feet wet with a range of technologies I have an interest in.

For all intents and purposes I want to write a simple chat application. I’d like to create a browser-based chat client using Flex and then a desktop-based client for the same application using Apollo.

Since I’m just getting started and I have no plans to make this a real production application I decided to use the beta of LiveCycle Data Services 2.5 available on Adobe Labs (which is the next version of Flex Data Services renamed).

Because this is a chat system it seems makes sense to use LiveCycle Data Services. As I understand it, I can use LCDS to push data out to a client. So, if someone sends a message in my chat client I’d like it to be pushed to other chat clients.

Last night I (think I) downloaded all the components I need. Namely, FlexBuilder and LiveCycle Data Services. I got both installed and running. Great!

So… now what?

Well, I thought it would make perfect sense to simply create a new Flex project and see what I can do. So I fired up Eclipse and created a new Flex project. The first thing it asked me was how I wanted my application to access data. Easy, FDS!

However, it’s not that easy. First off I need to select if I want to Compile locally in Flex Builder or on the Server when the page is viewed. Heck if I know. So I guess “locally” and continue. The next page asks about locations of FDS. This is where I start getting iffy. It’s asking me where the FDS root folder is. I decide to go with the defaults (which are always right, I’m sure) and click continue a few times. But, when I’m sure I’m almost done I get a new dialog asking me about build paths where I note that the output path is under the LCDS server itself!

Well, I’m pretty sure I don’t want that, but I just don’t know. I’m hoping that I don’t have to serve Flex apps that use LCDS from under the LCDS server. I imagined that a Flex app that uses LCDS would work in a manner similar to using Flex with, for example, a web service. That is, I’d be able to create an instance of some object within my Flex app that handled my communication with LCDS. From how it looks right now, it seems that LCDS is baked at a lower level. Honestly though, I doubt that. Ultimately, I just don’t know.

So, rather than jumping in feet first I figured I’ll look for some tutorials on using FDS. A nice hello world application would have been a good starting point, for example. Unfortunately I couldn’t find much. I did find a nice article by Ben Forta discussing the purpose of FDS and how it could be used with FDS, but it didn’t give any concrete examples.

Another article I found by Tom Jordal actually provided a sample Contact Manager application and seemed quite promising. However, I can’t make sense of the configuration instructions he wrote. (Granted, I am fairly tired. I’ll try again tomorrow, time permitting.)

I tried to follow his instructions, which involved a lot more XML editing than I expected, but every time I restarted the LCDS server I saw pages of errors associated with the cfcontact destination XML Tom had me copying all over the place. (Note: steps 8, 9 and 10 seem to all be saying the same thing, as far as I can tell.)

So that’s where I got stuck. I’m not sure where my source goes, though both Flex Builder and the Contact Manager sample lead me to believe the FDS apps are stored under FDS. Ok, I’m sure I’ll learn why soon enough.

One thing that surprised me was the amount of XML editing I need to do just to get one application configured. I do somehow have to tell FDS how to connect my client to ColdFusion and I’m pretty sure that’s what I was trying to do. I would have expected there would be some cute UI I could click through to do this similar to ColdFusion’s administration interface. Heck, maybe there is!

I’m sure I’ll learn more as I move forward. I’ll try to write about my learnings here as I move along.

LiveCycle Data Services, RTMP and Port 2038

I have an idea I’ve been rolling around in my head for a nice Flex and Apollo application. Sorry, I won’t tell you what it is yet. Just incase it’s my billion dollar idea. (As if.) Seriously, I’m just playing with Flex right now.

Anyhow, I’ve played with Flex Builder in the past but never Flex Data Services. I figured that if I’m going to jump into Apollo I might as try out the new LiveCycle Data Services 2.5, which is a beta update to FDS.

So, I went ahead and installed LCDS. I was going to install it under my current JRun 4 installation but for some reason I couldn’t pull up the JRun admin interface. Instead of worrying about that I decided to try the LCDS install with integrated JRun. I thought this would be similar to a multi-server installation of ColdFusion, but it turns out it’s much more similar to the server installation of ColdFusion, which happens to be what I’d really rather have for now anyhow.

So LCDS installs without a hitch. Once it’s installed I quickly figure out that I can start the server by clicking Start > Programs > Adobe > LiveCycle Data Services 2.5 > Start Integrated LiveCycle Data Services Server. This opens a command window and runs whatever commands are needed to fire up LCDS.

However, as I watched the resulting status scroll by I noticed this failure message:

03/22 22:39:38 user FlexInternalServlet: init
[Flex] RTMP-Server on port: 2038 failed to start up.
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind(Native Method)
at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
at sun.nio.ch.ServerSocketAdaptor.bind(Unknown Source)
at flex.messaging.endpoints.rtmp.BaseNIORTMPServer.run(BaseNIORTMPServer
.java:158)
at java.lang.Thread.run(Unknown Source)
flex.messaging.endpoints.rtmp.RTMPException: The RTMP server has encountered a fatal exception starting up: Address already in use: bind
at flex.messaging.endpoints.rtmp.BaseNIORTMPServer.run(BaseNIORTMPServer
.java:320)
at java.lang.Thread.run(Unknown Source)

The message “Address already in use” was pretty descriptive and the port 2038 was fairly clear too. Unfortunately I wasn’t able to turn up much by googling any of the error message or the port number.

It occurred to me that I could simply use netstat to see what’s listening on port 2038.

Running netstat b will return all of the open ports and the executable associated with it. In my case this showed that port 2038 was being used by googletalk.exe. Doh!

Searching for anything with the word “google” and “2038” was useless. I seems that Google is infamous for setting a cookie that doesn’t expire till 2038 and all the matches were for people griping about this.

However, after a few more variations on the search I discovered that I could safely change the port that RTMP is running on. To do this I found my services-config.xml file for Flex which was located under the C:lcdsjrun4serversdefaultflexWEB-INFflex directory.

I simply searched for the number 2038 in this file and changed its one occurrence to 2039. Like this:

<endpoint url="http://{server.name}:2038"/>

The next time I fired up LCDS I received no errors!

Now, honestly, I have no idea if this will break something else down the line. I suspect that I’ll eventually try to use RTMP (whatever that is) and believe it to be broken because, by default, something will try to connect on port 2038, not 2039. Oh well, I’ll cross that bridge when I get there.

Looking for a Graphic Designer

Can anyone recommend to me a highly talented web and print designer? I need someone who would be willing to work with me to update the design of a website, create a logo and some printed materials.

I haven’t had any luck by just googling around. Any suggestions / links / email addresses would be greatly appreciated. Thanks!

Alagad Is Hiring a Senior Developer!

Update: Thanks to everyone who applied! This position has now been filled.

I’m happy to announce that Alagad Inc is ready to hire its first full time programmer. I’ve reached the limits of my ability to get things done and I need to hire the best developer I can to help with Alagad’s continued growth.

Though Alagad is a very small company, it’s not a new venture. I’ve been in business with Alagad since 1996 and have been profitable for several years. Since making it my full time commitment in 2005 the company has grown tremendously. I have dozens of projects (both contractual and internal) ongoing and lots of opportunities yet to be tapped.

Why You Should Work With Alagad

Because Alagad is so small I can’t offer the same benefits as larger companies. However, I do believe what I can offer is quite compelling.

Hourly Pay!

That’s right, hourly pay. If you work overtime you get paid for your overtime. How many of you senior developers out there work 60 hour (or more) per week and get paid for 40? Not at Alagad. You’re guaranteed to be busy for at least 40 hours a week and you’ll get paid for every hour extra you work. Your hourly rate will be determined based on a “salary” we agree on divided by 2080.

A nice thing about this that if you need to take time for a doctors appointment, or if you need some time to run to the post office, or if you need any time for any reason, you can simply take it. There’s no need to take a half day of paid time off just to see the dentist.

Paid Time Off

Starting immediately, you will begin accruing paid time off. Paid time off is calculated based on percentage of your salary and the hours you work. If you work a standard 40 hour week you’ll earn 1.5 days off per month, give or take. Because this is proportional to the time you work, any overtime will lead to more time off being accrued.

In a standard year you’d earn 144 hours off, or just over three and a half weeks off. However, note that any holidays you choose to take will come out of these hours. But, if you don’t want Columbus Day off you don’t need to take it!

Paid time off also accrues forever. If you work for Alagad for 10 years and never take a day off, then, I suppose, you could take a 180 day vacation. Or, when you quit you’ll get every penny of un-taken time in your last check.

However, because time off is proportional to what you earn big raises will actually lessen the time you’ve accrued to take off. Don’t worry though, it’s worth it.

Remote Work

Alagad has no central office. I work from my home office. You can work from the local mom-and-pop coffee shop, for all I care. All that matters to me is that you get your work done in a timely and professional manner.

Obviously, we’ve all got schedules. We’ll set yours so it works for everyone.

Oh, and because this is remote work I don’t care where you live. This job is open to anyone in the United States.

Health Insurance Stipend

Initially I’m not going to be offering any group health insurance plan. However, I will be offering a stipend of $200 per month if you’re single and $400 per month if you’re married. For those who have other health insurance options this might not matter. However, if you do need insurance, I’ll do what I can to help you get started with your individual plans.

The nice thing about this is that you can pick a plan that’s right for you and your family. My wife and I use Blue Cross Blue Shield. We’ve used Aetna in the past too. The $400 stipend is about half of our bill.

In the future, if employees want it, I’ll be looking into group plans. (Sadly, the one I wanted to use is not available in North Carolina!)

Future Benefits

In the future I’ll be putting together a 401k plan with matching for retirement savings.

I’m also considering various profit sharing ideas or bonus programs. I’ve not come up with any formal plan for this yet, but I plan to be generous.

Interested? Here’s What I’m Looking For

I’m in need of a senior developer. I’m looking for someone who has years of experience building enterprise applications. I need someone who can be very productive. You will be programming in ColdFusion most of the time. However, you’ll also be expected to be strong in SQL, JavaScript, CSS, HTML and all the other standard web languages.

Because of the size of Alagad, I also need someone who’s a fairly strong Jack of All Trades. For example, you might receive artwork for a site in a PSD or JPEG file. In these cases I’ll need you to be able to do a good job slicing this artwork up into something that’s usable on the web. A nice, well rounded background will help with this. Any design background (however limited) or at least a confidence in your ability to make stuff look nice and be usable will be important.

For the most part you’ll be either working on current contracts or new development. Most projects will use Model-Glue, ColdSpring and Reactor on a daily basis. The ability to understand and write Object Oriented code is essential. There are also some older applications and tools that may need to be supported, but this will not usually be your responsibility.

The ideal person for the job will also be able to quickly pickup new tools and languages. I wouldn’t be surprised to see some J2EE or.NET work come up. All in all, you should be very proficient technically and have a demonstrated capability to pick up new tools and languages quickly. I’m also looking to expand into Flex development in the future, so any experience with this will be a big bonus.

Lastly, I need someone who talks and writes professionally. When you’re speaking with clients you must sound professional and intelligent. Additionally, you’ll be required to write one technical blog entry per week. Obviously you have to be coherent!

I’m looking for someone who can start around April 2nd, though I’m flexible.

Please follow these instructions when submitting your resume:

Please send your resume to: dhughes(at)alagad.com.

Please use a subject that includes the word “Avocado”. (Hey, we’ve got to have our fun somehow.) Bonus points for creativity. And, although your subject may be zany, I will be looking for professionalism in your cover letter and resume.

If you have any other questions or concerns please feel free to email me at dhughes(at)alagad.com. I’ll try to answer all questions in a timely manner.

Irregular Expressions

I’m not a big fan of the Regular Expression methods that come with ColdFusion. I find them cumbersome, at best. They’re great if you just want to check a string for a pattern, but if you’re replacing data using any sort of algorithm you’re hosed.

As an example, I’m working on a very simply content editor for a client’s website. A feature of the system is that they can type link names as plain test. Thus, if they wanted to go a page that they want to call “About Us”, they simply click the link icon in TinyMCE and type in the English words, “About Us”. When the content form is submitted the system translates this into a more meaningful URL, “index.cfm?event=About-Us.

The problem is that the site only receives the HTML markup which might look like this:

<p>Click here to read <a href="About Us" />about us</a>. </p>
<p>And, as an example, here's <a href="Another Link" />another link to see</a>. </p>
<p>Lastly, here's a real URL to <a href="http://www.anothersite.com" />another site</a>. </p>

So, the idea is, I loop over all the matches I can find in the HTML and check the href value to see if it contains “http://&#8221;, “http://&#8221; or “index.cfm”. If so, I ignore it. Otherwise, I manipulate the href value so that I insert index.cfm and replace all non alphanumeric characters with hyphens.

So, the first thing I always do when I run into problems like this is try to use ReReplace. Frankly, I’m no regular expression wizard. I can usually slink by, but if there’s any solution to this problem with just regular expressions I sure don’t know.

The problem is that I need to make decisions conditionally and ReReplace statically replaces instances of a pattern in a string with another string or a limited pattern.

So, to do what I want I typically write a loop tag that looks till I break out of it. On each iteration of the loop I look for the pattern with ReFind. I parse the heck of the results and then rebuild the string I’m searching over. Lastly, I figure out where the next search should begin.

Gawd do I despise this technique. So, I decided to work out a better solution.

Wouldn’t it be nice if there was a way to call a handler function on each match that simply had to parse that one match and return the result? Well, here’s a very simply CFC that does just that:

<cfcomponent>
    <cffunction access="public" hint="I am a function that can be used to more easily parse a set of matches in a particular way using regular expressions" name="parse" output="false" returntype="string">
        <cfargument hint="I am the string to parse" name="string" required="yes" type="string"/>
        <cfargument hint="I am the regex to use" name="regex" required="yes" type="string"/>
        <cfargument hint="I am the call back function to use. This must accept one argument, an array of elements in one match." name="callbackFunction" required="yes" type="string"/>
        <cfset location=0 var/>
        <cfset match=0 var/>
        <cfset full=0 var/>
        <cfset detail=0 var/>
        <cfset result=0 var/>
        <cfset var x=0/>
        <cfset left=0 var/>
        <cfset right=0 var/>
        <cfset change=0 var/>
        <cfloop condition="true">
            <cfset detail=ArrayNew(1)/>
            <cfset >)(.+?)(</a>)', arguments.string, location, true)/>
            <cfif 0 IS match.len[1]>
                <cfbreak/>
            </cfif>
            <!--- parse the match into chunks --->
            <cfloop from="1" index="x" to="#ArrayLen(match.len)#">
                <cfset detail[x]=StructNew()/>
                <cfif match.len[x]>
                    <cfset detail[x].string=Mid(arguments.string, match.pos[x], match.len[x])/>
				<cfelse>
					<cfset detail[x].string=""/>
				</cfif>
				<cfset detail[x].pos=match.pos[x]/>
				<cfset detail[x].len=match.len[x]/>
			</cfloop>
			<cfif match.len[1]>
				<cfset left=left(arguments.string, match.pos[1] - 1)/>
				<cfset right=right(arguments.string, Len(arguments.string) - (match.pos[1] + match.len[1]) + 1)/>
				<cfset change=arguments.callbackFunction(detail)/>
				<cfset & & arguments.string=left change right/>
			</cfif>
			<cfset + + 1 len(change) location=len(left)/>
		</cfloop>
		<cfreturn arguments.string/>
	</cffunction>
</cfcomponent>

This CFC has one method, parse, which accepts a string, a regular expression and a pointer to a method to that will handle matches. The handler method receives an array of structs. Each structure in the array has keys “string”, “len” and “pos”. The string is the string that was matched by the portion of the regular expression.

Let’s say I used this regular expression

(&lt;a href=&quot;(.+?)&quot;.*?&gt;)(.+?)(&lt;/a&gt;)

I would end up with five elements in my array: The entire link tag, the opening tag, the value of the href element, the text in the link, and the closing tag. Each of these elements would have the matched string. IE, element 4 would be “about us” for the first match in the HTML example above.

So, I can write a handler method like this:

<cffunction name="fixLinks" output="false" returntype="string">
    <cfargument name="match"/>
    <cfset return="" var/>
    <cfset link="" var/>
    <!--- parse any string that doesn't start with http://, http:// or contain index.cfm --->
    <cfif "http://" "http://" (arguments.match[3].string CONTAINS "index.cfm" ) AND AND IS IS Left(arguments.match[3].string, 7) Left(arguments.match[3].string, 8) NOT NOT NOT>
        <!--- open the link tag --->
        <cfset return=arguments.match[2].string/>
        <!--- fix the href in the link tag --->
        <cfset & ReReplace(Trim(arguments.match[3].string), "W", "-", "all") link="index.cfm?event="/>
        <cfset return=replace(return, arguments.match[3].string, link)/>
        <!--- add the link text --->
        <cfset & arguments.match[4].string return=return/>
        <!--- close the tag --->
        <cfset & arguments.match[5].string return=return/>
	<cfelse>
		<cfset return=arguments.match[1].string/>
	</cfif>
	<cfreturn return/>
</cffunction>

This accepts the match and parses it. It simply looks to see if it’s an http, https or index.cfm link and parses it to the standard, if not.

Making this work is as simple as two remaining lines of code:

<cfset var RegEx = CreateObject("Component", "model.regex.Regex") />
<cfset content = RegEx.parse(content, '(<a href="(.+?)".*?>)(.+?)(</a>)', fixLinks) />

Assuming we use the HTML aboive, the output from this method is:

<p>Click here to read <a href="index.cfm?event=About-Us" />about us</a>. </p>
<p>And, as an example, here's <a href="index.cfm?event=Another Link" />another link to see</a>. </p>
<p>Lastly, here's a real URL to <a href="http://www.anothersite.com" />another site</a>. </p>

How handy is that? Isn’t it cool what can happen when you start coding to interfaces?

Tag Cloud