What is line 91 in your java file? That's where the error in your class
is being thrown,

Phil

-----Original Message-----
From: Russ [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 18, 2007 11:46 AM
To: CF-Talk
Subject: RE: CF and Java

Looks like something is getting a null pointer, meaning something is not
getting set.  I usually find it easier to create the methods, test them
in
java through eclipse (stepping through the debugger if necessary) and
once
it's ready to put it to cf.  Basically it's breaking at line 91 in your
file, so either your passing some null variable, or you forgot to set
something, etc.. 

Russ

> -----Original Message-----
> From: Andrew Whone [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, April 18, 2007 11:01 AM
> To: CF-Talk
> Subject: Re: CF and Java
> 
> I got a bit further on using Mark Mandels Javaloader.
> The coldfusion code is:
> <cfscript>
> loadPaths = ArrayNew(1);
> loadPaths[1] = expandPath("irmarkjars");
> loadPaths[2] = expandPath("irmarkjars\jce-jdk13-114.jar");
> loadPaths[3] = expandPath("irmarkjars\style-apachexml.jar");
> loadPaths[4] = expandPath("irmarkjars\stylebook-1.0-b3_xalan-2.jar");
> loadPaths[5] = expandPath("irmarkjars\xmlParserAPIs.jar");
> loadPaths[6] = expandPath("irmarkjars\xmlsec.jar");
> loadPaths[7] = expandPath("irmarkjars\jakarta-log4j-1.2.6.jar");
> loadPaths[8] = expandPath("irmarkjars\xercesImpl.jar");
> loadPaths[9] = expandPath("irmarkjars\xml-apis.jar");
> loadPaths[10] = expandPath("irmarkjars\xalan.jar");
> loader = createObject("component",
> "javaloader.JavaLoader").init(loadPaths);
> IRMark = loader.create("IRMark");
> ret = IRMark.init("input.xml");
> </cfscript>
> <cfoutput>#ret.doStuff()#</cfoutput>
> 
> The java code is:
> public class IRMark  {
>      protected String filename;
>   public IRMark (String filename) throws Exception
>   {
>     this.filename=filename;
>               }
>       public String doStuff()throws Exception
>       {
>         // Init the Apache XML security library
>               Init.init();
> 
>                               // Open the input file
>               FileInputStream fis=null;
>               try {
>                       fis=new
> FileInputStream("C:\\CFusionMX7\\wwwroot\\tradesmen\\input.xml");
>               } catch (FileNotFoundException e) {
>                       return("The file " + filename + " could not be
> opened.");
>               }
>               // Load file into a byte array
>               byte[] data=null;
>               try {
>                       int bytes=fis.available();
>                       data=new byte[bytes];
>                       fis.read(data);
>               } catch (IOException e) {
>                       System.out.println("Error reading file.");
>                       e.printStackTrace();
>                       return("Error reading file.");
>               }
>                               // First part is to run the a transform
over
the
> input to extract the
>               // fragment to be digested. This is done by setting up a
> Transforms
>               // object from a Template and then executing against the
input
> document
>               // The transforms to be performed are specified by using
the
> template XML below.
>               String transformStr =
>         "<?xml version='1.0'?>\n"
>               + "<dsig:Transforms
> xmlns:dsig='http://www.w3.org/2000/09/xmldsig#'
> xmlns:gt='http://www.govtalk.gov.uk/CM/envelope'
> xmlns:ir='http://www.govtalk.gov.uk/taxation/CISrequest'>\n"
>               + "<dsig:Transform
Algorithm='http://www.w3.org/TR/1999/REC-
> xpath-19991116'>\n"
>               + "<dsig:XPath>\n"
>               + "count(ancestor-or-
> self::node()|/gt:GovTalkMessage/gt:Body)=count(ancestor-or-
> self::node())\n"
>               + " and count(self::ir:IRmark)=0 \n"
>               + " and count(../self::ir:IRmark)=0 \n"
>               + "</dsig:XPath>\n"
>               + "</dsig:Transform>\n"
>               + "<dsig:Transform
Algorithm='http://www.w3.org/TR/2001/REC-
> xml-c14n-20010315#'/>\n"
>               + "</dsig:Transforms>\n"
>               ;
> 
>               // Parse the transform details to create a document
>               DocumentBuilderFactory
> dbf=DocumentBuilderFactory.newInstance();
>               dbf.setNamespaceAware(true);
>               DocumentBuilder db=dbf.newDocumentBuilder();
>               Document doc=db.parse(new
> ByteArrayInputStream(transformStr.getBytes()));
> 
>               // Construct a Apache security Transforms object from
that
> document
>               Transforms transforms = new
> Transforms(doc.getDocumentElement(), null);
> 
>               // Now perform the transform on the input to get the
results.
>               XMLSignatureInput input = new XMLSignatureInput(data);
>               XMLSignatureInput result =
> transforms.performTransforms(input);
> 
>               // Uncomment this line to see transform output
>               //System.out.println(new String(result.getBytes()));
> 
>               // Second part is to run output via SHA1 digest
>               // This is done via the standard java.security API
>               MessageDigest md = MessageDigest.getInstance("SHA");
>               md.update(result.getBytes());
>               byte[] digest=md.digest();
> 
>               // And finally print a Base64 of the digest with
>               // The help of the BouncyCastle JCE library
>               System.out.println("IRmark: " + new
> String(Base64.encode(digest)));
>               return filename;
>    }
> }
> The error message is now:
> java.lang.NullPointerException
>       at
>
org.apache.xml.security.transforms.Transform.<init>(Transform.java:195)
>       at
>
org.apache.xml.security.transforms.Transforms.item(Transforms.java:329)
>       at
>
org.apache.xml.security.transforms.Transforms.performTransforms(Transfor
ms
> .java:256)
>       at IRMark.doStuff(IRMark.java:91)....etc
> 
> So I am still trying but things are a bit clearer...mmm.. what now?
> A+
> 
> 



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
The most significant release in over 10 years. Upgrade & see new features.
http://www.adobe.com/products/coldfusion?sdid=RVJR

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:275735
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to