使用Javascript函数调用的小程序调用:IcedTea插件的初始化错误

时间:2012-07-18 01:50:31

标签: java javascript security applet japplet

我试图从我开发的Java Signed Applet中调用Javascript函数。当我使用带有Sun Java插件的浏览器时,这非常好。我在Windows 7和Ubuntu 10.04上使用Firefox,Chrome和Internet Explorer(Windows)浏览器进行了测试。

当我尝试在任何带有Iced Tea插件的浏览器上运行相同的代码时,会通知以下错误:


  

net.sourceforge.jnlp.LaunchException:致命:初始化错误:无法初始化applet。       at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:735)       at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:676)       at net.sourceforge.jnlp.Launcher $ TgThread.run(Launcher.java:886)引起:java.lang.NullPointerException       at net.sourceforge.jnlp.runtime.JNLPClassLoader.getPermissions(JNLPClassLoader.java:915)       在java.security.SecureClassLoader.getProtectionDomain(SecureClassLoader.java:206)       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)       at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)       在java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)       at java.security.AccessController.doPrivileged(Native Method)       在java.net.URLClassLoader.findClass(URLClassLoader.java:354)       at net.sourceforge.jnlp.runtime.JNLPClassLoader.findClass(JNLPClassLoader.java:1499)       at net.sourceforge.jnlp.runtime.JNLPClassLoader.loadClassExt(JNLPClassLoader.java:1526)       at net.sourceforge.jnlp.runtime.JNLPClassLoader.loadClass(JNLPClassLoader.java:1341)       at java.lang.Class.getDeclaredMethods0(Native Method)       at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)       at java.lang.Class.getDeclaredMethod(Class.java:1952)       at java.awt.Component.isCoalesceEventsOverriden(Component.java:6190)       at java.awt.Component.access $ 500(Component.java:188)       at java.awt.Component $ 3.run(Component.java:6144)       at java.awt.Component $ 3.run(Component.java:6142)       at java.security.AccessController.doPrivileged(Native Method)       at java.awt.Component.checkCoalescing(Component.java:6141)       在java.awt.Component。(Component.java:6110)       在java.awt.Container。(Container.java:276)       在java.awt.Panel。(Panel.java:64)       在java.awt.Panel。(Panel.java:56)       在java.applet.Applet。(Applet.java:65)       在javax.swing.JApplet。(JApplet.java:130)       在br.ufrj.land.tangram.measures.NetworkMeasurerApplet。(NetworkMeasurerApplet.java:11)       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)       在java.lang.reflect.Constructor.newInstance(Constructor.java:525)       在java.lang.Class.newInstance0(Class.java:372)       在java.lang.Class.newInstance(Class.java:325)       at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:726)       ... 2更多引起:java.lang.NullPointerException       at net.sourceforge.jnlp.runtime.JNLPClassLoader.getPermissions(JNLPClassLoader.java:915)       在java.security.SecureClassLoader.getProtectionDomain(SecureClassLoader.java:206)       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)       at java.net.URLClassLoader.defineClass(URLClassLoader.java:447)       在java.net.URLClassLoader.access $ 100(URLClassLoader.java:71)       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:361)       在java.net.URLClassLoader $ 1.run(URLClassLoader.java:355)       at java.security.AccessController.doPrivileged(Native Method)       在java.net.URLClassLoader.findClass(URLClassLoader.java:354)       at net.sourceforge.jnlp.runtime.JNLPClassLoader.findClass(JNLPClassLoader.java:1499)       at net.sourceforge.jnlp.runtime.JNLPClassLoader.loadClassExt(JNLPClassLoader.java:1526)       at net.sourceforge.jnlp.runtime.JNLPClassLoader.loadClass(JNLPClassLoader.java:1341)       at java.lang.Class.getDeclaredMethods0(Native Method)       at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)       at java.lang.Class.getDeclaredMethod(Class.java:1952)       at java.awt.Component.isCoalesceEventsOverriden(Component.java:6190)       at java.awt.Component.access $ 500(Component.java:188)       at java.awt.Component $ 3.run(Component.java:6144)       at java.awt.Component $ 3.run(Component.java:6142)       at java.security.AccessController.doPrivileged(Native Method)       at java.awt.Component.checkCoalescing(Component.java:6141)       在java.awt.Component。(Component.java:6110)       在java.awt.Container。(Container.java:276)       在java.awt.Panel。(Panel.java:64)       在java.awt.Panel。(Panel.java:56)       在java.applet.Applet。(Applet.java:65)       在javax.swing.JApplet。(JApplet.java:130)       在br.ufrj.land.tangram.measures.NetworkMeasurerApplet。(NetworkMeasurerApplet.java:11)       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)       在java.lang.reflect.Constructor.newInstance(Constructor.java:525)       在java.lang.Class.newInstance0(Class.java:372)       在java.lang.Class.newInstance(Class.java:325)       at net.sourceforge.jnlp.Launcher.createApplet(Launcher.java:726)       at net.sourceforge.jnlp.Launcher.getApplet(Launcher.java:676)       at net.sourceforge.jnlp.Launcher $ TgThread.run(Launcher.java:886)java.lang.NullPointerException       在net.sourceforge.jnlp.NetxPanel.runLoader(NetxPanel.java:154)       在sun.applet.AppletPanel.run(AppletPanel.java:379)       at java.lang.Thread.run(Thread.java:722)java.lang.Thread.run(Thread.java:722)中sun.applet.AppletPanel.run(AppletPanel.java:429)的java.lang.NullPointerException


