Licensee reported us that behavior of HttpURLConnection.getResponseCode() is
different between 1.3.1 and 1.3.1_01. It seems to happen after implementation of
#4160499. This problem appears on Solaris and Windows.
- behavior of getResponseCode() included in JDK1.3.1 older
When HTTP server returns HTTP responce, Java receive the responce code as
server returned.
- behavior of getResponseCode() included in JDK1.3.1_01
When HTTP server returns code over 400(?), Java throw the exception. Detail of
exception is uncertain.
We tested this matter by using followin sample code on Windows. In the case of
access to exsiting server, difference donesn't appear. But in the other case, some
differences appear.
----------------------
E:\>java -fullversion
java full version "1.3.1-b24"
E:\>java HttpTest GET http://jle <- existing server
method=GET
URL=http://jle.japan.sun.com
ResponseCode=200
E:\>java HttpTest PUT http://jle
method=PUT
URL=http://jle.japan.sun.com
java.io.FileNotFoundException: http://jle
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:574)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
E:\>java HttpTest DELETE http://jle
method=DELETE
URL=http://jle
java.io.FileNotFoundException: http://jle
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:574)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
E:\>java HttpTest GET http://foo <- not existing server
method=GET
URL=http://foo
java.net.UnknownHostException: foo
at java.net.InetAddress.getAllByName0(InetAddress.java:571)
at java.net.InetAddress.getAllByName0(InetAddress.java:540)
at java.net.InetAddress.getByName(InetAddress.java:449)
at java.net.Socket.<init>(Socket.java:100)
at sun.net.NetworkClient.doConnect(NetworkClient.java:50)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:331)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:517)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:277)
at sun.net.www.http.HttpClient.New(HttpClient.java:289)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:408)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.ja
va:501)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
----------------------
E:\>java -fullversion
java full version "1.3.1_01"
E:\>java HttpTest GET http://jle
method=GET
URL=http://jle.japan.sun.com
ResponseCode=200
E:\>java HttpTest put http://jle
method=put
URL=http://jle
java.net.ProtocolException: Invalid HTTP method: put
at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:201)
at HttpTest.main(HttpTest.java:28)
E:\>java HttpTest DELETE http://jle
method=DELETE
URL=http://jle
java.io.IOException: Server returned HTTP response code: 405 for URL: http://jle
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:564)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
E:\>java HttpTest GET http://foo
method=GET
URL=http://foo
java.net.UnknownHostException: foo
at java.net.InetAddress.getAllByName0(InetAddress.java:571)
at java.net.InetAddress.getAllByName0(InetAddress.java:540)
at java.net.InetAddress.getByName(InetAddress.java:449)
at java.net.Socket.<init>(Socket.java:100)
at sun.net.NetworkClient.doConnect(NetworkClient.java:50)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:335)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:521)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:271)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:281)
at sun.net.www.http.HttpClient.New(HttpClient.java:293)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:404)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:497)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
---->8----------------->8---------------->8-------------
import java.net.*;
import java.io.*;
public class HttpTest {
public static void main( String args[] ){
URL url=null;
HttpURLConnection con=null;
if(args.length != 2){
System.out.println("usage: java HttpTest method URL");
System.exit(1);
}
System.out.println("method=" + args[0]);
System.out.println("URL=" + args[1]);
String method = new String(args[0]);
try{
url = new URL(args[1]);
} catch(java.net.MalformedURLException ex){
ex.printStackTrace();
System.exit(1);
}
try{
con = (HttpURLConnection)url.openConnection();
con.setRequestMethod(method);
int code = con.getResponseCode();
System.out.println("ResponseCode=" + code);
} catch(java.net.ProtocolException ex){
ex.printStackTrace();
} catch(java.io.IOException ex){
ex.printStackTrace();
}
}
}
---->8----------------->8---------------->8-------------
different between 1.3.1 and 1.3.1_01. It seems to happen after implementation of
#4160499. This problem appears on Solaris and Windows.
- behavior of getResponseCode() included in JDK1.3.1 older
When HTTP server returns HTTP responce, Java receive the responce code as
server returned.
- behavior of getResponseCode() included in JDK1.3.1_01
When HTTP server returns code over 400(?), Java throw the exception. Detail of
exception is uncertain.
We tested this matter by using followin sample code on Windows. In the case of
access to exsiting server, difference donesn't appear. But in the other case, some
differences appear.
----------------------
E:\>java -fullversion
java full version "1.3.1-b24"
E:\>java HttpTest GET http://jle <- existing server
method=GET
URL=http://jle.japan.sun.com
ResponseCode=200
E:\>java HttpTest PUT http://jle
method=PUT
URL=http://jle.japan.sun.com
java.io.FileNotFoundException: http://jle
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:574)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
E:\>java HttpTest DELETE http://jle
method=DELETE
URL=http://jle
java.io.FileNotFoundException: http://jle
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:574)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
E:\>java HttpTest GET http://foo <- not existing server
method=GET
URL=http://foo
java.net.UnknownHostException: foo
at java.net.InetAddress.getAllByName0(InetAddress.java:571)
at java.net.InetAddress.getAllByName0(InetAddress.java:540)
at java.net.InetAddress.getByName(InetAddress.java:449)
at java.net.Socket.<init>(Socket.java:100)
at sun.net.NetworkClient.doConnect(NetworkClient.java:50)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:331)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:517)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:267)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:277)
at sun.net.www.http.HttpClient.New(HttpClient.java:289)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:408)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.ja
va:501)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
----------------------
E:\>java -fullversion
java full version "1.3.1_01"
E:\>java HttpTest GET http://jle
method=GET
URL=http://jle.japan.sun.com
ResponseCode=200
E:\>java HttpTest put http://jle
method=put
URL=http://jle
java.net.ProtocolException: Invalid HTTP method: put
at java.net.HttpURLConnection.setRequestMethod(HttpURLConnection.java:201)
at HttpTest.main(HttpTest.java:28)
E:\>java HttpTest DELETE http://jle
method=DELETE
URL=http://jle
java.io.IOException: Server returned HTTP response code: 405 for URL: http://jle
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:564)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
E:\>java HttpTest GET http://foo
method=GET
URL=http://foo
java.net.UnknownHostException: foo
at java.net.InetAddress.getAllByName0(InetAddress.java:571)
at java.net.InetAddress.getAllByName0(InetAddress.java:540)
at java.net.InetAddress.getByName(InetAddress.java:449)
at java.net.Socket.<init>(Socket.java:100)
at sun.net.NetworkClient.doConnect(NetworkClient.java:50)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:335)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:521)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:271)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:281)
at sun.net.www.http.HttpClient.New(HttpClient.java:293)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:404)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:497)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:230)
at HttpTest.main(HttpTest.java:29)
---->8----------------->8---------------->8-------------
import java.net.*;
import java.io.*;
public class HttpTest {
public static void main( String args[] ){
URL url=null;
HttpURLConnection con=null;
if(args.length != 2){
System.out.println("usage: java HttpTest method URL");
System.exit(1);
}
System.out.println("method=" + args[0]);
System.out.println("URL=" + args[1]);
String method = new String(args[0]);
try{
url = new URL(args[1]);
} catch(java.net.MalformedURLException ex){
ex.printStackTrace();
System.exit(1);
}
try{
con = (HttpURLConnection)url.openConnection();
con.setRequestMethod(method);
int code = con.getResponseCode();
System.out.println("ResponseCode=" + code);
} catch(java.net.ProtocolException ex){
ex.printStackTrace();
} catch(java.io.IOException ex){
ex.printStackTrace();
}
}
}
---->8----------------->8---------------->8-------------
- duplicates
-
JDK-4984712 With JRE 1.3.1 getResponseCode() from the HttpURLConnection throw unwanted excep
- Closed
- relates to
-
JDK-4160499 sun.net.www.protocol.http.HttpURLConnection error handling
- Resolved