tags:

views:

249

answers:

2

Hi everybody.

I'm working with gwtai to integrate a java applet into my gwt - project. Basic communication from my main application to the applet (such as invoking simple methods that return int or boolean values) works.

But the main reason why I need to integrate this applet is, that I need it to connect to another server and receive a answer and pass it to my gwt-application.

So there's one basic method in the applet:

public String SendAndReceive(String host, int sendPort, int receivePort, String query)

that connects to the server, receives an answer and returns this answer as a string.

When I now try to invoke this method like this:

applet.SendAndReceive("0.0.0.0", 9099, 2000, "show streams;");

I constantly run into following error (full error message at the end):

com.google.gwt.core.client.JavaScriptException: (String): Error calling method on NPObject! [plugin exception: java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)]

I couldn't find a solution (for gwtai is a quite uncommon topic), what I found out (and what the Exception let's one assume) is, that there's a security problem - maybe because I'm connecting to another server. I also read something about browser's Single Origin Policy, what would point in the same direction...up to now I have never worked with java applets.

So if someone has a solution or a hint I would be very thankful. If more code is helpful I can give.

Thanks,

Andy


the full error message:

21:03:49.864 [ERROR] [follovizergwt] Unable to load module entry point class follovizer.gwt.client.FolloVizerGWT (see associated exception for details) com.google.gwt.core.client.JavaScriptException: (String): Error calling method on NPObject! [plugin exception: java.security.AccessControlException: access denied (java.util.PropertyPermission * read,write)]. at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:195) at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:120) at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:507) at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:264) at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91) at follovizer.gwt.client.AnduINAppletImpl.SendAndReceive(AnduINAppletImpl.java) at follovizer.gwt.client.FolloVizerGWT.createLayout(FolloVizerGWT.java:92) at follovizer.gwt.client.FolloVizerGWT.onModuleLoad(FolloVizerGWT.java:40) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:369) at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:185) at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:380) at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:222) at java.lang.Thread.run(Thread.java:619)

A: 

Like other browser plugins, Java Applets have security restrictions. Notably, they can only make network connections to the host they came from. You cannot use applets to connect to arbitrary servers.

Communicating with other servers is a fairly common requirement, and there are several ways to get around it. Common solutions are Flash + Crossdomain.xml and JSONP. There are other solutions as well, just do a google search for all possible solutions.

sri
A: 

If your Java applet needs to make a cross-domain request then it will need to be signed. By default the Java sandbox doesn't allow applets to fetch pages that reside in a domain different than that from which the applet originated.

Bobby