• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

Java Applet that pull URL data

I want to pull up a web page on my site containing the java applet below that will pull a piece of data from another internet site and display it thur my applet.

but I get "access denied (java.net.SocketPermission www...some.....  connect,resolve)

I tested it using the appletviewer with a local profile and it worked fine (ppletviewer -J-Djava.security.policy=polfile URLReader1.htm )

Do I add logic to the applet to similuate the profile, do I put a profile file on mysite and/or how do i reference it. etc?

Remember my applet on my site page is pulling the url from another site.


import javax.swing.*;
import java.awt.*;
import java.net.*;
import java.io.*;
public class URLReader1 extends JApplet{
   String message;
   public void init() {
       try
       {
        URL httpurl = new URL("http://www.---someurl---.com");
        BufferedReader in = new BufferedReader(new InputStreamReader(httpurl.openStream()));

        StringBuffer result = new StringBuffer();
        StringBuffer dest = new StringBuffer();
        String tempxml;
        String startxml;
        String endxml;

        String inputLine;

        int     c;
        char    x;
        while ((c = in.read()) != -1)
           {
             x  = (char) c;
             //System.out.println(x);
             dest.append(x);
           }

        int isque = dest.toString().indexOf("</td>");
        isque=isque+01;
        tempxml = dest.toString();
        startxml = tempxml.substring(isque,isque+100);

        message=startxml;

        isque = startxml.toString().indexOf("<b>");
        isque=isque+03;
        tempxml = startxml.toString();
        endxml = tempxml.substring(isque,isque+5);

        in.close();
         }
        catch (Exception e)
           {
                  message=e.getMessage();
           }
    }
 public void paint(Graphics artist)
        {
          artist.drawString(message,20,330);
        }
}

<html>
<body>
<object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase= "http://java.sun.com/products/plugin/autodl/jinstall-1_4_2-windows-i586.cab#Version=1,4,2,0"
codetype="application/java" standby="Loading..."
height="600" width="600">
<param name="code" value="URLReader1.class">
</object>
</p>
</body>
</html>
0
MrBoiledCrawfish
Asked:
MrBoiledCrawfish
1 Solution
 
CEHJCommented:
You'll need to sign your applet if you want to distribute it. If it's just for you use you can edit the policy file. Either way, you'll need to add the permission to allow it to connect to another host
0
 
steve_bagnallCommented:
Hi MrBoiledCrawfish,

You can't access one domain from another, for security reasons.  I think this will be your problem.

Cheers,
Steve
0
 
MrBoiledCrawfishAuthor Commented:
So how do I get the applet on mypage on mysite to reference the policy file or is that a webserver setup (IIS)?
0
 
CEHJCommented:
No, the applet runs on the client machine - it has nothing to do with the site, apart from originating there. The sandbox is on the client machine, as is the policy file. If you have access to it, you can alter it. Otherwise you must sign the applet.

http://www.mindprod.com/jgloss/signedapplets.html
0
 
objectsCommented:
your users would need to update their policy file.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now