Security exceptions

I have an applet that needs to access images on another server. What will happen is that it has the address of the image that it needs to display, but then I run into the security issue where I can't access anything outside of the server that the applet is on. Is there a way that I can bypass this and access the image?

Thanks

[341 byte] By [jdub53a] at [2007-11-27 9:54:56]
# 1
A work-around is to place a program on the applet's host server which accesses the foreign server and places the information on itself so the applet can access it.See this tutorial for more information: http://java.sun.com/docs/books/tutorial/deployment/applet/server.html
ChuckBinga at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 2

> A work-around is to place a program on the applet's

> host server which accesses the foreign server and

> places the information on itself so the applet can

> access it.

>

> See this tutorial for more information:

>

> http://java.sun.com/docs/books/tutorial/deployment/app

> let/server.html

Here's a way to do it with cgi:

http://www.webdeveloper.com/java/java_jj_read_write.html

hunter9000a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 3

I'm still not sure what to do because when i try this code:

Image img;

MediaTracker tr;

public void paint(Graphics g) {

tr = new MediaTracker(this);

img = getImage(getCodeBase(), "ftp://.../images/1992/014/Img-1992-01-14-06-GMS-4-IR.jpg");

tr.addImage(img,0,1,1);

g.drawImage(img, 0, 0, this);

}

I get the access denied exception.

jdub53a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 4

Unless your server is actually called ... that's not going to work. If you give a full absolute path, it has to be valid. If you want to use a relative path, drop the protocol and use the correct number of dots.

"../images/1992/014/Img-1992-01-14-06-GMS-4-IR.jpg"

hunter9000a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 5
I was just shortening the path. I have the full path name in the code.
jdub53a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 6

> I was just shortening the path. I have the full path

> name in the code.

Ok, but in the future if you do something like that, be sure to tell us so we know that's not the real problem.

I just noticed that you were downloading a file from a server in your paint method. Don't do that. The paint method gets called many many times, and you can't control it. You only want to retrieve the image once, then paint it multiple times.

hunter9000a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 7
Any other advice as far as actually getting the picture from the server.
jdub53a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 8
> Any other advice as far as actually getting the> picture from the server.In what ways is the advice you've already been given inadequate?
hunter9000a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 9
> In what ways is the advice you've already been given> inadequate?It's not inadequate, I just can't get the darn thing to work and was wondering if anyone had any other ideas.
jdub53a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 10

Just a suggestion but put a picture at the root directory and name it something very simple. See if that works, then move it further in as well as adding to your name until you discover the problem. I'm not sure how long the actual path is but it seems to me there can be a problem if it reaches a certain length. Try that and hopefully it will give you a starting point.

Aknibbsa at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...
# 11

> > In what ways is the advice you've already been

> given

> > inadequate?

>

> It's not inadequate, I just can't get the darn thing

> to work and was wondering if anyone had any other

> ideas.

Applets don't let you access resources on servers except for the server where the applet was downloaded from. This is for security reasons. If you want to retrieve something from a different server, you need a process on the applet server to retrieve it for you, and return it to your applet.

Server A: has your applet.

Server B: has your images.

The applet can only access resources on A, so you need a process (a servlet, cgi script, small furry animal, etc) on A to fetch the image from B and give it to the applet.

hunter9000a at 2007-7-13 0:25:01 > top of Java-index,Java Essentials,Java Programming...