Riven
|
 |
«
Posted
2008-05-15 08:43:49 » |
|
I had an applet hosted on IP address xx.xx.xx.xx, and the applet could do a URL(" http://xx.xxx.xx.xx/resource").openConnection() and do I/O without problems. Now I have the applet hosted on domain www.abcdef.com which resolves to xx.xx.xx.xx, yet URL(" http://www.abcdef.com/resource").openConnection() works fine in MSIE, but fails in Firefox with: 1
| java.security.AccessControlException: access denied (java.net.SocketPermission xx.xx.xx.xx:80) |
I think Firefox turns the domain into its IP-address... then checks whether or not "xx.xx.xx.xx" textually equals " www.abcdef.com"  This is such a common case, that I'm wondering why I fail to get it right...
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Matzon
|
 |
«
Reply #1 - Posted
2008-05-15 09:03:04 » |
|
I fail to see what the browser has to do with the runtime ? are they using the same jre when the applet is running ? does the ip match for both www.abcdef.com and abcdef.com ?
|
|
|
|
Riven
|
 |
«
Reply #2 - Posted
2008-05-15 09:38:44 » |
|
Thanks for replying. I fail to see what the browser has to do with the runtime ? I fail to see it too... yet it only throws an Exception in Firefox (it's like Opera doesn't properly load *.jar.pack.gz while you'd say that's up to the JRE as well...) are they using the same jre when the applet is running ? Yup, same version, not JRE process ofcourse. Yes. At first it wasn't, so I changed the DNS and did a "ipconfig /flushdns" followed by "ping abcdef.com" to verify the (restarted) browser would see the right IP. Anyway, it resolved to xx.xx.xx.xx anyway, which is the right IP.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Games published by our own members! Check 'em out!
|
|
Riven
|
 |
«
Reply #3 - Posted
2008-05-15 10:26:19 » |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| System.out.println(applet.getCodeBase()); --> "http://www.abcdef.com/"
String action = applet.getCodeBase() + "resource/"; URL url = new URL(action); URLConnection con = url.openConnection();
con.setDoInput(true); con.setUseCaches(false);
if(postData != null) { con.setDoOutput(true); con.getOutputStream().write(postData); }
int len = con.getContentLength(); if(len == -1) { } else { } |
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Riven
|
 |
«
Reply #4 - Posted
2008-05-15 12:38:33 » |
|
Bugger...
I have 2 systems, both are identical: FireFox 2.0.0.14 Java Plug-in 1.6.0_05 Using JRE version 1.6.0_05 Java HotSpot(TM) Client VM
One works, one doesn't.
Write once, run anywhere, with varying results
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
|
|
Riven
|
 |
«
Reply #7 - Posted
2008-05-15 16:54:16 » |
|
So........... it works now, but it does not make sense. I simply put the given example code in Applet.start() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public void start() { try { URL url = new URL( "http://www.abcdef.com/" ); URLConnection conn = url.openConnection(); conn.setDoOutput( false ); BufferedReader br = new BufferedReader( new InputStreamReader( conn.getInputStream() ) ); String line; StringBuffer response = new StringBuffer(); while( (line = br.readLine()) != null ) response.append( line ); br.close(); } catch (Exception exc) { exc.printStackTrace(); } } |
After that, all my further URLConnections work....!And if I remove that (useless) code in Applet.start(), it breaks down instantly. Seems to me like some threading-issue. Appearantly you have to be in the thread that calls applet.start() to do the first URLConnection, after that it doesn't matter which Thread does the I/O.. 
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
timfoden
|
 |
