Results 1 to 12 of 12
  1. #1
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default [SOLVED] Server file loading

    I have developed a java applet which loads a file from its own directory. This works brilliantly when ran from eclipse.

    I have moved the applet to my server along with the files and i keep getting:

    Java Code:
    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    	at java.lang.System.getProperty(Unknown Source)
    	at weka.core.converters.AbstractFileLoader.<init>(AbstractFileLoader.java:46)
    	at weka.core.converters.ArffLoader.<init>(ArffLoader.java:56)
    	at weka.core.converters.ConverterUtils$DataSource.<init>(ConverterUtils.java:127)
    	at Data.dataset.loadfile(dataset.java:120)
    I have read the information about permissions here duckware.com/applets/reference.html#securitymodel

    I have 4 folders containing class files on my server siu05dr.webs.sse.reading.ac.uk

    The applet is within one of these folders (main). I have moved the files (cpu.arff, iris.arff etc.) i would like opening to this same folder on the server and am accessing using this command:

    Java Code:
    new URL(cpu.arff)
    It is then opened and parsed using the WEKA libraries ARFF parsers.

    I have also tried

    Java Code:
    new URL(./cpu.arff)
    but still get security issues.

    What am i doing wrong? am i correct in thinking that you can load files from where the applet is located?

    Any help would be really great
    SIAS

  2. #2
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    Quote Originally Posted by SIAS87 View Post
    Java Code:
    new URL(cpu.arff)
    Java Code:
    new URL(./cpu.arff)
    Opps should be

    Java Code:
    new File(cpu.arff)
    Java Code:
    new File(./cpu.arff)

  3. #3
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you try to use file operations in an applet it will try to access files on the client machine - which is not allowed.
    To access files from the server, either put them in the jar and use getResourceAsStream() or write a server you connect to with some kind of socket.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  4. #4
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    Thanks for the reply, that explains alot.
    The weka library i am using only supports reading files or URLs. Is there any other way of getting around this?
    If I used getResourceAsStream() would it be treated as a File or another data object?
    If i digitally signed my applet would the method i am currently using work?
    Thanks for your help so far
    Dan

  5. #5
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    The method returns an InputStream. These abstract away whether the source is a File, Socket or whatever. There's a similar method getResource() that returns a URL object.
    Alternatively use URLs that point to your server. That means using full paths like http://www.example.org/files/cpu.arff
    Using the File API will work only if the files you want to access are already on the client computer.
    Last edited by OrangeDog; 04-18-2009 at 01:36 AM.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  6. #6
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    I have tried loading an URL using the full path but received the same security error.
    I will try the resource method.
    Thank you

  7. #7
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If it's another error thrown by weka.core.converters.AbstractFileLoader.<init> then it may be the case that the library isn't ever going to work in an applet. Look for a method that takes some kind of stream to load data from, or complain to the developers to put one in (or become a developer and put it in yourself).
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  8. #8
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    Ok, i have found another project using weka to open ARFF files from a URL. (hakank.org/weka simple weka program 1)

    I looked at his code and have replicated what he did. This is the solution he is using:
    Java Code:
    	BufferedReader reader = null;
            URL url = new URL(filename);
            reader = new BufferedReader (new InputStreamReader( (InputStream) url.getContent() ));
    I am now getting this error when run:

    Java Code:
    java.security.AccessControlException: access denied (java.net.SocketPermission siu05dr.webs.sse.reading.ac.uk:80 connect,resolve)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkConnect(Unknown Source)
    	at sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
    	at sun.net.ww.http.HttpClient.openServer(Unknown Source)
    	at sun.net.ww.http.HttpClient.<init>(Unknown Source)
    	at sun.net.ww.http.HttpClient.New(Unknown Source)
    	at sun.net.ww.http.HttpClient.New(Unknown Source)
    	at sun.net.ww.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
    	at sun.net.ww.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
    	at sun.net.ww.protocol.http.HttpURLConnection.connect(Unknown Source)
    	at sun.net.ww.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    	at java.net.URLConnection.getContent(Unknown Source)
    	at java.net.URL.getContent(Unknown Source)
    	at Data.dataset.loadfile(dataset.java:126)
    	at Main.applet$10.mouseClicked(applet.java:401)
    	at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Any ideas?
    Thanks so much for your help so far

    p.s. had to change www -> ww due to the forum restrictions on posting links
    Dan

  9. #9
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Yes, an untrusted applet can only open connections to the server from which it was downloaded.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  10. #10
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    I uploaded the applet to the server containing the files.
    I now get this error:

    Java Code:
    java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    	at java.lang.System.getProperty(Unknown Source)
    	at weka.core.converters.AbstractFileLoader.<init>(AbstractFileLoader.java:46)
    	at weka.core.converters.ArffLoader.<init>(ArffLoader.java:56)
    	at weka.core.converters.ConverterUtils$DataSource.<init>(ConverterUtils.java:127)
    	at Data.dataset.loadfile(dataset.java:120)
    	at Main.applet$10.mouseClicked(applet.java:402)
    	at java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    Thanks for all your help

  11. #11
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Now your applet is trying to read the users' home directory. Either you got your paths wrong or that library really wasn't designed to be used in an applet, the naughty thing.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  12. #12
    SIAS87 is offline Member
    Join Date
    Mar 2009
    Posts
    8
    Rep Power
    0

    Default

    Thanks for all your help orangedog.
    I finally got it working by loading the ARFF files into the JAR, like u suggested.
    Thanks you have been a life saver
    Dan

Similar Threads

  1. loading .properties file dynamically
    By nanaji in forum Advanced Java
    Replies: 3
    Last Post: 03-17-2009, 04:40 AM
  2. loading a text file
    By nick2price in forum New To Java
    Replies: 2
    Last Post: 12-24-2008, 01:46 AM
  3. error while loading the image from the server
    By testtest in forum CLDC and MIDP
    Replies: 1
    Last Post: 09-23-2008, 06:16 AM
  4. Loading of JSP file failed
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-06-2007, 02:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •