Skip to content

ColdFusion Component Dynamic Proxy

markmandel edited this page Feb 16, 2012 · 2 revisions

The ColdFusion component dynamic proxy is Java library that provides a Java Dynamic Proxy that allows for the ability to pass ColdFusion Components to Java objects and have Java objects call the CFC methods seamlessly.

Requirements

  • ColdFusion 8 or 9
  • Java 1.5+
  • Including the following .jar's with the JavaLoader loadpaths: ** /javaloader/support/cfcdynamicproxy/lib/cfcdynamicproxy.jar
  • loadColdFusionClassPath must be true

Java Build Path Requirements

If you are using the Dynamic Proxy within a Java Project, the following libraries will need to be added to your Build Path so that it can compile:
/<coldfusion-home>/lib/cfusion.jar

If you need access to any of the J2EE classes, you can import them from:
/<coldfusion-home>/runtime/lib/jrun.jar

API Documentation

JavaDoc Documentaton

Reference

The ColdFusion Component Dynamic Proxy is able to be wrapped around a CFC, and thereby make Java Objects think they are interacting with a native Java object, which implements a given set of interfaces, but in fact, communicate directly with your CFC.

When a Java Object calls a method on the ColdFusion Component Dynamic Proxy, it is passed through and invoked directly on the CFC, completely transparent to your Java layer.

To use the CFC dynamic proxy, you will first need to create a reference to the class com.compoundtheory.coldfusion.cfc.CFCDynamicProxy, as the methods we want to use to create the dynamic proxy are all static.

For example:

CFCDynamicProxy = javaloaderloader.create("com.compoundtheory.coldfusion.cfc.CFCDynamicProxy");

To create an actual dynamic proxy, the static method createInstance() is available on the CFCDynamicProxy object.

The two easiest ways to create a Dynamic Proxy from ColdFusion are is through one of the following method:

DynamicProxy.createInstance(cfc, interfaces)

or

DynamicProxy.createInstance(pathToCFC, interfaces)

Parameter: cfc

The actual CFC to use in the dynamic proxy

Parameter: pathToCFC

The absolute path to the CFC that you wish to create

Parameter: interfaces

A string array of the Java interfaces that this CFC implements with its methods.

Please see the JavaDocs for other arguments that are available for createInstance()

For example, if I had a CFC name 'MyRunner' that has implemented the 'run' method of the Java Interface of java.lang.Runnable, I would end up creating it as:

myRunner = createObject("component", "MyRunner").init();
runnerProxy = CFCDynamicProxy.createInstance(myRunner, ["java.lang.Runnable"]);

I could then pass my runnerProxy to a java.lang.Thread on construction, as to Java it doesn't know the runnerProxy is anything but an instance of java.lang.Runnable, like so:

thread = createObject("java", "java.lang.Thread").init(runnerProxy);
thread.run();
Clone this wiki locally