class“Controller”与同一包中其他类的信任级别不匹配

时间:2014-01-09 14:22:12

标签: java eclipse applet

我已经创建了一个java traceroute applet,它在eclipse appletviewer中运行正常,但是当我在浏览器中执行它时,我收到以下错误:

actionPerformed()中的

错误:java.lang.SecurityException:类“Controller”与同一包中其他类的信任级别不匹配

我已经签署了我的jar文件并在我的清单文件中尝试了很多更改,但它仍然无法正常工作。我使用的是java jdk1.7.0_45。

控制器类:

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.util.ArrayList;

public class Controller {

    public Controller(GUI gui) {
        this.gui = gui;
    }

    private final String os = System.getProperty("os.name");
    private GUI gui;

    public void displayHopsOnConsole(final InputStream stream) {
        gui.clearConsole();
        Thread thread = new Thread() {
            public void run() {
                BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); //create BufferedReader to read the inputstream easily
                ArrayList <String> hops = new ArrayList <String> ();
                ArrayList <String> hopCoordinates = new ArrayList <String> ();
                String hop;
                String IP;
                int i = 0;
                try {
                    while ((hop = reader.readLine()) != null) { // while the input is not NULL, read every line separately
                        if (i >= 5 && hop.length() > 25) {
                            IP = getIpFromHop(hop); //Filter the hop and get the ip back
                            hops.add(IP); //put this ip in a arraylist
                            hopCoordinates.add(new Post(IP).getResponse());
                        }
                        gui.setConsoleOutput(hop);
                        System.out.println(hop);
                        i++;

                    }
                    reader.close(); //close buffer because finished
                    gui.setConsoleOutput("\n");
                    int c=2;
                    for(String str:hopCoordinates){
                         gui.setConsoleOutput(c + ": " + str);
                         c++;
                    }

                } 
                catch (Exception ex) {
                    System.out.println("Error in displayHopsOnConsole" + ex);
                }
            }
        };
        thread.start(); //start thread  
    }

    public void traceRoute(InetAddress address) {
        try {
            Process traceRt;
            if (os.contains("Win") || os.contains("win")) {
                traceRt = Runtime.getRuntime().exec("tracert " + address.getHostAddress());
            } 
            else {
                traceRt = Runtime.getRuntime().exec("traceroute " + address.getHostAddress());
            }
            displayHopsOnConsole(traceRt.getInputStream());
        } 
        catch (Exception ex) {
            System.out.println("error while performing trace route command, see traceRoute() " + ex);
        }
    }

    public String getIpFromHop(String routeLine) {
        String resultString = routeLine.substring(31, routeLine.length() - 1);
        if (resultString.contains("[")) {
            String[] splitString = resultString.split("\\[");
            resultString = splitString[1].substring(0, splitString[1].length() - 1);
            return resultString;
        } 
        else {
            if (!resultString.contains("-")) {
                return resultString.replaceAll("\\s", "");
            } 
            else {
                return "Timeout!";
            }
        }
    }
}

GUI CLASS ACTION FORFORMED METHOD:

public void actionPerformed(ActionEvent e) {
        if(e.getSource()==submitButton) {
            try{
                new Controller(this).traceRoute(InetAddress.getByName(targetField.getText())); //call traceRoute method to start traceroute on given target address 
            }
            catch (Exception ex) {
                System.out.println("error in actionPerformed(): " + ex);
            }
        }
    }

我的宣言文件:

  

清单 - 版本:1.0代码库:*权限:所有权限   Application-Library-Allowable-Codebase:* Caller-Allowable-Codebase:*   应用程序名称:GUI

0 个答案:

没有答案