[coldbox-3.7.0] Headache with JavaLoader Plugin

In one of my apps, I’m wanting to convert SVG (from an HTML5-ish chart) to PNG. To do this, I found the Batik SVG Toolkit.

I have been trying like heck to get this implemented, but no matter what I try, I cannot seem to get it to work with the JavaLoader plugin.

Here’s what I’ve done:

When I run the script, however, I get an error like so:

`
Object instantiation exception.
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: org/apache/batik/dom/util/DocumentFactory.

`

On a whim, I tried ditching the JavaLoader approach, and simply added all the batik-{}.jar files to the ColdFusion library path. I tried the same approach in the code (sans the JavaLoader bits), and everything worked perfectly.

I feel like I’m doing something very obviously and stupidly wrong, but have restarted ColdFusion way too many times to be able to see things clearly any longer. I would love to be able to use JavaLoader for this, but am wondering if I’m doing something wrong or if this particular scenario won’t work.

I definitely appreciate any advice that anyone can offer.

Thanks!

But DocumentFactory is an interface. Isn’t that error expected?

http://xmlgraphics.apache.org/batik/javadoc/org/apache/batik/dom/util/DocumentFactory.html

Are you sure you’re using the library correctly? Are you trying instantiate the DocumentFactory in your code? if not, can you show a stack trace of the full error?

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Hi Brad–

Right, but my point is that it only occurs when I try to use this library via JavaLoader. If I add the jars to the CF lib path, it does not error and produces the desired result (a PNG stream).

I’m including a gist of what my code, the example SVG content, and the stack trace.

Thanks!

CODE:

`


var response = getPageContext().getFusionContext().getResponse();
    response.setContentType( 'image/png' );
 
var content = fileread( expandPath( "./handlers/test.svg" ) );
 
var inputStream = createObject("java", "java.io.StringBufferInputStream").init( content );
var input = createObject( "java", "org.apache.batik.transcoder.TranscoderInput").init(inputStream);
 
var outputStream = response.getOutputStream();;
var output = createObject( "java", "org.apache.batik.transcoder.TranscoderOutput").init(outputStream);
 
var transcoder = createObject( "java", "org.apache.batik.transcoder.image.PNGTranscoder" ).init();
 
transcoder.transcode(input, output);
outputStream.close(); 

`

ERROR:

Object instantiation exception. An exception occurred while instantiating a Javaobject.Theclass must not be an interfaceor an abstractclass.Error: org/apache/batik/dom/util/DocumentFactory.

STACK:
`


coldfusion.runtime.java.JavaObjectInstantiationException: Object instantiation exception.
  at coldfusion.runtime.java.JavaProxyFactory.getProxy(JavaProxyFactory.java:170)
      at coldfusion.runtime.ProxyFactory.getProxy(ProxyFactory.java:65)
       at coldfusion.runtime.CFPage.createObjectProxy(CFPage.java:5747)
        at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5710)
     at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5644)
     at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5619)
     at coldfusion.runtime.CFPage.CreateObject(CFPage.java:5566)
     at cfGeneral2ecfc646371968$funcINDEX.runFunction(/Applications/MAMP/htdocs/gloss_2.0/handlers/General.cfc:32)
   at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
      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:518)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469)
      at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373)
    at coldfusion.tagext.lang.InvokeTag.doEndTag(InvokeTag.java:402)
        at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2800)
       at cfController2ecfc1145999322$funcINVOKER.runFunction(/Applications/MAMP/htdocs/coldbox_3.7.0/coldbox/system/web/Controller.cfc:756)
   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.CfJspPage._invokeUDF(CfJspPage.java:2659)
 at cfController2ecfc1145999322$funcRUNEVENT.runFunction(/Applications/MAMP/htdocs/coldbox_3.7.0/coldbox/system/web/Controller.cfc:640)
  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:518)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:660)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:469)
      at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2373)
    at cfColdbox2ecfc365152025$funcPROCESSCOLDBOXREQUEST.runFunction(/Applications/MAMP/htdocs/coldbox_3.7.0/coldbox/system/Coldbox.cfc:236)
        at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
      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:655)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414)
      at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2432)
    at cfApplication2ecfc1740922731$funcONREQUESTSTART.runFunction(/Applications/MAMP/htdocs/gloss_2.0/Application.cfc:82)
  at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
      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:655)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:444)
      at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:414)
      at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:108)
  at coldfusion.runtime.AppEventInvoker.onRequestStart(AppEventInvoker.java:278)
  at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:411)
       at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
  at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
  at coldfusion.filter.PathFilter.invoke(PathFilter.java:112)
     at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:30)
        at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:94)
    at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
  at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
        at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
        at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
        at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
  at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
        at coldfusion.CfmServlet.service(CfmServlet.java:204)
   at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
   at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
 at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:414)
  at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:203)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:298)
     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: org/apache/batik/dom/util/DocumentFactory
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2300)
    at java.lang.Class.privateGetPublicFields(Class.java:2333)
      at java.lang.Class.getFields(Class.java:1361)
   at coldfusion.runtime.java.ObjectHandler.Initialize(ObjectHandler.java:35)
      at coldfusion.runtime.java.ObjectHandler.(ObjectHandler.java:30)
        at coldfusion.runtime.java.ReflectionCache.get(ReflectionCache.java:38)
 at coldfusion.runtime.java.JavaProxy.(JavaProxy.java:35)
        at coldfusion.runtime.java.JavaProxyFactory.getProxy(JavaProxyFactory.java:121)
 ... 95 more
Caused by: java.lang.ClassNotFoundException: org.apache.batik.dom.util.DocumentFactory
       at coldfusion.bootstrap.BootstrapClassLoader.loadClass(BootstrapClassLoader.java:235)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 104 more

`

Blush

Ok, I figured it out I think. Turns out that one of the supplemental jars included with the Batik library was needed in addition to the core batik-* jars. Apparently, one of them (xml-apis.jar) is already in the CF lib, so that explains why it was working when I added the jars there. To get it to work with JavaLoader, I just had to add xml-apis-ext.jar to the same location as my other loaded jars.

I had tried this before, but instead of adding the supplemental jars one by one, I added all of them in one lump. I think the xml-apis.jar that comes with Batik was conflicting with the one in CF, and so put me down a false path in my trouble-shooting.

Thanks

Joel, this has plagued me for years as well.

The solution is what you did, a quick google search will show you the following

http://forums.adobe.com/thread/415943

https://groups.google.com/forum/#!topic/javaloader-dev/FQqdqX7J-yE

Definitely good to know–thanks Andrew!

No problem.

Yeah - always have to remember - go hunting for the “Caused by:” clause - that will tell you all.

Mark