-
Notifications
You must be signed in to change notification settings - Fork 25
ColdFusion Component Dynamic Proxy
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.
- 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
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
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)
The actual CFC to use in the dynamic proxy
The absolute path to the CFC that you wish to create
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();