Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 25th, 2007, 2:51 PM   #1
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
Question Small Applet Problem

I'm trying to create an applet which retrieves information from a foreign url. I'm not entirely sure that this is even allowable however, because my code generates the following exception:
exception: java.lang.RuntimeException: java.security.AccessControlException: access denied (java.net.SocketPermission cache.pando.com:80 connect,resolve).
And here's the code for the applet:
import java.awt.*;
import javax.swing.*;

import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class URLGet extends JApplet
{
    private String input;

    public void start()
    {
        try
        {
            URL u = new URL("http://cache.pando.com/soapservices/SendToWeb?action=info&format=json&id=5AEDE982393976A10050F2EC7C20C3C5EFDE0BBB&key=C51E9F2767B6747A9C9841AF7EEB9CC0E967D5B37CEC05B8C9DF310A03958AD2");
            URLConnection connection = u.openConnection();
            
            HttpURLConnection httpConnection = (HttpURLConnection)connection;
            int code = httpConnection.getResponseCode();
            
            if(code != HttpURLConnection.HTTP_OK)
            {
                throw new MalformedURLException("HTTP_OK failed");
            }
            
            InputStream in = connection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        
            boolean done = false;
            input = "";
            while(!done)
            {
                input += reader.readLine();
                if(input == null) done = true;
            }
        }
        catch(MalformedURLException u)
        {
            input = "MalformedURLException";
        }
        catch(IOException e)
        {
            input = "IOException";
        }
    }

    public void paint(Graphics g)
    {
        g.setColor(Color.white);
        g.fillRect(0, 0, 200, 100);
        g.setColor(Color.black);
        g.drawString(input, 20, 20);
        
    }
}
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Old Jun 25th, 2007, 6:08 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,038
Rep Power: 5 lectricpharaoh will become famous soon enough
There was a similar "can't do this in Java" thread a short time back, and andro posted a nice link in response. See post #5 in this thread.

The short answer: you can't open a socket connection to a foreign site from the applet. If you're able to implement server-side code, you can always have the server do it (and if possible, cache results to reduce overhead).

[edit] Regarding your other post, it seems server-side code isn't viable, either. Hate to say it, but it sounds like you're screwed. Have you considered switching your web hosting? [/edit]
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Jun 25th, 2007, 9:08 PM   #3
grimpirate
King of Portal
 
grimpirate's Avatar
 
Join Date: Sep 2005
Posts: 431
Rep Power: 4 grimpirate is on a distinguished road
Send a message via Yahoo to grimpirate
yeah seems to be that switching web hosting is the only way to go. I was thinking Flash to work with XML, but flash has the same limitation. It can only read XML files on the domain. I may just have to get users to paste the actual content of the URL as opposed to trying to get my script to do all the work for them. I could use the javascript api, but I don't like to use javascript at all since I usually surf with javascript disabled.
__________________
Lo, there do I see my father. 'Lo, there do I see My mother, and my sisters, and my brothers. 'Lo, there do I see The line of my people... Back to the beginning. 'Lo, they do call to me. They bid me take my place among them. In the halls of Valhalla... Where the brave... May live... ...forever.. GrimBB | Mimesis
grimpirate is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Applet / Button problem. TCStyle Java 1 Apr 29th, 2007 11:10 AM
simple java applet problem anant_tickoo Java 2 Aug 9th, 2006 4:13 AM
Problem with GetOpenFileName buffer too small. Chesso C++ 8 Mar 11th, 2006 9:47 AM
Java - Searching a table in a database - small problem. Vengeance Java 4 Apr 28th, 2005 2:53 PM
problem with JDBC for talking to Microsoft Access database using a Java Applet captainK Java 4 Mar 20th, 2005 11:01 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:48 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC