-1

NOTE:I apologize if this is a stupid question, I am new to web server interaction, and I have yet to find any useful information online to help with this issue.

I am trying to install an image off of a web server using the following code:

public static void main(String args[]){
    try {
        BufferedImage image = ImageIO.read(new URL("http://medialink.atspace.cc/uploads/murphy/apple.jpg"));
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

This code gives the following error:

javax.imageio.IIOException: Can't get input stream from URL!
at javax.imageio.ImageIO.read(Unknown Source)
at MediaLinkMain.main(MediaLinkMain.java:24)
Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://medialink.atspace.cc/uploads/murphy/apple.jpg
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
... 2 more

The image is on a subdomain I have with atspace.com. The same code with for example to google logo image at address: https://www.google.com/images/srpr/logo11w.png

By default atspace had a setting called "directory protection" under their hosting settings. Prior to disabling that I was strangely not able to view the image at it's address(http://medialink.atspace.cc/uploads/murphy/apple.jpg), unless i added it to a webpage, and right clicked + pressed view image.

You may also want to note using the following code:

URL url = new URL(addr + "/list.dat");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
for(String line = reader.readLine(); line != null; line=reader.readLine()){
    //Use data here
}

Runs without issue for a file in the exact same directory as the image.

csga5000
  • 4,062
  • 4
  • 39
  • 52

2 Answers2

0

The server returns a response code 500. This means there is a server error. You can see that also when you try to open that URL in a browser.

The problem must be tackled on the server side.

Henry
  • 42,982
  • 7
  • 68
  • 84
  • Yes, a 500 response code means an internal error. And I agree, the problem is on the server. But how do I fix it/what is the problem on the server side..? – csga5000 Jan 26 '14 at 09:02
  • 1
    @csga5000 thats impossible to answer without better knowledge of the server and the software running there. – Henry Jan 26 '14 at 09:18
  • That's probable, I was hoping perhaps it was a general setting common on web servers, and someone would know what it was. Anyway, thanks for your contribution. – csga5000 Jan 26 '14 at 17:41
0

As @Henry says:

The problem must be tackled on the server side.

The server's HTTP 500 error message says:

Premature end of script headers: f403.php

Based on an educated guess, I'd say that this is not the real problem, but that you'll initially get an HTTP 403 "Forbidden" return status, but the error handler for 403 status (f403.php) is broken, thus resulting in the 500 error.

If the real problem is indeed an HTTP 403 status, you probably didn't set the file permissions for your image correctly.

Not sure if the error handlers are yours, or your ISP's, in the latter case you should probably tell them about the problem.

PS: The server's 500 status page also lists the most common cases for the error, you should probably read them too.

Harald K
  • 26,314
  • 7
  • 65
  • 111
  • I did read the probably causes, it talked about scripting, and no scripting was involved on my part. Also, my image file has 644 file permissions, which says that it can be read by anyone, and written to only by the owner. I've tried all sorts of file persmisions however, including 777 – csga5000 Feb 02 '14 at 22:42