CSS Parsing ColdFusion Function

Here's a function I knocked up to retrieve a specified CSS property from within a specified CSS Selector:

<cffunction name="GetCSSProperty" access="public" output="false" returntype="any" hint="I attempt to find and return a specified CSS property contained within a specifed CSS selector">
   <cfargument name="CSS" type="string" required="true" hint="CSS to Process">
   <cfargument name="Selector" type="string" required="true" hint="Selector to locate">
   <cfargument name="Property" type="string" required="true" hint="CSS Property to retrieve">
   <cfargument name="DefaultValue" type="string" required="false" default="" hint="Default value if not found">

   <cfscript>   
      var local = structnew();
      
      local.MatchingSelectors = REMatch("[^}]*#arguments.Selector#[^{]*{[^}]*#arguments.Property#[\s]*:[\s]*([^;}]*[^}]*})",arguments.css);
      if (arraylen(local.MatchingSelectors))
      {
         local.relevantSelector = trim(local.MatchingSelectors[arraylen(local.MatchingSelectors)]);
         local.FindValue = refind("{[^}]*#arguments.Property#[\s]*:[\s]*([^;}]*)",local.relevantSelector, 1, true);
         local.pos = local.FindValue.pos[2];
         local.len = local.FindValue.len[2];
         local.cssValue = trim(mid(local.relevantSelector,local.pos,local.len));
      }
      else
      {
         local.cssValue = arguments.DefaultValue;
      }

      return local.cssValue;
   </cfscript>      
</cffunction>

This function will attempt to return the specified property as defined in the last CSS definition which contains the specified selector. This does mean that it will potentially return false matches against more specific selectors - e.g. searching for font-size property within td.gridDataCell would return the value for the button (8px), even though more accurately the previous less specific value (10px) should have been returned.

td.gridDataCell {font-size:10px;}
td.gridDataCell button {font-size:8px;}

I have a particular use case for this functionality for parsing CSS used to control formatting of dynamically generated HTML emails, and convert it to HTML which is more compatible with Outlook 2007 (i.e. HTML Properties rather than CSS :-/) where I already know that no complex cascading rules have been defined - but if need be additional functionality could be added to parse the selectors within local.MatchingSelectors, and remove any matches which only match partially.

How to call a Web Service from CF7 using Client Certificate based ("Bilateral") authentication (Win)

If you have to call a web service from ColdFusion 7 - and the destination web service enforces bilateral SSL authentication (i.e. the caller has to supply a client certificate to prove who they are, as well as the destination supplying a server certificate to prove who it is...) - then the options, in descending order of preference are:

  1. Check / ask really nicely / beg / etc. to see if there is a way of calling the web service without passing a client SSL certificate
  2. Use CF8 (or later) - I believe that you will still need to do the SOAP generation by hand, as cfobject / cfinvoke do not appear to allow a client certificate to be set - but you can use cfhttp and specify the clientcert and clientcertpassword attributes - which avoids having to use the WinHttp.WinHttpRequest COM object as shown below.
  3. Use the WinHttp.WinHttpRequest COM object as shown below...

ColdFusion (when running on windows) allows (and has allowed for several versions) COM objects to be called from within CF code, using the CFOBJECT tag or CreateObject() function.

Built into the following versions of windows, is the WinHTTP 5.1 COM object:

WinHTTP 5.1 is available only with Windows Server 2003, Windows XP with Service Pack 1 (SP1), and Windows 2000 Professional with Service Pack 3 (SP3). (I suspect that it may also be available in Windows 2008)

This provides similar functionality to CFHTTP - but at a lower level.  In particular it allows a client certificate to be specified, using the SetClientCetificate function.

This is not as simple as it seems - where as in CF8 using CFHTTP you just have to specify the physical location of the client certificate file - the WinHttp object requires that the client certificate is first imported into a certificate store - and then the reference to the certificate provided to the SetClientCetificate function:

ClientCertificate [in]

Specifies the location, certificate store, and subject of a client certificate

To cut a very long (well around 5 hours) story short, this is how I finally got it to work:

[More]

ColdFusion Job opportunity in Manchester, UK

A new job opportunity for a ColdFusion developer has just become available in Manchester, UK.

This is at the company that I worked at for 5 years (Gencia Media) - great bunch of people to work with, really friendly.

Click here for job details / contact details.

