We are trying to implement a java interface in a C...
# cfml-beginners
b
We are trying to implement a java interface in a Coldfusion component. The component is a callback from another java function and needs to be of a certain type. We tried several values in the implements but got errors for all of them.
Copy code
component implements = "java:com.digitalpersona.uareu.Engine.EnrollmentCallback" {

component implements = "java:com.digitalpersona.uareu.Engine$EnrollmentCallback" {

component implements = "java:Engine.EnrollmentCallback" {
This is how we are calling it from our cfm like this
Copy code
createObject(component, "...callback_component").init(rc);
and this is the error message we are seeing
Copy code
The java:com.digitalpersona.uareu.Engine.EnrollmentCallback ColdFusion component or interface name, used to extend or implement the model.UserProfile.callback_component component is invalid. Ensure that the file exists, that the name does not start or end with a period (.), and the name is not an empty string.

Invalid component or interface name.
We have the jar file for digitalpersona in our lib directory and are using the other classes & interfaces already. But I'm not sure we have the right value in for implements or maybe we are missing something somewhere else.
a
Yer def running CF2021 yeah?
b
We are running CF11 I think
a
Yeah that ability to implement Java interfaces was only added in CF2021.
b
You'll need to use
createDynamicProxy()
instead @Becky Hilton
b
@bdw429s Would I then also need to create my own Java class to act as the proxy?
b
Have you read the docs on
createDynamicproxy()
yet?
b
I was just reading through and wanted to make sure I was understanding it correctly
b
You basically just create a CFC that implements all the methods, and then tell CF what interface you want it to implement. It's creates a java class behind the scenes on the fly to proxy to it
b
ok
But in step 3 of the second document it says "Create a Java class"
b
That's just an example
An example where they wrote their own java classes in order to prove the CF function was doing what it advertized
b
ok
b
Honestly it would have been a much better example if they just picked some well-known part of the JDK that used an interface and then showed using that
b
yeah no kidding
b
Presumably you're already using a java library that requires the interface that you need to pass the CFC into.
I will warn you-- I see the word "callback" in the interface name which implies your CFC may be executed in another thread
This will "work", but your CFML code will be disconnected from an application settings or request/cgi/form/url variables if it runs inside another thread
@Becky Hilton
b
ok
We will give it a try and see what happens. And maybe just try to upgrade 😆
b
This is a massive oversight in CF IMO and the ColdBox frameworks have gone to great length to make stuff like that work.
Upgrading won't help
This is just the nature of how CF code works when you cram it in a thread without a CF page context
I've been talking to the Adobe and Lucee engineers about this for years. Adobe did mark my recent ticket as "to fix" so I guess there is hope for the universe.. https://tracker.adobe.com/#/view/CF-4213223
b
So then would it look something like this @bdw429s what would I put for the InvokeHelloProxy?
Copy code
instance= new cfc.callback_component();
dynInstnace = createDynamicProxy(instance, ["java:com.digitalpersona.uareu.Engine.EnrollmentCallback"]);
x = createObject("java","InvokeHelloProxy").init(dynInstnace);
y = x.myFunction();
b
That looks like you're on the right track, but I'm not sure about line 3 without knowing what actual java class requires the callback
It won't necessarily be a constructor arg
it could be passed as part of a setter, etc
I can't find any java docs online for that library
b
When I do the first two lines I'm getting this error "java.lang.ClassNotFoundException: com.digitalpersona.uareu.Engine.EnrollmentCallback"
@bdw429s
b
Have you added the jar containing that interface/class to the JVM's classpath?
There's a whole lot of missing information here to really know what you're doing
it's also possible that's a nested class. I can't find any javadocs or source code online that appears to match this project so I can't say
com.digitalpersona.uareu.Engine$EnrollmentCallback
is probably what you want if it's an inner class
Also, get rid of the
java:
So try just this for starters
Copy code
instance= new cfc.callback_component();
dynInstnace = createDynamicProxy(instance, "com.digitalpersona.uareu.Engine$EnrollmentCallback");
The array is also unnecessary of you're just implementing a single interface
b
we will give it a try - @bdw429s I appreciate the help
👍 1
We are making progress! but I have another question. The below code is working:
Copy code
local.orgInst = new model.UserProfile.callback_component(rc);
local.dynInstance = createDynamicProxy(local.orgInst, ["com.digitalpersona.uareu.Engine$EnrollmentCallback"]);
local.x = createObject("java","com.digitalpersona.uareu.dpfj.EngineImpl");
But it doesn't let me do an init on the last line because there isn't one in the EngineImp
We got an error about not having a constructor when we tried to include the init() to the last line @bdw429s
And i'm not sure that we are creating the correct Object
b
We got an error
@Becky Hilton Please include the full stack trace. There are many 'errors' you could be talking about
b
oh i'm sorry i forgot to include it
b
I don't see a constructor at all on that class, so it may be that you're not supposed to create it directly. Are you following a guide for this library that shows how to use it?
If you have an example of actual working java code, that would make this whole thing a lot simpler
b
Well... They gave us some code examples in java, C etc and we are trying to replicate from there
"Use the Enrollment interface to create an FMD of type DP_REGISTRATION. For Java, the interface and method to use is Engine.CreateEnrollmentFmd. " is the description in the documentation
b
I would highly recommend asking for a working Java example.
I can tell you how CF interacts with java classes, but I have no idea about how this particlar library works
that is what I'm trying to replicate
b
I have a feeling this is part of the step you're missing https://github.com/ankit4u3/Digital-Persona/blob/90f0af37b7108adcd0eb0bb1c3f53ca62bd6673f/src/Enrollment.java#L100 I dont' think you're supposed to create the engine yourself
I don't see any references at all to the engine class in your last example link
b
I didn't include that part
but we do have it working
b
So the fact you're trying to directly instantiate engineimpl tells me you're not following that example
I didn't include that part
I don't know what that means
but we do have it working
So what exactly is your question then?
b
Copy code
hidObj = createObject("java","com.digitalpersona.uareu.UareUGlobal").init();
fmdObj = createObject("java","com.digitalpersona.uareu.Fmd$Format");
engine = hidObj.GetEngine();
that is where we're creating our engine object
b
Good luck with all this. There's literally no way I can follow any of this by seeing only snippets of code here and there that change from message to message and still not seeing a single error message. 🙂
b
ok