JavaLoader Plugin and WURFL problems

I was trying to get this to work and create a standard plugin for the community to use, but ran into an issue with both of these applications.

If I use createObject I have no problems getting this to work, but not with JavaLoader. So does anyone have any ides?

var libPath = ‘/system/plugins/WURFL-lib’;

var wurflFile = ExpandPath(libPath & ‘\wurfl.xml’);

var wurflObj = createObject(“java”,“java.io.File”).init(wurflFile);

getPlugin(“JavaLoader”).appendPaths(ExpandPath(libPath););

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);

manager = temp.getWURFLManager();

The error message is

An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: ‘’.

I thought I would look into the other and probably more correct way of doing it, which is

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.WURFLHolder”);

manager = temp.getWURFLManager();

Even though I can dump the actual object out, the method getWURFLManager() is not found. And yet it looks like it is in the object. Anyone have an clues.

Regards,

Andrew Scott

http://www.andyscott.id.au/

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: ‘’.

Is that code exaclty the code you were using when you received the error? Below you show net.sourceforge.wurfl.core.WURFLHolder which is an interface, and therefore has impicitly abstract methods. You should expect to recieve the above error when trying to create an instance of an interface.

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.WURFLHolder”);
manager = temp.getWURFLManager();

Even though I can dump the actual object out, the method getWURFLManager() is not found. And yet it looks like it is in the object. Anyone have an clues.

You have to use the init() method to actually get an instance of the class. Otherwise you area just getting the class definition. (the equivilant of getMetaData()) And again, here you are creating the class info for the abstract interface WURFLHolder. I don’t know anything about WURFL, but you probably want the concrete class CustomWURFLHolder which implements WURFLHolder.

http://wurfl.sourceforge.net/njava/javadocs/net/sourceforge/wurfl/core/CustomWURFLHolder.html

Thanks!

~Brad

Brad,

I am not sure I am understanding you with this

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

If I replace the logic to be

var temp = createObject(‘java’, “net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

It works fine.

I don’t think you understand the last one, I said I am getting an instance of the class. And when you dump it out it is clear that method exists, and yet when you call it the messages says there are no methods that match, and that I should be using JavaCast. Now as the JavaDocs tell me that the method takes no arguments, I am not really sure what I can do there.

But the real problem is the first example, if I dump the jar file into a known class path and instantiate using createObject I have no problem. Yet if I remove that object from the class path an try to use the JavaLoader I get the problem.

And the init() is only used if it has a constructor too Brad, which the second way I am trying doesn’t have a constructor.

Regards,

Andrew Scott

http://www.andyscott.id.au/

I am not sure I am understanding you with this

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

If I replace the logic to be
var temp = createObject(‘java’, “net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

It works fine.

If that first code sample above is the one returning the “The class must not be an interface or an abstract class” error, then I’m not sure what the problem might be. I was simply asking if you had really been inadvertanlty trying to create an instance of WURFLHolder instead of CustomWURFLHolder depsite what you pasted in.

I don’t think you understand the last one, I said I am getting an instance of the class.

Not with the code you posted, you aren’t. This from the JavaLoader docs:
This works exactly the same as createObject(“java”, className), such that simply calling create(className)
gives you access to the static properties of the class, but to get an instance through calling the
Constructor you are required to call create(className).init();

And when you dump it out it is clear that method exists,

Yes, if you dump out the static class definition you would see the method name in there, but you aren’t dumping an actual instance of the class. Besides that, WURFLHolder is an interface so you aren’t going to be able to call the methods anyway.

and yet when you call it the messages says there are no methods that match, and that I should be using JavaCast. Now as the JavaDocs tell me that the method takes no arguments, I am not really sure what I can do there.

I think the javaCast() bit in the error message is just trying to be helpful. WURFLHolder is abstract, and most likley a red herring.

But the real problem is the first example, if I dump the jar file into a known class path and instantiate using createObject I have no problem. Yet if I remove that object from the class path an try to use the JavaLoader I get the problem.

Yeah, I don’t have a good answer for that. I downloaded the WURFL jar to play with it and I see the same “An exception occurred when instantiating a Java object.” error when trying to initialize an instance of CustomWURFLHolder with javaloader. I’m kind of curious if the fact that the CustomWURFLHolder class has a protected method called “init” has anything to do with it. If not, it probably has something to do with another class path that’s not being found when using javaloader. The site mentions that it is dependant on xercesImpl.jar and xmlParserAPIs.jar. There’s a chance they’re being found in the classpath when using createObject, but not by javaloader. Mark Mandel hangs out on this list so he will hopefully chime in. If not, you can post over on the javaloader list. http://groups.google.com/group/javaloader-dev

And the init() is only used if it has a constructor too Brad, which the second way I am trying doesn’t have a constructor.

Actually all Java classes have a constructor. If you don’t type it in, the compiler creates one for you. Also, if you don’t explicitly call it with init(), ColdFusion will call the default constructor for you. So, you can get away with not calling init explicitly if the default constructor for a class accepts no arguments, but don’t be fooled-- it’s getting called behind the scenes. That doesn’t change the fact that WURFLHolder is an interface with abstract methods which cannot be called though.

If you find the answer off-list, please do post it. I’m really curious now what is causing your error initializing the CustomWURFLHolder class.

Thanks!

~Brad

Ok Brad that makes sense, the last one was because that was how they were doing it in the Java examples.

I still don’t comprehend why this works

var temp = createObject(‘java’, “net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

and this doesn’t

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

Regards,

Andrew Scott

http://www.andyscott.id.au/

Ok Brad that makes sense, the last one was because that was how they were doing it in the Java examples.

I still don’t comprehend why this works

var temp = createObject(‘java’, “net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

and this doesn’t

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);
manager = temp.getWURFLManager();

Luis, even though I received the same error as Andrew, I don’t know if my stack trace was the same. He can provide the stack trace he is getting, but in the mean time, this is the relevant portion of the stack trace I see when I try the code he provided:

# Object Instantiation Exception.
An exception occurred when instantiating a Java object. The class must not be an interface or an abstract class. Error: ‘’.

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:156)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:63)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2272)
at cftest2ecfm746405006.runPage(D:\websites\dev.mylocalsite.com\test.cfm:12)