Aggregate Bug? with ColdFusion (8.0.1) Query of Queries

I've been having the following issue with CF8 Query of Queries on ColdFusion 8.0.2:

Iniital query resultset:

attraction_latitudeattraction_longitude
51.4808-0.155075
51.564617-0.092513
51.558144-0.316379

[More]

CFAjaxProxy - don't add the .CFC file extension...

I've been getting the following CF error when attempting to use the CFAjaxProxy tag:

The specified CFC path.to.cfcname.cfc cannot be found

The specified CFC definitely existed, and all the mappings had been set up correctly.

I was calling it with the following code:

<cfajaxproxy cfc="path.to.cfcname.cfc" jsclassname="searchCFC">

I was tearing my hair out for about an hour, before I realised think CF not AJAX - the path to be supplied is in exactly the same format as all CFC references - i.e. excluding the .CFC file extension.

I'm sure this is completely obvious to most people (although at least one guy (thanks Andy) mentioned having done the same thing even today) - but its the obvious ones that seem to catch me out!!!

Weird issue trying to start a CF8 instance

Just had the following issue when trying to start a CF8 instance.

Within the windows services control panel, I clicked start for all of the instances (8) - and they all started except 1.

This was following some fairly in depth reconfiguring of the instances - involving changes to multiple configuration files, the registry, and (perhaps most tellingly) mapping each instance to use its own configuration file by un-registering the windows service, and then re-registering the service using the new config file.

During this process, jrunsvc will stop the service if it is currently running.

When I checked within the JRun {instance name}-out.log file within the instance which would not start, I saw the following error:

error JRun Naming Service unable to start on port 2914
java.net.BindException: Port in use by another service or process: 2914

[More]

64 bit CF8 Compatability issue (Completely irrelevant to most people)

There doesn't appear to be a 64bit driver for MS Access data sources.

I know - no-one in there right mind would use access for driving a website - but we still host a couple (literally) of sites which were created at least 6 years ago and have barely been changed since...

Solution: Import said databases into SQL Server...

SMTP Event Gateway???

Does anyone know of an SMTP event gateway for ColdFusion>

What I'm looking for, is a way of implementing helpdesk type functionality, whereby any emails to a certain domain are handled by ColdFusion according to a set of rules (e.g. create new issue - add comment to an exiting issue etc.)

It struck me that it should be relatively straightforward to handle incoming SMTP transmissions using a ColdFusion Event Gateway (seeing as SMTP is a relatively simple text based prtocol...) - and I wondered if anyone had already done it - and if not - why not? (I'm presuming I must have overlooked something that would make it more complicated than I anticipate...)

ColdFusion 8.01 on Windows - should I go 64 bit?

I'm in the process of specifying a new web server, which will be running ColdFusion 8.01 Enterprise (as well as IIS etc.).

The server will be running ~6 active instances of ColdFusion - and will initially be configured with 4GB RAM - with the option of upgrading in the future as required.

We will be using Windows 2003 Enterprise as the operating system.

What will the benefits and downsides be of going for the x64 OS compared with the x32 OS, taking the following into consideration:

  • The system will only be used as web application server
  • The system will initially be set up with 4GB RAM - and will never have more than 8GB.
  • The high number of instances of CF mean that if we did set the JVM Heap size over the ~1200 MB x32 limit, then we'd run a distinct possibility of running out of memory. (The reason for having so many instances of CF is to enable separation of CF Mail queues - 2 of the instances don't get any front end traffic at all, and are just responsible for sending out large batches of email)

Any advice would be appreciated...

A big thankyou to all those involved in Scotch on the Rocks

Got back home from Scotch on the Rocks - just wanted to publicly thank all those involved with Scotch on the Rocks.

In particular I want to thank Andy Allan and his wife Leanne for the huge amount of time and resource they have given to make this conference the best ever European ColdFusion conference, together with Kev, Stephen and others.

I also want to thank all the speakers - All the presentations I attended were interesting - and some were particularly relevant to where I am now as a developer.

The networking was great - it was particularly good to be able to chat with some of the guys who are leaders within the community - I think this can be even more valuable in many occasions than the sessions - as well as the interaction with Adobe staff.

Thanks Everyone.

How to change ColdFusion / JRun logging location

ColdFusion by default stores log files in 2 locations, dependant on the type:

[More]

