Author: TomdeMan
Related Categories:
ColdFusion, Coldbox
July 14, 2008
I recently posted about the Coldbox 2.6 environment interceptor and how it allows you to set different config settings for your app. Then, I released a BugLogHQ plugin for Coldbox. After taking in some feedback, and chatting with Luis, I have made some modifications. This post will discuss the updated Webservice Plugin. I will post another to go over the updates to the BugLog plugin.
Currently the native Webservice support for Coldbox expects 2 WSDL URLs for each service, one for DEV and one for PROD. Looks like:
<WebService name="TESTWS" URL="http://www.test.com/test.cfc?wsdl" DevURL="http://dev.test.com/test.cfc?wsdl" />
</WebServices>
Well, with the new environment specific settings, it defeats the purpose of defining them like this any longer. You can now set them in your environemnts.xml. Like so:
Luis plans to deprecate the current method, but not sure as to when. So implementing this can be done in a number of ways in the meantime.
First option: Overwrite existing Webservice plugin distributed with Coldbox and move your Webservice declarations out of the coldbox config file and into your environments.xml. ** You will not have to modify any application code **
Second Option: Place the updated version into your plugins folder, and call it by using getPlugin('webservices',true). This is for those who need some time to update for the deprecation. You can continue to use your existing Webservices from the coldbox config. Allowing you to add new ones to your environments.xml but remember to use the ',true' when calling the webserivce plugin.
Honestly, I recommend the first option, as it shouldn't take much effort to transfer Webservice WSDLs to the environments.xml, and you wont create a mesh of syntax with getPlugin() calls.
hint="The webservices framework plugin."
extends="coldbox.system.plugin"
output="false"
cache="true">
<!------------------------------------------- CONSTRUCTOR ------------------------------------------->
<cffunction name="init" access="public" returntype="webservices" output="false">
<cfargument name="controller" type="any" required="true">
<cfset super.Init(arguments.controller) />
<cfset setpluginName("Web Services")>
<cfset setpluginVersion("1.0.a")>
<cfset setpluginDescription("This is a very useful web services utility plugin.")>
<cfreturn this>
</cffunction>
<!------------------------------------------- PUBLIC ------------------------------------------->
<cffunction name="getWS" returntype="any" access="Public" hint="Get a web service's wsdl url from the configStruct according to which environment you are on." output="false">
<!--- ************************************************************* --->
<cfargument name="name" hint="The name of the web service. If the web service is not found an exception is thrown." type="string" required="Yes">
<!--- ************************************************************* --->
<cfset var stLocal = structNew() />
<cfset stLocal.stWSVC = getController().getSetting("WebServices") />
<cfif structKeyExists(stLocal.stWSVC, arguments.name)>
<cfreturn stLocal.stWSVC[arguments.name] />
</cfif>
<cfthrow type="ColdBox.plugins.webservices.WebServiceNotFoundException" message="The webservice #arguments.name# was not found in the configuration structure.">
</cffunction>
<!--- ************************************************************* --->
<cffunction name="getWSobj" access="Public" hint="Get a reference to a webservice obj according to which environment you are on." output="false" returntype="any">
<!--- ************************************************************* --->
<cfargument name="name" hint="The name of the web service. If the web service is not found an exception is thrown" type="string" required="Yes">
<!--- ************************************************************* --->
<cfset var stLocal = structNew() />
<cfset stLocal.stWSVC = getController().getSetting("WebServices") />
<cfif structKeyExists(stLocal.stWSVC, arguments.name)>
<cfreturn CreateObject("webservice", stLocal.stWSVC[arguments.name] )>
</cfif>
<cfthrow type="ColdBox.plugins.webservices.WebServiceNotFoundException" message="The webservice #arguments.name# was not found in the configuration structure.">
</cffunction>
<!--- ************************************************************* --->
<cffunction name="refreshWS" access="Public" hint="Refresh a web service stub object" output="false" returntype="void">
<!--- ************************************************************* --->
<cfargument name="webservice" hint="The name or wsdl URL of the web service to refresh" type="string" required="Yes">
<!--- ************************************************************* --->
<!--- Get the Webservice from the configStruct --->
<cfset var ws = getWS(arguments.webservice)>
<cfset var rpcService = "">
<cfset var factory = 0>
<cfif ws neq "">
<cfobject type="java" action="create" name="factory" class="coldfusion.server.ServiceFactory">
<cfset rpcService = factory.XmlRpcService>
<cfset rpcService.refreshWebService(ws)>
<cfelse>
<cfobject type="java" action="create" name="factory" class="coldfusion.server.ServiceFactory">
<cfset rpcService = factory.XmlRpcService>
<cfset rpcService.refreshWebService(arguments.webservice)>
</cfif>
</cffunction>
<!--- ************************************************************* --->
</cfcomponent>





Comments:
[Add Comment]