TerrenceRyan.com

I'm a 35 year old redhead geek from Philly.
I'm currently a Developer Evangelist for Adobe.
Also the author of Driving Technical Change

Resetting Webservices

7 Comments

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:

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

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:

&lt;cfset var factory = createobject("java", "coldfusion.server. ServiceFactory")&gt;
&lt;cfset var RpcService = factory.XmlRpcService&gt;
&lt;cfset RpcService.refreshWebService(arguments.wsdl)&gt;

(you don't need "#..#" there)

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

&lt;cfset createObject("java", "coldfusion.server.ServiceFactory").XmlRpcService.refreshWebService(arguments.wsdl) /&gt;

7 responses so far ↓

  • 1 Sean Corfield

    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)
  • 2 Sean Corfield

    Oops, that kinda messed up the formatting :)
  • 3 Terrence Ryan

    I added Sean's comments to the extended entry portion of the post. Sorry about that, Sean, I haven't hacked MovableType enough for it to show code properly in comments.
  • 4 cfJeff

    nice work. I happened to run into this very problem the other day.
  • 5 Rich Rein

    So essentially, you would have the following:

    <cftry>
    <!--- try to consume web service --->
    <cfcatch type="any">
    <cfset reset_webservice(wsdl_URL) />
    <!--- try to consume web service again --->
    </cfcatch>
    </cftry>

    where your web service call would happen a maximum of two times before erroring out?
  • 6 Rich Rein

    Oops, code was gone from my previous:

    cftry
    call webservice
    cfcatch type="any"
    reset_webservice(wsdl_url)
    call webservice again
    /cfcatch
    /cftry

    Also, would this be useful for noticing a change in a local webservice and reloading it, rather than having to restart the CF service?
  • 7 Terrence Ryan

    That's exactly the way I do it. You could also write the catch to exacly match the conditions that cause the error (something about Stub objects usually.)

    As for this as an alternative to restartings: Absolutely. It's the equivalent and reloading the webservice in the cfide/administrator console.

Leave a Comment









Categories

Monthly Archives

Tag Cloud

coldfusion web development flex coldfusion builder appearances squidhead coldfusion builder extensions higher ed html5 flash builder air mobile android driving technical change adobe apptacular running a coldfusion shop adobemax06 movable type flash catalyst flash css blackberry adobemax07 adobemax08 hero finicky adobemax09 holy crap i’m a mobile developer centaur phonegap basecamp cfc whichelement unfuddle motorola metablog irrational characters ios git evangelism edge devices code reviews ant wharton subversion security rhino philly philadelphia multidevice knowledge@wharton jobs javascript java browserlab adobemax10 adobe tv unfuddlecfc svnauth.cfc semantic html semantic html responsive web design qnx nlb linux jquery mobile it github flexorg fireworks eclipse dreamweaver apps apple adobemax11