Unable to persist CFC to App scope if invoked by Webservice call (With workaround)

I have come across the following issue when attempting to persist a CFC to the Coldfusion Application scope, when the the CFC method had been invoked remotely.

[More]

Beware Coldfusion / mapping

Be careful when setting up a root ColdFusion mapping, where the ColdFusion root and the web server root are not the same location.

On our standard Development machines, we are running IIS on Windows XP, and have been developing against 3 versions of ColdFusion.

We set up 3 IIS virtual directories (/cf5, /cf6, /cf7) each pointing to a subdirectory of our sites folder (c:\sites\cf5, c:\sites\cf6, c:\sites\cf7 etc.) - with the corresponding version of CF handling each virtual folder.

Within each version of CF, we set up a root mapping - e.g. for CF7: / = c:\sites\cf7, in order to allow the CF Mapping path to be consistent between development machines and production servers.

This works fine for most occasions - the IIS virtual directory normally has nothing to do with the CF Mapping - however there are a couple of exceptions:

  • Using the Application.cfc OnRequest Method: (CF will set arguments.targetpage to equal the IIS path)
  • When attempting to invoke a CFC as a webservice (error: Could not resolve CFC datatype)

Both of these issues can be resolved by setting up a CF mapping to match the web server virtual directory mapping (e.g. /CF7 = c:\sites\cf7)

Flex integration broken in CFMX 7.02 on Ubuntu (maybe - for most people)

I struggled with this over most of the weekend - and eventually came to the conclusion that flex / CF integration does not work using CFMX 7.02 on Ubuntu.

This appears to be a known issue (at least for Red Hat) - logged here

Any flex requests to CFC's are met with flex/messaging/io/amf/UnknownTypeException.

[More]

ColdFusion 7.02 + Apache 2.2 installed on Ubuntu 7.04 on VMware Player

Its definately harder than windows - but I have managed to get ColdFusion 7.02 Server running on Apache, on Ubuntu 7.04 (Feisty Fawn).

My previous experience with Linux is very limited to say the least - and most of the issues I ran into were due to misunderstandings on my part about how linux works...

Main issues i ran into:

  • Ubuntu does not have a root account (not strictly true - but when I though it was asking me for a root password - it was actually asking for my password...)
  • Could not execute ColdFusion installer after I had downloaded it (not marked as executeable - chmod +x)
  • I really don't understand linux permissions - I want to be able to create and edit docs in /usr/local/apache2/htdocs/ without having to sudo (I'm sure this one will seem more logical when its not 3am!
  • Had an issue with the connector for apache - the one that is distributed with CF is not compatible with Apache 2.2 (there is a hotfix downloadable from adobe for this, which worked)

All in all, I don't think 4 hours was too bad, baring in mind my inexperience with linux etc.

I have to say, I'm very impressed with VMware player - about 100 billion times faster than MS Virtual PC!

A big thankyou goes to Dave Shuck for his excellent post on Installing CFMX7 & Apache2.2.2 on Ubuntu - Without this I think I would have been totally lost...

I'll post more when its not 3am - and I've had more chance to get everything setup how I want.

