We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpIntegration › Problems with signed applet and DocumentBuilder
Page Index Toggle Pages: 1
Problems with signed applet and DocumentBuilder (Read 1986 times)
Problems with signed applet and DocumentBuilder
Jun 9th, 2009, 9:17am
 
Hi there

I have an app, which works fine standalone and in processing IDE, but I am trying to export and run it from the index.html.
The app (simplified code included), launches, requests that I trust it (because I signed it) and shows the image as
expected. However when I look in the Java console (as part of my browser) I see the following error messages:

trying dataPath
java.security.AccessControlException: access denied (java.io.FilePermission /null/data/HoCMP.xml read)
trying data/
java.security.AccessControlException: access denied (java.io.FilePermission /data/HoCMP.xml read)
trying absolute Path
java.security.AccessControlException: access denied (java.io.FilePermission /home/AntMan/Processing/Test/Simpler/Simpler/data/HoCMP.xml read)
Hello

Investigating I have found the lines this relates to (see below), which is basically the constructor of the object
which receives the location to the xml file which will be loaded ready to be parsed later on in the app:

   try
   {
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     DocumentBuilder db = dbf.newDocumentBuilder();
     myDom = db.parse(fileName);
   }
   catch (java.security.AccessControlException e)
   {
     System.out.println("Found an error!!!!!");
     System.err.println(e.toString());
   }

From what I can find on the internet this would only happen if the app is not signed, which it is?

I am running Fedora 9, viewing the index.html with Opera and the Java console included with Opera.

This is my code:

//Simple.class

PFont font8;
MyParser tp;
boolean failed = false;

void setup()
{
 fill(0);
 smooth();
 size(800,600);
}

void draw()
{
 rect(0,0,800,600);
 
 try
 {
   System.out.println("trying dataPath");
   tp = new MyParser(dataPath("")+"/HoCMP.xml");
 }
 catch (java.security.AccessControlException e)
 {
   System.out.println("dataPath() failed!");
   System.err.println(e.toString());
   failed = true;
 }
 try
 {
   System.out.println("trying data/");
   tp = new MyParser("data/HoCMP.xml");
 }
 catch (java.security.AccessControlException e)
 {
   System.out.println("data/ failed!");
   System.err.println(e.toString());
   failed = true;
 }
 try
 {
   System.out.println("trying absolute Path");
   tp = new MyParser("/home/AntMan/Processing/Test/Simpler/Simpler/data/HoCMP.xml");
 }
 catch (java.security.AccessControlException e)
 {
   System.out.println("Absolute path failed!");
   System.err.println(e.toString());
   failed = true;
 }

 finally
 {
   if (failed)
       System.out.println("Failure occured");
   else System.out.println("No failures!");
 }

 strokeWeight(0.25f);
 font8 = createFont("Serif",28);
 textFont(font8);
 fill(255);
 if (failed)
 {
  text("Some or all failed",370,300);
  System.out.println("Some or all failed");
 }
 else
 {
   text("Hello",370,300);
 System.out.println("Hello");
 }
 noLoop();

}



//MyParser.java

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;

public class MyParser
{
 private Document myDom;
TransformerFactory.newInstance();

 public MyParser(String fileName)
 {

   File xmlFile = new File(fileName);

   try
   {
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     DocumentBuilder db = dbf.newDocumentBuilder();
     myDom = db.parse(fileName);
   }
   catch (java.security.AccessControlException e)
   {
     System.out.println("Found an error!!!!!");
     System.err.println(e.toString());
   }
   catch (Exception e)
   {
     System.err.println(e.toString());
   }

 }

}
Re: Problems with signed applet and DocumentBuilder
Reply #1 - Jun 9th, 2009, 9:53am
 
Are there files where you try to read them?
Do they have world read access?
Re: Problems with signed applet and DocumentBuilder
Reply #2 - Jun 10th, 2009, 5:53am
 
Hey PhiLho

The file, HoCMP.xml does exist where I am trying to read it from. I own both the directory and the file and have full (chmod 777) access on both.

Have been playing with the code today and have noticed that even though the Java console report access denied the object has been instantiated and I can execute a VERY simple method within that object. However, if I go further and try to execute the next method it fails with null pointer because the variables within the object/class do not exist! This only happens when running as an applet, not when run from the IDE.

I am really confused. I have previously published applets that reference files (however these file have always been hosted).

I am running Processing 1.0.4, and the Java console in Opera is running java 1.6:

-- Opera - Java Console --

Java vendor: Sun Microsystems Inc.
Java version: 1.6.0

type 'h' for help

--
java.security.AccessControlException: access denied (java.io.FilePermission /home/AntMan/Processing/Test/Test/Clean/Clean/clean/temp/HoCMP.xml read)
Reports all is ok!
Hello


Here is my latest version of the code (remove comments around .List method to see problem):

//Clean.pde

PFont font8;
MyParser tp;

void setup()
{
 fill(0);
 smooth();
 size(800,600);
}

void draw()
{
 rect(0,0,800,600);

 tp = new MyParser("/home/AntMan/Processing/Test/Test/Clean/Clean/clean/temp/HoCMP.xml");

 if (tp.ok())
   System.out.println("Reports all is ok!");

 //Vector parties = tp.List("Party");
 //for (int i = 0; i < parties.size(); i++)
 //     System.out.println(parties.get(i));
     
 strokeWeight(0.25f);
 font8 = createFont("Serif",28);
 textFont(font8);
 fill(255);
 if (!tp.ok())
 {
   text("Some or all failed",370,300);
   System.out.println("Some or all failed");
 }
 else
 {
   text("All good?",370,300);
   System.out.println("Hello");
 }
 noLoop();

}  

//MyParser.pde

import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.*;
import org.xml.sax.SAXException;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.Vector;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import java.net.URL;

public class MyParser
{

   protected Document myDom;
   private Document previous = null;
   private Document root;
   
   private TransformerFactory tranFact = TransformerFactory.newInstance();
   
   
   public MyParser(String fileName)
   {
       
       //File xmlFile = new File(fileName);
       
       try
       {
           DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
           DocumentBuilder db = dbf.newDocumentBuilder();
           myDom = db.parse(fileName);
//            root = myDom;
       }
       catch (Exception e)
       {
           System.err.println(e.toString());
       }
                   
 }
 
 public boolean ok()
 {
     return true;
 }

   public Vector List(String tag)
   {
       Vector a = new Vector();
       NodeList t = myDom.getElementsByTagName(tag);
       if (t.getLength() > 0)
       {
           for (int i = 0; i < t.getLength(); i++)
           {
                  if (i+1 < t.getLength())
                  {
                       if (!(t.item(i).getTextContent().equals(t.item(i+1).getTextContent())))
                       {
                           a.add(t.item(i).getTextContent());
                       }
                  }
                  else
                  {
                      if (!(t.item(i).getTextContent().equals(t.item(i-1).getTextContent())))
                      {
                           a.add(t.item(i).getTextContent());
                       }    
                  }
                 
           }
           
       }
       
       return a;

   }

}

Page Index Toggle Pages: 1