HTTPを介して画像のリストを処理するクラスでは、1つの画像がFNFEをスローします。最初の仮定は、ファイルが宛先に存在しないということですが、存在します。イメージはブラウザでアクセスでき、同じマシンで実行されている別のJavaアプリケーション(私が作成したコマンドラインテストケース)を介してアクセスできますか?
スタックトレースは次のとおりです。
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)
これは元のコードです:
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;
}
クラスがスタックに表示されるため、sun.net.www.protocol.http.HttpURLConnection
これがクラスローダーの問題であるかどうか疑問に思いました。java.net
そのパッケージを明示的にインポートしていません-同等のものを使用するべきではありませんか?