Submitted On 21-APR-1999
l061917
When the file ends with those extension, what is the difference in terms of
output returned by getErrorStream() and getInputStream() ?
Both of them will return the error page returned by the server, won't they ?
Submitted On 06-AUG-1999
hartlands
FileNotFoundException should never be thrown.
It is worse than meaning less in most cases and there is no benefit to be
gained; infact it just adds a level of complexity/processing.
Each app should be able to access the data that was returned from the server
and make its OWN decision on what to do with it.
Submitted On 27-AUG-1999
jlubliner
First of all, the implementation of getErrorStream() in Solaris_JDK_1.2.1_02 is
"return null", so don't even call that a workaround. Secondly,
getInputStream should RETURN THE INPUT STREAM, no matter what the HTTP response
is, and no matter what the file extension is. Why is HttpURLConnection
deciding whether or not we should get to see the document content? If there is
no stream, return null. That's it. There is no reason for an exception here.
Submitted On 06-APR-2000
shecter
Has anyone found that on Linux 1.2.2, when there's been a
404 error, the input stream crashes midway or at EOF with a
SocketException? I´ve got a workaround underway...
Submitted On 12-JUL-2000
euxx
JDK 1.3 GA still have this bug.
Submitted On 14-AUG-2000
FuckingA
2 YEARS. Hey Sun you gonna fix this one or what? Throw
away useful info, throw an unrelated exception: That
approaching a Microsoft level of incompetence.
Submitted On 04-OCT-2000
mark.robinson
> Will fix in Merlin.
i sure do hope so - this BUG (denied by some) has been
around so long that its has at least 10 bug reports against
it! my particular complaint is that it obscures errors from
servlet managers (which are typically in the 5xx range) even
though there is valid error text available on the
inputStream.
Submitted On 16-OCT-2000
olivaux
this error is not in "Top 25 Bugs" but certainly in "Top 25
oldest Bugs" .....
argggh
Submitted On 08-JAN-2001
ghamann1
Trying to retrieve XML documents from a servlet with a .xml
extension. So far a partial work-around I have found (JDK
1.3) is that I can get all the header information using
interations of the getHeaderField method. The error content
cannot be retrieved, even though it is there. Immediately
retrying the request in the exception handling code does
not provide anything new.
If the error is a result of a basic authentication error
(401), I can get the response by appending a ".txt" onto
the end of the URL and retrying a request for the non-
existent document. Ugly.
Submitted On 15-MAR-2001
roryward
Pretty much along the same lines as ghamann1, except it works more broadly. I also came across the fact
that if you use the HttpURLConnection getHeaderFieldKey or getHeaderField methods, then the
FileNotFoundException is not thrown and you can successfully read the response code using
getResponseCode. This fact in itself is weird and can be explained by a catch in getHeaderFieldKey and
getHeaderField that eats the FileNotFoundException
You can then look at the response code and decide what to do. In my case I append a new parm to the
URL to avoid the jdk bug and try the connection again. In my case ?foo=/ or &foo=/ worked. You could also
end it with .html, .htm or .txt (as in ?foo=.html etc.). This time you will get the body
Here's the test code, an application Test500.java and a jsp 500error.jsp. Don't forget to change TESTJSP
for your environment.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.net.*;
import java.security.*;
public class Test500
{
public static final String TESTJSP = "http://moggy.mcom.com:7779/500error.jsp";
public static void main(String args[])
throws IOException
{
System.out.println("Accessing Test Page at - "+TESTJSP);
URL url=new URL(TESTJSP);
System.out.println(url.getFile());
try {
// Open the URL Connection
HttpURLConnection conn=(HttpURLConnection)(url.openConnection());
int i=1;
String key, field;
while(true) {
// Make sure we get a key and it's corresponding field
key = conn.getHeaderFieldKey(i);
field = conn.getHeaderField(i);
if((key == null) && (field == null))
break;
System.out.println("Set header back to client -- > Key: "+key+",
Field: "+field);
i++;
}
int code=conn.getResponseCode();
System.out.println("Response Code: "+code+" "+conn.getResponseMessage());
// Did we tweak the jdk bug (should be more checks for .htm, .html, .txt and /
if(code>=400) {
// Tweak the URL and try again
String urlStr=url.toString();
if(urlStr.indexOf('?')==-1)
urlStr+="?foo=/";
else
urlStr+="&foo=/";
System.out.println("Need to retry the url: "+urlStr);
url=new URL(urlStr);
conn=(HttpURLConnection)(url.openConnection());
}
BufferedReader reader = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
String c;
while((c=reader.readLine())!=null) {
System.out.println(c);
}
}
catch(Exception e) {
System.out.println("Exception: "+e);
e.printStackTrace();
}
}
}
And the jsp (500error.jsp)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<META HTTP-EQUIV="expires" CONTENT="0">
<HTML>
<BODY bgcolor="#FFFFFF">
<%
response.setHeader("Cache-Control", "no-cache");
response.setHeader("pragma", "no-cache");
response.setStatus(500);
%>
<H1> This page returns a 500 http error </H1>
</BODY></HTML>
And finally, here is the output showing that it worked
moggy% java Test500
Accessing Test Page at - http://moggy.mcom.com:7779/500error.jsp
/500error.jsp
Set header back to client -- > Key: Server, Field: Netscape-Enterprise/4.1
Set header back to client -- > Key: Date, Field: Fri, 16 Mar 2001 02:28:22 GMT
Set header back to client -- > Key: Content-type, Field: text/html; charset=ISO8859_1
Set header back to client -- > Key: Set-cookie, Field:
NSES40Session=d%253A3ab17a46%253A12bc58936d5ddec8;path=/;expires=Fri, 16-Mar-2001 02:58:23
GMT
Set header back to client -- > Key: Cache-control, Field: no-cache
Set header back to client -- > Key: Pragma, Field: no-cache
Set header back to client -- > Key: Connection, Field: close
Response Code: 500 Server Error
Need to retry the u
Submitted On 06-AUG-2001
getwiththeprogramsun
3+ years and still no fix!
Submitted On 14-AUG-2001
kingaD
The HTTP specification clearly states that a server should
return an entity describing the reason for the error.
The bug was reported on Jul 24, 1998. The status is "fixed".
I am using JDK1.3 and HttpURLConnection is throwing
IOException for status code > 400. The bug is still not
fixed.
What is the value of HttpURLConnection if it works properly
only for status codes < 400????
Submitted On 30-AUG-2001
bboilard
Its quite unbelievable that a company like Sun, so involved
in the Internet, as been carrying that bug for so long...
I am currently quite stuck now, as we went to production
with a fix for that bug, and now, the fix is causing me
quite a headache...
Submitted On 04-JUN-2002
kikibobo
Argh! Please fix this!
Submitted On 27-JUN-2002
richdobbs
I tried the workaround given by roryward, but the technique
of calling getHeaderFieldKey didn't prevent an exception
being thrown when I called getResponseCode().
I'm on JDK 1.3 on Windows 2000.
Submitted On 28-FEB-2003
mthamala
As reported, the bug still seems to be in JDK 1.3.1. Based on
the roryward's workaround, I (accidentally) found a way to
always get the response code.
String field = connection.getHeaderField(null)
for an HttpURLConnection seems to return the first row of the
HTTP response. The row contains the status code, but
no "key". From there you can parse the code easily.
Submitted On 21-AUG-2005
I installed 1.4 and I'm still getting this error/bug. Is this fixed or not?
Submitted On 11-OCT-2005
michael@dbscape
As far as I am concerned, it still NOT work with 1.5 !!!
How is that possible ??
Submitted On 11-OCT-2005
michael@dbscape
For my problem, I had to replace the code from getURLInputStream() in URLTag.java (io taglib) as follow :
public InputStream getURLInputStream() throws IOException {
URLConnection connection = getConnection();
connection.connect();
try {
return connection.getInputStream();
}
catch (IOException e) {
return((HttpURLConnection)connection).getErrorStream();
}
}
with this code, getURLInputStream() sends the content of the error message instead of throwing the exception.
Submitted On 19-MAY-2006
morkster
1.5.0_06 Still no fix?
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|