Line 12 of test.cfm is this:

<cfset temp = application.JavaLoader.create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj)>

ooh, this looks it’s actually the problem. Like you said Luis, the real error is often farther down. I forgot that the generic CF error page truncates the stack. When I try/catch the error and dump the full catch, there are two other nested errors that preceed the above one. Looks like the actual error is indeed additional classes that the javaloader’s classloader is not finding. Specificlaly org.apache.commons.lang.Validate,

java.lang.NoClassDefFoundError: org/apache/commons/lang/Validate at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:82)
at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:105)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:156)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:63)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2272)
at cftest2ecfm746405006.runPage(D:\websites\dev.mylocalsite.com\test.cfm:12)

java.lang.ClassNotFoundException: org.apache.commons.lang.Validate
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.findSystemClass(ClassLoader.java:883)
at com.compoundtheory.classloader.NetworkClassLoader.loadClass(NetworkClassLoader.java:473)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:82)
at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:105)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:156)
at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:63)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2272)
at cftest2ecfm746405006.runPage(D:\websites\dev.mylocalsite.com\test.cfm:12)

I would recommend finding whatever JAR includes those apache classes and adding it into the array of jars that the javaloader loads.

Thanks!

~Brad

Eureka! I find that sometimes when dealing with java class loading and native java errors, they are depeer in the stack.

coldfusion.runtime.java.JavaObjectInstantiationException: Object instantiation exception.

at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:171)

at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80)

at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360)

at cfwurfl2ecfc1807922066$funcINIT.runFunction(C:\projects\ColdFusion\dev.andyscott.id.au\wwwroot\system\plugins\wurfl.cfc:33)

Regards,

Andrew Scott

http://www.andyscott.id.au/

Brad, thanks for the extra info that indeed would explain why it worked when I dropped it in the normal ClassPath and used createObject.

However I get a different error to you when I do the try/catch

