![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
King of Portal
|
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). 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 |
|
|
|
|
|
#2 |
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,033
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#3 |
|
King of Portal
|
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |