ColdFusion MX 7.0.1 includes a Java CFCProxy class which can be used to invoke ColdFusion Components from within Java code. Lots of developers are trying to find documentation on this class, and we will be posting this shortly. But in the interim, I have posted a copy on my site.
First I received this error:Caused by: java.lang.NoClassDefFoundError: coldfusion/cfc/CFCProxy, Caused by: java.lang.ClassNotFoundException: coldfusion.cfc.CFCProxy
Now I received this error: instantiation exception.An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: coldfusion/cfc/CFCProxy...
------------------------
test.cfm:
------------------------
<cfset invkJAVA = createObject("java","Coldfusion2").init()>
<cfset LvarArgs = structNew()>
<cfset LvarArgs.dato = "hello">
<cfset x = invkJAVA.jCFCinvoker('TestColdfusion','ping',LvarArgs)>
------------------------
Coldfusion2.java:
------------------------
import coldfusion.cfc.CFCProxy;
import java.util.Map;
public class Coldfusion2
{
public java.util.Map jCFCinvoker(String cfc, String fn, java.util.Map args)
throws Throwable
{
Map map = null;
try{
CFCProxy myCFC;
myCFC = new CFCProxy ("C:\\ColdFusion9\\wwwroot\\TestColdfusion.cfc");
Object[] myArgs = {cfc, fn, args};
map = (java.util.Map) myCFC.invoke("rmiCFCinvoker", myArgs);
}catch (Throwable e){
System.out.println("exception: " + e.getMessage());
e.printStackTrace();
}
return map;
}
}
------------------------
TestColdfusion.cfc
------------------------
<cffunction name="ping" returntype="string" output="no">
<cfargument name="dato" required="yes" type="string">
<cfreturn dato>
</cffunction>
<cffunction name="rmiCFCinvoker" returntype="any" output="no">
<cfargument name="cfc" required="yes">
<cfargument name="fn" required="yes">
<cfargument name="args" required="yes" type="struct">
<cfset LvarResult = structNew()>
<cfset LvarResult.Error = "">
<cftry>
<cfinvoke component ="#Arguments.cfc#"
method ="#Arguments.fn#"
returnvariable="LvarRes"
>
<cfloop collection="#Arguments.args#" item="arg">
<cfinvokeargument name="#arg#" value="#Arguments.args[arg]#">
</cfloop>
</cfinvoke>
<cfif isdefined("LvarRes")>
<cfset LvarResult.Result = LvarRes>
</cfif>
<cfcatch type="any">
<cfset LvarResult.Error = cfcatch.Message & " " & cfcatch.Detail>
</cfcatch>
</cftry>
<cfreturn LvarResult>
</cffunction>
-------------------------------------------
myCFC = new CFCProxy ("C:\\ColdFusion9\\wwwroot\\TestColdfusion.cfc");
and
map = (java.util.Map) myCFC.invoke("rmiCFCinvoker", myArgs);
(and recompile Coldfusion2 and restart CF), you won't get the errors when invoking the class from within CF, but of course the question it begs is why the CFCProxy is considered notfound. I'm experiencing the same thing in CF8 (so it's not a CF9 thing). I can confirm (for those who would wonder) that I am on the Enterprise edition, not Standard. the CFCProxy is inside the cfusion.jar, which is already in the classpath for CF. Very curious.