java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source) at net.sourceforge.wurfl.core.resource.XMLResource.readData(XMLResource.java:302) at net.sourceforge.wurfl.core.resource.XMLResource.getData(XMLResource.java:134) at net.sourceforge.wurfl.core.resource.DefaultWURFLModel.(DefaultWURFLModel.java:83) at net.sourceforge.wurfl.core.CustomWURFLHolder.init(CustomWURFLHolder.java:116) at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:100) at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:105) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166) at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360) at cfwurfl2ecfc1807922066$funcINIT.runFunction(C:\projects\ColdFusion\dev.andyscott.id.au\wwwroot\system\plugins\wurfl.cfc:35) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:491) at

Regards,

Andrew Scott

http://www.andyscott.id.au/

Brad, thanks for the extra info that indeed would explain why it worked when I dropped it in the normal ClassPath and used createObject.

However I get a different error to you when I do the try/catch

java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source) at net.sourceforge.wurfl.core.resource.XMLResource.readData(XMLResource.java:302) at net.sourceforge.wurfl.core.resource.XMLResource.getData(XMLResource.java:134) at net.sourceforge.wurfl.core.resource.DefaultWURFLModel.(DefaultWURFLModel.java:83) at net.sourceforge.wurfl.core.CustomWURFLHolder.init(CustomWURFLHolder.java:116) at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:100) at net.sourceforge.wurfl.core.CustomWURFLHolder.(CustomWURFLHolder.java:105) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:166) at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360) at cfwurfl2ecfc1807922066$funcINIT.runFunction(C:\projects\ColdFusion\dev.andyscott.id.au\wwwroot\system\plugins\wurfl.cfc:35) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47) at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220) at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:491) at

Ok there weird thing is that I am now getting the same error as Brad, didn’t change anything.

If I try to put the classpath for the comms language in the JavaLoaders path, ColdFusion resets itself. I will have to look into the logs as to why on that.

So the next thing I tried was to copy the commons-lang.jar into the same dir as the wurfl jar, nope same error.

So I removed the jar from where I have it and dropped it into a known CF9 classpath, and modified the code too.

var libPath = ‘/system/plugins/WURFL-lib’;

var wurflFile = ExpandPath(libPath & ‘\wurfl.xml’);

var wurflObj = createObject(“java”,“java.io.File”).init(wurflFile);

try {

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);

this.temp = temp;

} catch(Any e) {

writeDump(e); abort;

}

And it works, but as soon as I take the jar out of the known classpath and back in the libpath dir in the code, and modify the code too it fails.

var libPath = ‘/system/plugins/WURFL-lib’;

var wurflFile = ExpandPath(libPath & ‘\wurfl.xml’);

var wurflObj = createObject(“java”,“java.io.File”).init(wurflFile);

var path = ExpandPath(libPath);

getPlugin(“JavaLoader”).appendPaths(path);

try {

var temp = getPlugin(“JavaLoader”).create(“net.sourceforge.wurfl.core.CustomWURFLHolder”).init(wurflObj);

this.temp = temp;

} catch(Any e) {

writeDump(e); abort;

}

And as I said if I use the lib dir in the CF9 classpath and append it to JavaLoader ColdFusion actually crashes a number of times before running, which is weird. But I think it has something to do with the amount of jars in that directory. Either way this is really got me stumped.

Regards,

Andrew Scott

http://www.andyscott.id.au/

xerces is one of those tricky libs that can be *very* hard to use with
a classloader.

Have you tried the other options of javaloader? Like the one that
includes the CF lib path?

:Den

No what is that option I would like to try it.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of denstar
Sent: Friday, 7 January 2011 5:31 AM
To: coldbox@googlegroups.com
Subject: Re: [coldbox:7559] Re: JavaLoader Plugin and WURFL problems

xerces is one of those tricky libs that can be *very* hard to use with a
classloader.

Have you tried the other options of javaloader? Like the one that

includes

Never mind I got it to work, I feel like a goose because I was creating a
new instance of the JavaLoader plugin, after setting the path :frowning:

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of denstar
Sent: Friday, 7 January 2011 5:31 AM
To: coldbox@googlegroups.com
Subject: Re: [coldbox:7559] Re: JavaLoader Plugin and WURFL problems

xerces is one of those tricky libs that can be *very* hard to use with a
classloader.

Have you tried the other options of javaloader? Like the one that

includes