«
Reply #8 - Posted
2008-05-18 13:55:25 » |
|
I've just started to see exactly the same problem. I've got an applet (Pipe Extreme, http://games.7sun.com/applet.php?game=50) which loads some resources from the host after the applet has started. It has worked fine for ages. Now though, it works OK the first time firefox loads it. But if I then clear the applet cache (x in console) and hit ctrl-F5 in firefox... the resources fail to load.... arrrrgggh!! Clear classloader cache ... completed. java.security.AccessControlException: access denied (java.net.SocketPermission 65.254.51.202: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 java.net.Socket.connect(Unknown Source) etc.. I noticed it as I'm doing some development at the moment to add an online highscore facility, so I'm testing the applet a lot in firefox. Bizarrely it seems to me to have only broken recently... Is it perhaps due to firefox updating to 2.0.0.14? Or maybe its the java runtime... I've tried jre versions 1.6.0_03 and 1.6.0_05? BTW, Riven, your workaround above doesn't work for me. Cheers, Tim.
|
|
|
|
Riven
|
 |
«
Reply #9 - Posted
2008-05-18 14:20:44 » |
|
Does this one work: http://oueb.org/AppletFireFoxLiveconnectBug.htmlclick the button IN the applet, that one works for me.. which is enough, as I don 't care about LiveConnect It still works after I press 'x' in the JavaConsole
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Games published by our own members! Check 'em out!
|
|
timfoden
|
 |
«
Reply #10 - Posted
2008-05-19 09:16:27 » |
|
.. did you try Ctrl-F5 before clicking the java button again? The sequence below replicates what I'm seeing in my applet: Click Java button. -- This works fine. Click JavaScript button. -- This produces an ACE, as expected. 'x' in Java console window. Ctrl-F5 in Firefox to reload page. Click Java button. -- This now produces an ACE. Close and restart Firefox completely to get it to work again. That this started happening with my applet late yesterday afternoon is a complete mystery to me, as I had been doing the 'x', Ctrl-F5 sequence all weekend to reload my applet, and it worked fine (loading resources and high scores from the server). Just as I got it to the state where I was doing final testing to release it, it started to fail every time (due to this bug of course). What a pain.  I think I'm going to have to start using IE to develop with until this bug is fixed. doh! Cheers, Tim.
|
|
|
|
Riven
|
 |
«
Reply #11 - Posted
2008-05-19 13:20:53 » |
|
Yes, it throws an ACE with that exact sequence.
But *without* that LiveConnect button, it works, even with 'x' and CTRL+F5
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
timfoden
|
 |
«
Reply #12 - Posted
2008-05-19 15:44:41 » |
|
Yes, it throws an ACE with that exact sequence.
But *without* that LiveConnect button, it works, even with 'x' and CTRL+F5
True. Up till now I've been using LiveConnect in my applet to save the "local" high scores (via a cookie). This is the only LiveConnect code used. I guess that once I've finally got server side high scores working I could just remove the local ones. It's a shame though, as I'd like to keep them. I don't suppose anyone knows some way, other than using LiveConnect with Cookies, of persisting data from an unsigned applet? Cheers, Tim.
|
|
|
|
Riven
|
 |
«
Reply #13 - Posted
2008-05-19 16:05:46 » |
|
Applet => website 1 2 3 4 5 6 7 8 9 10 11 12
| public void executeScript(String js) { try { String path = "javascript:eval(hexToStr('" + strToHex(js) + "'));"; this.getAppletContext().showDocument(new URL(path), "_self"); } catch (Exception exc) { } } |
Website => Applet - Website: write into Applet <param name="myProperty" value=""> using Javascript / DOM - Applet: polling applet.getParameter("myProperty") every N ms
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Riven
|
 |
«
Reply #14 - Posted
2008-05-19 16:07:56 » |
|
Just to clearify, you need to 'encode' and 'decode' the javascript you want to execute in the browser because is won't probably be a valid URL. Here is some incredibly ineffictient (who cares) javascript for strToHex() and hexToStr() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| function strToHex(str) { var hex = ""; for(var i=0; i<str.length; i++) hex += itoh(str.charCodeAt(i)); return hex; }
function hexToStr(hex) { var str = ""; for(var i=0; i<hex.length; i+=2) str += String.fromCharCode(htoi(hex.substring(i, i+2))); return str; }
function itoh_(i) { return "0123456789ABCDEF".charAt(i); }
function itoh(i) { var hi = (i >> 4) & 15; var lo = (i >> 0) & 15; return itoh_(hi)+""+itoh_(lo); }
function htoi_(h) { return "0123456789ABCDEF".indexOf(h); }
function htoi(h) { var hi = (htoi_(h.charAt(0)) & 15) << 4; var lo = (htoi_(h.charAt(1)) & 15) << 0; return hi+lo; } |
Java versions: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| private static char[] hexTable = "0123456789ABCDEF".toCharArray();
public static final String strToHex(String str) { try { return rawToHex(str.getBytes("utf8")); } catch(UnsupportedEncodingException exc) { return null; } }
public static final String hexToStr(String hex) { try { return new String(hexToRaw(hex), "utf8"); } catch(UnsupportedEncodingException exc) { return null; } }
public static final String rawToHex(byte[] raw) { char[] digits = new char[raw.length * 2]; for (int k = 0; k < raw.length; k++) for (int i = 0; i < 2; i++) digits[(k << 1) + (1 - i)] = hexTable[(hex[k] >>> (i << 2)) & 0x0F]; return new String(digits); }
public static final byte[] hexToRaw(String hex) { byte[] raw = new byte[hex.length() / 2]; for (int i = 0; i < raw.length; i++) { char c0 = hex.charAt((i << 1) + 0); char c1 = hex.charAt((i << 1) + 1);
int val = (c0 - (c0 < 'A' ? '0' : 'A')) << 4; raw[i] = (byte) (val | (c1 - (c1 < 'A' ? '0' : 'A'))); } return raw; } |
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
Riven
|
 |
«
Reply #15 - Posted
2008-05-19 16:21:57 » |
|
- see previous page
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
timfoden
|
 |
«
Reply #16 - Posted
2008-05-20 07:11:33 » |
|
Applet => website ... Website => Applet ...
That's just great, thanks Riven. I'll give it a try tonight. Cheers, Tim.
|
|
|
|
Riven
|
 |
«
Reply #17 - Posted
2008-05-20 07:52:40 » |
|
Keep in mind I 'manually wrote' (..) that code in the reply (not a copy/paste). I don't have the sourcecode here right now, only the bytecode  The concept works though.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
DzzD
|
 |
«
Reply #18 - Posted
2008-05-21 09:29:36 » |
|
So........... it works now, but it does not make sense. I simply put the given example code in Applet.start() 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| public void start() { try { URL url = new URL( "http://www.abcdef.com/" ); URLConnection conn = url.openConnection(); conn.setDoOutput( false ); BufferedReader br = new BufferedReader( new InputStreamReader( conn.getInputStream() ) ); String line; StringBuffer response = new StringBuffer(); while( (line = br.readLine()) != null ) response.append( line ); br.close(); } catch (Exception exc) { exc.printStackTrace(); } } |
After that, all my further URLConnections work....!And if I remove that (useless) code in Applet.start(), it breaks down instantly. Seems to me like some threading-issue. Appearantly you have to be in the thread that calls applet.start() to do the first URLConnection, after that it doesn't matter which Thread does the I/O..  cool, excellent that you find a workaround to this FF bug , great!
|
|
|
|
timfoden
|
 |
«
Reply #19 - Posted
2008-06-09 16:03:17 » |
|
1 2 3 4 5 6 7 8 9
| public void executeScript(String js) { try { String path = "javascript:eval(hexToStr('" + strToHex(js) + "'));"; this.getAppletContext().showDocument(new URL(path), "_self"); } ... } |
I did finally get around to trying this... and it does run the javascript code as advertised. However, it also changes the document  Is there some trick to getting the browser to run the javascript, but not change the document? Or should the javascript just change the document back again... but then I guess the applet would re-start? Or maybe I need to run it in a (non-visible) frame (but I'd prefer not to use frames at all)? Hmmm, tricky. Cheers, Tim.
|
|
|
|
Riven
|
 |
«
Reply #20 - Posted
2008-06-09 18:40:06 » |
|
You can do this: Have an <iframe src="myEval.html" name="myEval">, with myEval.html like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <html> <head> <script language="javascript"> function runEval() { var ownURL = window.location.href; var doEvalHex = ownURL.substring(ownURL.indexOf('?doEvalHex=')+'?doEvalHex='.length); var doEvalStr = hexToStr(doEvalHex);
with(window.parent) { eval(doEvalStr); } } </script> </head> <body onLoad="runEval();"> </body> <html> |
Run with: 1 2
| String js = "var anythingGoes = function() { setTimeout(function(){ window.alert("function in function");}, 1000)}"; this.getAppletContext().showDocument(new URL("./myEval.html?doEvalHex="+strToHex(js)), "myEval"); |
I have something like that (as a workaround in Opera, as it doesn't understand the "javascript:..."-protocol). It works, but the provided code is untested.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
timfoden
|
 |
«
Reply #21 - Posted
2008-06-11 11:15:54 » |
|
You can do this:
Have an <iframe src="myEval.html" name="myEval">, with myEval.html like this:
Ah, IFRAME... I handn't realised that such a thing existed. I guess my aversion to FRAMEs doesn't really apply to an IFRAME. Cool, I'll give it a try. I have something like that (as a workaround in Opera, as it doesn't understand the "javascript:..."-protocol). It works, but the provided code is untested.
No probs about untested code. Thanks for your help. Cheers, Tim.
|
|
|
|
DzzD
|
 |
«
Reply #22 - Posted
2008-06-19 14:22:23 » |
|
the "javascript:" protocol, what a good idea Riven ! so good than I decide to make a class for that  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
import java.applet.*; import java.net.URLEncoder; import java.net.URL; import java.net.MalformedURLException;
public class JavaScript { private Applet a; public JavaScript(Applet a) { this.a=a; } public void exec(String js) { String jsURL="javascript:eval(unescape(\""+URLEncoder.encode(js.replace(" ","%20"))+"\"))"; System.out.println(jsURL); try { this.a.getAppletContext().showDocument(new URL(jsURL),"_self"); } catch(MalformedURLException mue) { mue.printStackTrace(); } } }
|
Usage in an Applet : 1 2
| JavaScript js=new JavaScript(this); js.exec("alert('javascript!')"); |
|
|
|
|
Riven
|
 |
«
Reply #23 - Posted
2008-06-19 21:10:57 » |
|
Beware it doesn't work in Opera.
Soon I'll publish all code relevant to this 'issue'.
There are so many problems with this trivial stuff that there should be a centralized solution.
|
Hi, appreciate more people! Σ ♥ = ¾ Learn how to award medals... and work your way up the social rankings!
|
|
|
|