9 Replies Latest reply: Jul 3, 2011 6:33 PM by 793415 RSS

    Applet connecting to own host

    872925
      I put this question here because I haven't found any thread on applet development
      I have an applet embedded in a web page which needs to connect to the host where it has been downloaded. The purpose is retrieving a field from a database, so it invokes a script in the host and it expects to have the data returned
      It used to work fine, which is what I would expected from what I have read in every site about applet restrictions: applets are allowed to connect to the host where they have been downloaded
      But since one day on, it started to fail. I get the following exception:
      java.security.AccessControlException: access denied (java.net.SocketPermission 94.127.188.135: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 sun.plugin2.applet.Applet2SecurityManager.checkConnect(Unknown Source)
      .
      .
      .
      By tracing the code, I have seen that the exception is yielded in the last call of the following thread:
      objurl = new URL(url);
      HttpURLConnection conn = (HttpURLConnection)objurl.openConnection();
      conn.setDoOutput(true);
      conn.setRequestMethod("POST");
      conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
      conn.setRequestProperty("Content-Length", contentLength);
      OutputStream os = conn.getOutputStream();
      If someone could give me any hint or redirect to the proper thread, it will be greatly appreciated
      Thanks in advance

      Edited by: user5796846 on 03-jul-2011 14:41
        • 1. Re: Applet connecting to own host
          793415
          user5796846 wrote:
          I put this question here because I haven't found any thread on applet development
          See the Java Applet Development & Signed Applets forums. You should find plenty.

          Decide on one and we can get a moderator to move the thread. Do not repost the thread.


          While on the subject of other information lying about the place, note that there is a sticky post on the top of every Java forum listing you seem to have missed. Please read it and then format codes & input/output according to the instructions.
          • 2. Re: Applet connecting to own host
            872925
            Sorry, I didn't understand what you meant by repost. I'm not a native english speaker
            Tell me how I should proceed in order to get advice for my problem
            • 3. Re: Applet connecting to own host
              872925
              By rereading carefully your post, I understand that I should choose one of the forums you have sugested, then I should let you know, and then you would move this thread to the one I had chosen.
              So I choose the Java Applet Development forum
              Is that right?
              • 4. Re: Applet connecting to own host
                793415
                user5796846 wrote:
                By rereading carefully your post,..
                +1
                .. I understand that I should choose one of the forums you have sugested, then I should let you know, and then you would move this thread to the one I had chosen.
                That understanding is correct.
                So I choose the Java Applet Development forum
                Is that right?
                Well, it's enough to get me started at sorting the 3 posts. I'll ask the mods. to delete the ones on Java Programming and Signed Applets.

                But there are 2 other things.
                <ol>
                <li>I directed you to read the sticky post and format your code. The code on both of the new threads has no code formatting, which suggests you did not understand my advice. When you don't understand something, please ask. (And be specific about what you do not understand).
                <li>You said initially that you could not find any similar threads. Since I directed you to two separate forums related to applets, I expect you to look through some posts & see if you can find the answer from the many similar posts over time.
                </ol>
                • 5. Re: Applet connecting to own host
                  Darryl Burke
                  Moderator action: Moved from Java Programming.

                  db
                  • 6. Re: Applet connecting to own host
                    872925
                    I've tried to find a thread about a problem similar to mine and I have found one, but it doesn't seem to come to a clear conclusion and solution
                    I think there is something to begin with: does an applet have the right to connect the same host from which it has been downloaded, or is there any situation, like an action started from javascript as the thead I mentioned suggests, in which the applet doesn't have this permission?
                    • 7. Re: Applet connecting to own host
                      793415
                      user5796846 wrote:
                      I've tried to find a thread about a problem similar to mine and I have found one,..
                      Where? (As in, what URL?)
                      ..but it doesn't seem to come to a clear conclusion and solution
                      I think there is something to begin with: does an applet have the right to connect the same host from which it has been downloaded, or is there any situation, like an action started from javascript as the thead I mentioned suggests, in which the applet doesn't have this permission?
                      Quite possibly it is the JS complicating matters. I thought that only affected trusted applets, but perhaps it applies to a sand-boxed applet as well.

                      Try using <tt>AccessController.doPrivileged(PrivilegedAction)</tt> to wrap the contentious code.
                      • 8. Re: Applet connecting to own host
                        872925
                        Thanks a lot, it worked!!!
                        • 9. Re: Applet connecting to own host
                          793415
                          user5796846 wrote:
                          Thanks a lot, it worked!!!
                          No worries. Glad you got it sorted.