CFC’s, WSDL, and Whitespace

I ran into an odd issue this week, and figured I share. I was getting errors when trying to access a CFC as a webservice from another machine. When I actually browsed to the url of the cfc with the wsdl switch I got an error message that the XML was malformed. I examined the source of the wsdl I found a bunch of whitespace.

This cfc actually exists on all of my ColdFusion servers (15) half of which were the same version and patch level, and one that was cloned two weeks ago from the same source as the server having a problem (also cloned two weeks ago.) I checked the copy on all of them and no error, and no whitespace. I checked the ” Enable Whitespace Management” setting, which was enabled on all of the machines, and the malfunctioning server. So no joy.

I added <cfprocessingdirective supresswhitespace=”TRUE”>… Still no joy. Finally I added a <cfsilent> which did the trick. Very strange. Odd that it only effected one server.

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.

Why Webstandards Rule

I just read AListApart on my new Blackberry and am now writing about it on the same in the web based administrator for my MovableType install. Wht do I credit webstandards? Because these sites degrade beautifully because of webstandards. And since I’m really bored waiting for Janice to get done with skating practice without other entertainment So I’m grateful.

Update: I couldn’t get Ryan’s url to display in the comments. So here it is:
Why Flash still beats everything else on the Web

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.”