Blog

29Sep
2005
Using ColdFusion MX 7.0.1 CFCProxy

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.

Comments (8)



  • Gareth

    Is this an enterprise only feature?

    #1Posted by Gareth | Sep 29, 2005, 05:55 PM
  • Michael Dinowitz

    Yes

    #2Posted by Michael Dinowitz | Sep 29, 2005, 11:12 PM
  • Mujeebur Rahmansaher

    Thanks a Lot Ben! Forta.com is a ideal place to get your answers.:)

    #3Posted by Mujeebur Rahmansaher | Sep 30, 2005, 11:11 AM
  • Michael Dinowitz

    The docs say that the CF Classloader has to be the current classloader for any class making use of a CFCProxy. Does this mean that only java classes called by ColdFusion can use CFCProxy or that a non-ColdFusion app can use CFCProxy in some way?

    I'm sure that this is totally clear to a J2EE person, but the question of how to get a class to be part of the ColdFusion context without being inside ColdFusion is one that has to be asked.

    #4Posted by Michael Dinowitz | Sep 30, 2005, 12:02 PM
  • Sean Corfield

    Java code running in the same J2EE Context as ColdFusion will bee able to use CFCProxy.

    #5Posted by Sean Corfield | Oct 1, 2005, 01:53 AM
  • George Bridgeman

    Ben,

    The application scope does not seem to be accessible from a CFC created via CFCProxy.

    My methods work fine when I create the CFC from ColdFusion but as soon as I create it from Java using CFCProxy I get errors because variables don't exist in the application scope.

    Is this intended behaviour?

    George.

    #6Posted by George Bridgeman | Mar 20, 2009, 11:16 AM
  • Ozkar

    CFCproxy in Coldfusion 9
    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>
    -------------------------------------------

    #7Posted by Ozkar | Oct 7, 2009, 05:22 PM
  • Charlie Arehart

    Ozkar, did you ever resolve your problem? I can report that both errors have the same underlying cause: if you comment out the lines:

    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.