(Basically I'm trying to create an environment that I can dev in (and potentially move to other machines) when I'm not using my primary development machine - I have a lightweight laptop that I normally use when I'm not in the office - but I often want to quickly play with something in CF. I didn't want to break my existing windows installation on this machine by installing a load of server / development software - so I thought I'd build a virtual machine - using ubuntu rather than windows to avoid licensing (and hopefully performance) issues!)

WARNING! - Disabling clientManagement in cfapplication tag breaks cflocation

This one had me banging my head against the wall for a while...

Upon the recommendation of Adobe Technical support, we set the clientmanagement attribute within the cfapplication tag within a number of our applications to "no" (from the previous value of "yes") due to problems with stability of ColdFusion on a server recieving high levels of traffic.

He said to disable client management unless we were making use of client variables within our application.

[More]

ColdSpring - Locating CFC's outside Web Root???

I am in the process of creating a template application, using the following frameworks:

  • Fusebox 5.1
  • ColdSping
  • Transfer
I have run into the following issue.

We have tried to only have files within the web root, which should be accessible directly within the browser.

[More]

Brian Rinaldi - Anatomy of a Framework - Mach-II - Part I

Anatomy of a Framework - Mach-II - Part I

Brian Rinaldi gives a walkthrough of what happens when the Mach-II framework initialises.

Hopefully this will be the first of many articles - Brian is planning to disect a number of Frameworks - including Mach-II, Model-Glue, Fusebox and ColdBox, depedant on the interest generated...

Workshop recording: Sean Corfield on fusebox 5.5 available on cfFrameworks.com

The recording of the Fusebox presentation given by Sean Corfield yesterday is now available on cfFrameworks.com.

Workshop recording: Sean Corfield on fusebox 5.5

Coldfusion 8 Released... and I'm... Absolutely Gutted :(

Why?

Adobe's decision to charge an additional premium to customers in the UK.

From Adobe's online store for the download version:

  • US Price: $7,499
  • UK Price: $9,192 (that's before tax - after tax its $11,118 due to a bizarre decision to add tax at a rate which is 3.5% higher than the standard VAT rate within the UK- apparently because the ""UK"" store is based in Ireland.
This price differential causes a lot of bad feeling amongst companies within the UK - as the reason can only really boil down to one of the following:
  • Adobe feels they can get away with it in the UK
  • Adobe doesn't really care about the UK market, as its too small to be important to them
Neither of which is particularly encouraging for UK customers.

As part of my job, I am responsible for making technical recommendations with regards to the most suitable platform to be used for developing / hosting a web application. When dealing with SME's who require a dedicated server, we are often pitching against companies who are using free software (php in particular). We can consistently be competitive on cost for development (despite generally having a rate per hour that is higher than the companies we are competing against) - which is a commendation for ColdFusion. What is hard to justify to our clients, is why our hosting quote is double the cost for the first year. This is often enough to use up the saving we have offered for our client in development.

ColdFusion is not hard to sell to an enterprise client (When spending $100,000 year on hosting - the initial cost of CF Enterprise is not too great a percentage.

Its also not too hard to sell at the bottom end of the market - if you spread the cost of an Enterprise license over 10-20 clients on a shared box, again it is fairly easy to swallow.

In the middle though - for a client who would be paying $7k-$10K per year on hosting - its becoming harder and harder to justify.

Whilst I (and the company I work for) wants to continue developing applications in CF, we may soon come to a point where it is no longer an option for a large proportion of our clients.

As a final note - and the reason I am really disappointed, is that I feel we have been let down.

In  a conversation with Tim Buntel, at Scotch on the Rocks at the end of May, I (together with a few others) raised the issue of the existing disparity in pricing with Tim as being a major issue.  Tim responded to the effect that, although he could not give any specifics, that "They were aware of the issue - and that it had been sorted - and we would not be disappointed at the outcome"

So - this leaves me to conclude:

  • TIm? / Adobe? thought we in the UK are so stupid that we would not notice the continuing disparity in price.
  • Tim campaigned for consistent pricing - but in the end was overruled by other forces within Adobe.
  • Tim was lying in order to avoid having to confront this issue.
Which is it?

(p.s. the whole pricing structure for the CS suite of products is also massively overcharged within the UK - so this does seem to be a systemic Adobe failing rather than one specific to CF)

"Invisible Software," RIAs, and ColdFusion | Matt Woodward's Blog

Great article from Matt Woodward on the changing emphasis within online application development:<br/>

"Invisible Software," RIAs, and ColdFusion | Matt Woodward's Blog

Blogged with Flock

Excellent set of Ant Resources (with a ColdFusion bias)

James Priest has an excellent set of Ant Resources on his blog - I was looking for something like this earlier today...

Thanks James.

First cfFrameworks.com workshop announced: Peter Bell on Lightwire

The first cfFramworks.com has been announced.

Peter Bell has kindly offered to be the first person to host a workshop for cfFrameworks. Peter will be showing how to setup LightWire using both ColdSpring XML and a programmatic config file.

If you have any questions that you would like Peter to answer nows the time to get them in. The sooner you get them in the better Peter can prepare.

The scheduled time for this workshop is May 9th at 7pm GMT. Please put it in your diary. The link will follow soon.

Again please send in your questions to workshop [at] cfFrameworks.com or post them in the comments at cfFrameworks.com.

XML for application planning???

I am in the process of converting a Fusebox 5.1 application to an MVC implementation.

This is a relatively complex task, as I am also wanting to split the application into 2 - in order to allow shared functionality to be implemented once, and create another instance of the application with a different controller, and some unique functionality.

I was a little stumped at first to know how to visualise the folder structure for the application - I started laying it out within Visio - but quickly realised that this was not sustainable - Visio is great for visualising many aspects of an application design - but its not ideal for representing a large tree structure.

Then I thought - what about using XML - XML is great for representing hierarchical structures - and using the design view within the Eclipse WTP XML editor, its very quick to add, edit, move, and duplicate elements.

[More]

"Page Not Found (404)" error accessing Coldfusion /flex2gateway on IIS on windows XP

It's taken me 2 hours to get to the bottom of this, but I finally managed to fix the problem:).

Machine History

My machine had been set-up with CFMX 6.1.

I had then installed CFMX 7.0.1 in addition to CFMX 6.1, with a virtual directory set-up within IIS with all the CF7 mappings.

Subsequently I installed the CFMX 7.0.2 updater.

Problem Description

Any requests made to http://localhost/flex2gateway/ resulted in a standard IIS "Page not Found" 404 error being displayed.

Requests to http://localhost/flex2gateway/index.cfm resulted in "No configured channel has an endpoint path /flex2gateway/index.cfm'" JRun Servlet error being displayed.

This made me think that the problem was not with the Flex configuration, but rather that the request was not getting as far as JRun / CF / Flex - i.e. it was a problem with the CF connector.

Solution:

I ran:
\CFusionMX7\bin\connectors\Remove_ALL_connectors.bat
to remove CF7 IIS connector. Followed by:
\CFusionMX7\bin\connectors\IIS_connector.bat
to reinstall the CF7 IIS connector.

Success!

Requests to http://localhost/flex2gateway/ now result in a blank page - http status 200 - and flex applications can now access CFCs successfully.

Hopefully this helps someone out there - I couldn't find anything particularly helpful on google when I looked...

Never do this... PLEASE

I had been asked to make a couple of small amends to the functionality of an old legacy CF application, that had been created by someone who has long since left the company...

One of the pages in this application was responsible for displaying a list of all clients on the system, together with a count of the number of associated tasks. This page displays over 1700 rows (I know - paging wouldn't be a bad idea...)

At the bottom of the page, I was astounded to find this gem:

<cfoutput query="get_clients" >
   <!----- get count of tasks ----->
   <cfquery name="no_of_tasks" datasource="#request.dsn#">
          select count(*) as nooftasks from tasks where taskclientID = #clientID# and taskdeleted = 0
   </cfquery>
   <!----- get count of users ----->
   <cfquery name="no_of_users" datasource="#request.dsn#">
          select count(*) as noofusers from users where userclientID = #clientID#
   </cfquery>
</cfoutput>

This is terrible in several ways -

  • The queries are run once for each record within the outer query (get_clients) - 1708 times for each of the count queries
  • The output from these queries is never used!!!

I removed the above block of code - nothing broke as it wasn't being referenced, and the load time for the page went down from ~15 seconds to ~8.

I looked further up the page, and found that the queries I had deleted, had been copied from a location further up the page - where at least the calculated value was being referenced... or at least one of the values was being referenced - the HTML for displaying the other value had been commented out, without removing / commenting the 2nd query!

I removed the second query, which reduced the load time down to ~5 seconds.

So already, just by removing unused queries, we had a 300% improvement in performance.

Real world proof that parametrised SQL really does provide a measurable improvement in performance:

I wrapped the #clientID# value in the subquery in CFQUERYPARAM, and the page load time dropped from ~5 seconds to ~3 seconds...

Of course even with the 500% improvement in performance - I still didn't see the point of leaving this sub query in - when at most it would take me 15 min to build the aggregate in to the outer query.

So I did that, and page load dropped to < 700ms - over 20 times faster than the original page.

I calculated how many queries were being processed in the original page - it came to a mind blowing 6,833!!! - hardly surprising the page took a while to load!

I hope it is completely obvious to everyone why its a terrible idea to Nest CFQUERY calls within loops - performance of the application decreases logarithmically as the size of the outer data set increases - and its completely unnecessary, as the DB engine will be able to calculate the aggregates in the initial select statement, with virtually no measurable impact on performance - surprisingly enough, databases are actually pretty good at manipulating and doing calculations on data!!!

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.5.1, hosted by TalkWebSolutions.