Problem with CFMX 7 and JavaLoader

61 views
Skip to first unread message

webpointz

unread,
Nov 6, 2009, 9:14:54 AM11/6/09
to javaloader-dev
I have CF code which is being used in a project to extract information
from a digital signature using the iText API.

I need to use the JavaLoader so that I can keep the latest iText from
breaking the original iText.jar that ships with CFMX 7.

If I employ the following code:

<cfscript>
// WARNING: do not do this on production. store the javaloader
// in the server scope to avoid a memory leak
paths = arrayNew(1);
paths[1] = expandPath("/iText/iText-2.1.7.jar");
loader = createObject("component", "comnew.javaloader.JavaLoader").init
( paths );
document = loader.create("com.lowagie.text.Document").init();
WriteOutput("version="& document.getVersion() &"<br>");
document.setMarginMirroring( javacast("boolean", true) );
document.close();
WriteOutput("success<br>");
</cfscript>

I get the following results showing me it is correctly accessing the
latest JAR file:

version=iText 2.1.7 by 1T3XT
success

However, if I try to access the following:

PdfPKCS7 = CreateObject("java","com.lowagie.text.pdf.PdfPKCS7");

I get this error:

Object Instantiation Exception.
An exception occurred when instantiating a java object. The cause of
this exception was that: .

The error occurred in C:\Inetpub\wwwroot\comnew\javaloader
\JavaLoader.cfc: line 153
Called from C:\Inetpub\wwwroot\comnew\javaloader\JavaLoader.cfc: line
95
Called from C:\Inetpub\wwwroot\test_itext.cfm: line 28
Called from C:\Inetpub\wwwroot\comnew\javaloader\JavaLoader.cfc: line
153
Called from C:\Inetpub\wwwroot\comnew\javaloader\JavaLoader.cfc: line
95
Called from C:\Inetpub\wwwroot\test_itext.cfm: line 28

151 : }
152 :
153 : return createObject("java",
"coldfusion.runtime.java.JavaProxy").init(arguments.class);
154 : </cfscript>
155 : </cffunction>

at cfJavaLoader2ecfc732234946$funcCREATEJAVAPROXY.runFunction(C:
\Inetpub\wwwroot\comnew\javaloader\JavaLoader.cfc:153) at
cfJavaLoader2ecfc732234946$funcCREATE.runFunction(C:\Inetpub\wwwroot
\comnew\javaloader\JavaLoader.cfc:95) at
cftest_itext2ecfm1546285713.runPage(C:\Inetpub\wwwroot\test_itext.cfm:
28) at cfJavaLoader2ecfc732234946$funcCREATEJAVAPROXY.runFunction(C:
\Inetpub\wwwroot\comnew\javaloader\JavaLoader.cfc:153) at
cfJavaLoader2ecfc732234946$funcCREATE.runFunction(C:\Inetpub\wwwroot
\comnew\javaloader\JavaLoader.cfc:95) at
cftest_itext2ecfm1546285713.runPage(C:\Inetpub\wwwroot\test_itext.cfm:
28)

java.lang.reflect.InvocationTargetException

HELP!!











Leigh

unread,
Nov 6, 2009, 11:03:57 AM11/6/09
to javaloader-dev
> PdfPKCS7 = CreateObject("java","com.lowagie.text.pdf.PdfPKCS7");

You cannot mix javaLoader objects and ones created with createObject
(). As the objects are created by different class loaders, they are
not compatible. You must create all of your iText objects with the
JavaLoader.

-Leigh

webpointz

unread,
Nov 6, 2009, 11:48:49 AM11/6/09
to javaloader-dev
Sorry...I posted incorrect code.

This works fine:

pdfReader = loader.create("com.lowagie.text.pdf.PdfReader").init("C:
\inetpub\wwwroot\Invoice100034Frank.pdf");
acroFields = pdfReader.getAcroFields();

This doesn't and throws the error:

PdfPKCS7 = loader.create("com.lowagie.text.pdf.PdfPKCS7");

Leigh

unread,
Nov 6, 2009, 12:08:23 PM11/6/09
to javaloader-dev
> java.lang.reflect.InvocationTargetException

Given the classes you are using, you seem to working with signatures.
Look further down in the stack trace for the real cause. If you see an
error message similar to this, you probably forgot to load a required
jar:

java.lang.NoClassDefFoundError: org/bouncycastle/asn1/
DEREncodable

Download the Bouncy Castle jar from svn and add it to your javaLoader
paths.
bcprov-jdk14-138.jar
http://itext.svn.sourceforge.net/viewvc/itext/trunk/lib/

webpointz

unread,
Nov 6, 2009, 2:58:59 PM11/6/09
to javaloader-dev
Thanks...yes writing code that will verify and extract signature
certificate information.

Basically, the code was missing a pointer to the file "bctsp-
jdk14-138.jar" so I have added it in.
Things are now working as they should. It now seems to be a JVM issue
as my error message now is:

ExceptionConverter: java.security.NoSuchAlgorithmException: SHA256
MessageDigest not available

Thanks

Mark Mandel

unread,
Nov 6, 2009, 3:44:38 PM11/6/09
to javaloa...@googlegroups.com
This seems related:
http://www.coderanch.com/t/134224/Security/want-use-SHA-Algorithm-J

This is why it is very important to develop on the JVM version that you deploy on.

Mark
--
E: mark....@gmail.com
T: http://www.twitter.com/neurotic
W: www.compoundtheory.com

Reply all
Reply to author
Forward
0 new messages