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) />

7 thoughts on “Resetting Webservices

  1. 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)

    Like

  2. So essentially, you would have the following:

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

    Like

  3. 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?

    Like

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

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s