Resetting Webservices

From time to time, I have problems consuming webservices via ColdFusion. Usually these problems have to do with changes in the webservice’s code or configuration or corruption of the stub objects for the webservice on the calling ColdFusion server. To get around this: I wrap all foreign webservices calls in a <cftry> <cfcatch>; in the catch I reset the webservice; and retry the original webservice call.

To do this call the following code:


<cffunction access="private" name="reset_webservice" output="false" returntype="void" description="Reset the webservice in the Server Factory.">
<cfargument name="wsdl" type="string" required="yes" hint="The url of the the wsdl file of the webservice to reset." />
<cfobject type="JAVA" action="Create" name="factory" class="coldfusion.server.ServiceFactory" />
<cfset RpcService = factory.XmlRpcService />
<cfset RpcService.refreshWebService("#arguments.wsdl#") />
</cffunction>

UPDATE: Sean Corfield schooled me a bit, but it’s hard to see how elegant his code is in my comments, so I’ve reproduced it up here:

Don’t forget that the above code is not thread-safe unless you add ‘var’ declarations for both factory and RpcService:


<cfset var factory = createobject("java", "coldfusion.server. ServiceFactory")>
<cfset var RpcService = factory.XmlRpcService>
<cfset RpcService.refreshWebService(arguments.wsdl)>

(you don’t need “#..#” there)

Of course you could do the whole thing in one line and be thread-safe like this:


<cfset createObject("java", "coldfusion.server.ServiceFactory").XmlRpcService.refreshWebService(arguments.wsdl) />

Web Page Outliner

The World Wide Web Consortium has a tool it calls a “Semantic Data Extractor.” It basically parses a web page and shows you how a page would be outlined according to your <h1>, <h2> , <h3> … structure. I found it earlier today when I was using their Markup Validation Service to test my markup. Their tip of the day referenced it. I found it extraordinarily useful in analyizing the structure portion of the content + structure + presentation Webstandards equation.

CFC Caching and Whitespace

I was having a lot of trouble getting rid of whitespace at the top of one of my applications. I did some investigating using comments to suss out the source of it, and realized that it was coming from cfc invocation using <cfobject>. I was thinking about caching them to the application scope anyway, as they are basically just big function libraries. And that got rid of it.

Had I been a little more dilligent in my investigation, I would have figured out that <cfcomponent> takes output=”false” as attribute.

So it might be a lazy way of doing so, but caching cfc’s can also have the side benefit of getting rid of whitespace.

Easiest Way to Generate a Request Error

I ran into a situation today where I wanted to create a request errorin ColdFusion MX 7, to test handling request errors. My problem: How do you generate a request error?

My solution:

  • Create a test.page with the code <cfset undefvar= undefvar/>
  • In my application.cfc, create a <cferror /> tag and point it to error.cfm.
  • In error.cfm add code <cfset undefvar= undefvar/>

And that should do it. Is there an easier way that I’m missing?

CSS + CFMail

A came across the dumb little trick a while back, and wanted to share this.

I like to make the mail sent from an application look like it’s part of the application, but often the step is overlooked during the development process. However by using <cfinclude> and CSS, this can be accomplished:

<cfmail to=”user@example.com” subject=”Yo!” type=”HTML” from=”anotheruser@example.com”>

<style type=”text/css”>
<cfinclude template=”[path to CSS for site]”>
</style>
[content goes here.]
</cfmail>

Granted, you have to make sure that your CSS not huge, or this becomes inefficient.

Updated Flashpaper Embedder

After Ryan went through a fair amount of effort to help get me on MXNA, I thought it was only fair that I get some ColdFusion posting in. (Especially after last night’s drunken geekery.)

A while back I posted about creating a CFC that would embed dynamically created Flashpaper created by <cfdocument>. However, it didn’t create Webstandards compliant XHTML code. So, I updated it to do so using a variation on the Satay Method.

Now I know I’m outputting from a CFC, but frankly, I really don’t like custom tags, so I do this sort of thing in CFC format.

Check out the updated code: Flashpaper Embedder.

Which ColdFusion Personality Would You Host?

Dan, Ryan, and I were discussing this year’s Macromedia Max (or whatever Adobe will call it) while drinking, one thing led to another and the following question was posed:

Which ColdFusion personality would you to invite to sleep on your guest bed?

First, of course we thought Ben Forta. I think that would be like hosting the Dali Lama. You’d be nervous, you’d say things like “I can’t let Ben Forta see my PHP books.”

We moved on to Damon Cooper, who at first glance would be fun. But I get the feeling that he’s like your college friend who comes and makes drinking look so fun. So it’s fun, but you have like a 5 day hangover after he leaves.

So I think my vote would be for Tim Buntel. He seems like he would be fun but not a giant enabler. He wouldn’t criticize your book collection. And he would probably make the bed before he left.

Anyone out there have any opinions other than “Geeks like you should not drink.”

Jim Davis for Govenor (Florida)

I’m happy to share with everyone that ColdFusion is being used to make the world a better place… or at least to make Florida Democratic again.

The crew at Jim Davis for Governor ’06 have created a good looking site that uses ColdFusion, and blogging to reach the state of Florida. The cool thing I like about it is that the main blogger, Matthew Thornton, (disclaimer: a good friend of mine, who comments here from time to time,) gets the blogging medium. If you read the blog, it reads like a blog. It’s got a the right tone and content, as opposed to other candidate blogs that are just a collection of press releases. It’s not just me that thinks so. This guy said it too..

Congratulations to Matt, and the whole crew at the Jim Davis campaign. Now it’s time to win.

ColdFusion and Valid Code

I ‘ve gotten oddly obsessive about webstandards and valid XHTML. The problem is that many of ColdFusion‘s features that make web development easy also make very unstandard xhtml. In order to get this site to validate I had to:

  • Replace Flash <cfform> tags with properly styled XHTML forms.
  • Remove all <cfdump> tags
  • Replace all embedded Flash with Flash embedding using the Satay Method.
  • Clean all Movable Type created content.

Finally when all was said and done, I have one page left that won’t validate. It’s a page on which I use <cfchart>. Nothing I’ve been able to do seems to fix that. I know there are plenty of people who don’t think validation is vital but a large company like Macromedia should shoot for valid output.