Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
12.5k views
in Java FTP by
Does it work? I have this bit of code here which works fine in an application, but gives an runtime error when I try it in an applet.

import java.awt.*;
import java.applet.*;
import com.enterprisedt.net.ftp.*;

public class mUpload extends Applet
{
   private static String msg;
   
   public void init()
   {
      String server = new String("localhost");
      String user = new String("test");
      String passwd = new String("testtest");
      FTPClient ftp = null;
      msg = "Default";
      
      try
      {
         ftp = new FTPClient(server);
         ftp.login(user, passwd);
         ftp.put("C:\\me.rtf", "you.rtf");
      }
      catch (Exception e)
      {
         msg = e.toString();
      }
   }

   public void paint(Graphics g)
   {
      g.drawString(msg, 50, 60);
   }
}


Here's the error:
java.lang.ExceptionInInitializerError
        at com.enterprisedt.net.ftp.FTPClient.<init>(FTPClient.java:203)
        at com.enterprisedt.net.ftp.FTPClient.<init>(FTPClient.java:348)
        at com.enterprisedt.net.ftp.FTPClient.<init>(FTPClient.java:319)
        at mUpload.init(mUpload.java:28)
        at sun.applet.AppletPanel.run(AppletPanel.java:353)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission edtftp.log.level read)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
        at java.security.AccessController.checkPermission(AccessController.java:401)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
        at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1276)
        at java.lang.System.getProperty(System.java:612)
        at com.enterprisedt.util.debug.Logger.<clinit>(Logger.java:128)
        ... 6 more


Any ideas?

15 Answers

0 votes
by (162k points)
You don't have permission to read the property edtftp.log.level from the applet.

You need to add a permission to the policy file:

permission java.util.PropertyPermission "edtftp.log.level", "read"

See http://java.sun.com/j2se/1.4.2/docs/too ... ytool.html

for more info.

In the next release we'll modify the code so that if the property isn't accessible, a default is used and the exception is ignored.

Does it work? I have this bit of code here which works fine in an application, but gives an runtime error when I try it in an applet.

0 votes
by (162k points)
If you'd like to test a new version of edtFTPj in your applet please email us: support at enterprisedt dot com

In the next release we'll modify the code so that if the property isn't accessible, a default is used and the exception is ignored.
0 votes
by
Thanks for the response. I realized I needed a signed applet anyway. My code is working now though.
0 votes
by
Hello,

I'm having a problem with edtftpj in Java applets as well. I added the permissions to the policy file and I have a trusted java applet, but it still doesn't work. If I add the line with "ftp = new FTPClient("localhost");" to the code, then it says that my applet hasn't inited. If I take it out, it draws text to the screen as shown in the paint method.
Here is some of my code:

public void init() {
String str_file, str_dir, str_new_name;
int j;
Button test_but;
Panel pane;

try {
Frame parent = new Frame();
FileDialog fd = new FileDialog(parent, "Please choose a file:", FileDialog.LOAD);
FilenameFilter fnf = new EndsWithFilter(getParameter("FileFilter"));
FTPClient ftp;
drawGrid();

fd.setFilenameFilter(fnf);
fd.setFile(getParameter("FileFilter"));
fd.show();
str_errorcheck = "test1";
str_file_name = fd.getFile();
str_dir = fd.getDirectory();
str_errorcheck = "test2";
ftp = new FTPClient("localhost");
str_errorcheck = "test3";
/*
ftp.login("test", "testing");
str_errorcheck = "test4";
str_new_name = "temp" + getParameter("Login") + ".out";
ftp.put(str_file_name, str_new_name);
str_errorcheck = "test5";
*/
}
catch (Exception e) {
}
finally {
}
}

public void paint(Graphics g){
String url, str_string, string1;
Connection con;
Statement stmt;
ResultSet rs;
int j;
InputStream f0;

try {
getGraphics().drawString(str_errorcheck, 10, 80);
}
catch (Exception e) {
g.drawString(e.getMessage(), 0, 200);
}
finally {
}
}
0 votes
by (162k points)
When you catch the exception, use

ex.printStackTrace()

and look at what is shown in the Java console.

Hello,

I'm having a problem with edtftpj in Java applets as well. I added the permissions to the policy file and I have a trusted java applet, but it still doesn't work. If I add the line with "ftp = new FTPClient("localhost");" to the code, then it says that my applet hasn't inited. If I take it out, it draws text to the screen as shown in the paint method.
0 votes
by
The Stack Trace showed:

java.lang.NoClassDefFoundError: com/enterprisedt/net/ftp/FTPClient

at JFileDialogApplet.init(JFileDialogApplet.java:59)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

I should add that I have added as an import to the applet this line:

import com.enterprisedt.net.ftp.*;
0 votes
by (162k points)
There's your answer. You're not loading the jar file.

The Stack Trace showed:

java.lang.NoClassDefFoundError: com/enterprisedt/net/ftp/FTPClient

0 votes
by
Forgive me if I'm not experienced with including jar files, but I tried adding it to my applet. I have archive="JFileDialogApplet.jar,edtftpj.jar,junit.jar", and when I do I received the Stack Trace from the Java console as follows:

java.lang.ExceptionInInitializerError

at com.enterprisedt.net.ftp.FTPClient.<init>(FTPClient.java:203)

at com.enterprisedt.net.ftp.FTPClient.<init>(FTPClient.java:348)

at com.enterprisedt.net.ftp.FTPClient.<init>(FTPClient.java:319)

at JFileDialogApplet.init(JFileDialogApplet.java:59)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission edtftp.log.level 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 com.enterprisedt.util.debug.Logger.<clinit>(Logger.java:128)

... 6 more

I've tried setting
ARCHIVE = "JFileDialogApplet.jar","edtftpj.jar","junit.jar" as well, and it didn't work. I received the same Stack Trace as I reported yesterday. If you can shed some light as to how it should be included in an applet, that would be most appreciated.

Thanks
0 votes
by (162k points)
This is a different error - you need to give the applet this permission in the policy file, described in this thread.

In the next version we'll eliminate this requirement

Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission edtftp.log.level read)
0 votes
by (162k points)
We've got a preliminary release that gets around permissioning. Send an email to support at enterprisedt dot com requesting it if you'd like to test it out.

This is a different error - you need to give the applet this permission in the policy file, described in this thread.

In the next version we'll eliminate this requirement

Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission edtftp.log.level read)

Categories

...