Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7846511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:36:16+00:00 2026-06-02T17:36:16+00:00

In a class that processes a list of images over HTTP, one image throws

  • 0

In a class that processes a list of images over HTTP, one image throws a FNFE. The first assumption would be that the file doesn’t exist at the destination – but it does. The image is accessible in a browser and via another Java application (a command-line test case I wrote) running on the same machine?

Here’s the stack trace:

23-Apr-2012 17:23:57 uk.co.example.ExampleClass setImageUrl
WARNING: Exception setting image Url to http://images.example.co.uk/FPA-Midlands/MLO100316_01.jpg
java.io.FileNotFoundException: http://images.example.co.uk/FPA-Midlands/MLO100316_01.jpg
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1311)
    at uk.co.example.ExampleClass.importFileFromUrl(ExampleClass.java:460)

This is the orginating code:

private String importFileFromUrl(String imageUrl) throws IOException, CMException {
    InputStream is = null;
    String name = null;
    if (imageUrl != null && imageUrl.startsWith("http")) {
        URL url = new URL(imageUrl);
        URLConnection urlc = url.openConnection();
        is = urlc.getInputStream();
        name = url.getFile();
        name = name.substring(name.lastIndexOf('/') + 1);
    } else if (StringUtils.isNotBlank(imageUrl)){
        File f = new File (imageUrl);
        name = f.getName();
        is = new FileInputStream(f);
    }
    if (name != null && is != null) {
        importFile(name, is);
    }
    return name;
}

Because the sun.net.www.protocol.http.HttpURLConnection class appears in the stack, I was wondering whether this is a classloader issue? I haven’t explicitly imported that package – shouldn’t it be using a java.net equivalent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:36:19+00:00Added an answer on June 2, 2026 at 5:36 pm

    I added a try/catch block around the getInputStream() call:

    try {
        is = urlc.getInputStream();
    } catch(FileNotFoundException fnfe){
        is = ((HttpURLConnection) urlc).getErrorStream();
        LOG.log(Level.WARNING, "Exception streaming image: \n" + IOUtils.toString(is));
        throw fnfe;
    }
    

    From the log output, it’s now very clear that the server is responding with a 404 response code:

    25-Apr-2012 10:46:43 uk.co.example.ExampleClass importFileFromUrl
    WARNING: Exception streaming image: 
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    ~~~ snip ~~~
    <h2>HTTP Error 404 - File or directory not found.<br>Internet Information Services (IIS)</h2>
    ~~~ snip ~~~
    

    I wasn’t previously aware of the getErrorStream() method – I’d assumed any page response would have been covered by getInputStream(). The other area I found confusing / unintuitive is that the HttpURLConnection class throws the FNFE for a HTTP 404 response.

    For other errors, the response code is much more obvious:

    13-Apr-2012 15:40:43 uk.co.example.ExampleClass setImageUrl
    WARNING: Exception setting property image Url to http://images.example.co.uk/FPA-Midlands/MLO100316_01.jpg
    java.io.IOException: Server returned HTTP response code: 403 for URL: http://images.example.co.uk/FPA-Midlands/MLO100316_01.jpg
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
    

    Since making the above change, the issue hasn’t reoccurred. The only way I can explain it is that the browser must have been caching the image or that it was an intermittent problem. In any case, now the extra logging is available, any issue should be easy to resolve in the future.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a class that processes some data: class SomeClass { public: void
I have a class that is marked with DataContract attributes and I would like
If I have a class that contains a number of typedef 'd variables, like
Currently I have a class that looks like this: public class MyClass : IMyClass
I have a class that implements the IDisposable interface. I am using a webclient
I am writing a class that I know that needs a lock, because the
I have a basic class that derived subclasses inherit from, it carries the basic
I have a class that requires a specific method to be called before being
I have a class that maps incoming messages to matching readers based on the
I have a class that I am using below. And I am using this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.