我尝试过的配置和事情:

  • 我在Iced Tea插件中使用的Linux风格是Ubuntu 12.04

  • 我尝试使用Sun JDK 6和7以及Open JDK 6和7编译我的代码,但两者都在浏览器上使用Iced Tea插件失败。

  • 我在Iced Tea版本6和版本7

  • 中尝试了我的代码
  • 我在Ubuntu

  • 上使用Firefox和Chrome浏览器尝试了我的代码

代码段:

HTML(在body标签内):

    <!-- JavaScript File That Contains My Javascript Function -->
    <script type="text/javascript" src="./my_javascript_file.js"></script>

    <!-- Applet That Will Call My Javascript Function -->
    <object height="1" width="1" id="MyApplet" name="MyApplet"
    java_version="1.5+" type="application/x-java-applet">
        <param name="code" value="foo.MyApplet" />
        <param name="archive" value="MyApplet.jar" />
        <param name="JVM_PARAM" value="-Djava.security.policy=applet.policy" />
        <param name="mayscript" value="true" />
        <param name="scriptable" value="true" />
        <param name="name" value="MyApplet" />
    </object>

我试图调用的Javascript方法(在my_javascript_file.js中):

window.performAppletCode = function (parameter_1) {
    //Function code
}

Java applet代码(相关部分)&#34; MyApplet.jar&#34;:

package foo;

import java.util.Arrays;
import javax.swing.JApplet;
import netscape.javascript.JSException;
import netscape.javascript.JSObject;

public class MyApplet extends JApplet {

    //Parameter that will be sent to Javascript function    
    public String parameter_1;    
    //JSObject that will be responsible for accessing javascript on my page 
    public JSObject window = null;
    private Thread myThread;
    private ImportantClass importantClassInstance;

    @Override
    public void init() {

    }

    @Override
    public void start() {
        if (this.window == null) {
            try {
                this.window = JSObject.getWindow(this);
                if (this.window == null){
                    System.out.println("Window is null");
                }
            }
            catch (JSException jse) {
                jse.printStackTrace();
            }
            fooStart();
        }
    }


    public void fooStart() {

            importantClassInstance = new ImportantClass();

            // MyThread Section
            myThread = new Thread(new Runnable() {
                @Override
                public void run() {

                    // Run latency test.
                    int[] fooArray = importantClassInstance.fooMethod();
                    parameter_1 = Arrays.toString(fooArray);
                    //Javascript function call
                    window.call("performAppletCode", new Object[] {parameter_1});
                }
            });
            myThread.start();
    }
}

我的applet使用jarsigner签名,证书包含在我的HTML目录中。

如果有人知道解决这个问题的可能线索,请告诉我。

谢谢, Guilherme的。

2 个答案:

答案 0 :(得分:1)

从JS调用时,applet失去信任。要解决此问题,请参阅AccessController.doPrivileged(...)this answer

答案 1 :(得分:0)

我想我找到了解决方案,但我不知道为什么会这样。事情就是这样:

当我从我的操作系统Ubuntu上的目录启动我的网页(使用applet和其他所有内容)时,我的Java控制台上会弹出这个疯狂的错误。但是当我从一个位于远程服务器上的目录(例如我家LAN中的另一台计算机)启动我的页面时,一切都很完美。所以,出于某种原因,我需要从一些远程服务器请求我自己的页面,一切正常。这只发生在我的问题上描述的上述情况。我将在网上搜索,试图找出这种情况发生的原因。