Submitted On 01-MAY-2001
kampman
I've checked again, and the problem is still reproducable.
This behaviour,
however, seems to be a problem with the server used by
tridion (Microsoft
IIS/4.0). The server doesn't respond on HEAD-requests at
all. The reason
for the jvm to keep waiting forever (?) when using jdk1.3 is
that jdk1.3
sends HTTP 1.1 requests with a "Connection: Keep-Alive"
header. The
server doesn't appear to have a time-out on connections, so
it is kept
open forever. And, as long as the connection is open, the
jvm will wait
for a reponse that will never be given by this server.
So this appears to be a problem with the server and not with
Java. A
client-side timeout on the connection would be a nice thing
to have
though.
Submitted On 18-JUN-2008
NicDumZ
This is reproducable in jdk 1.5, please re open this bug :)
Test case :
import java.net.HttpURLConnection;
import java.net.URL;
public class GetResponseCodeError {
public static void main(String[] args) throws Exception {
HttpURLConnection urlConn;
URL url = new URL("http://digg.com");
System.out.print("Opening connection...");
urlConn = (HttpURLConnection) url.openConnection();
System.out.println("opened !");
System.out.print("Connecting...");
urlConn.connect();
System.out.println("connected !");
@SuppressWarnings("unused")
int httpResponseCode = 0;
System.out.print("Getting response code...");
httpResponseCode = urlConn.getResponseCode(); //hangs forever
System.out.println("done !");
}
}
I consider this as a serious bug : http://digg.com is reachable and has a "standard HTTP header." :
curl -I http://digg.com returns :
HTTP/1.1 200 OK
Date: Wed, 18 Jun 2008 13:41:03 GMT
Server: Apache
X-Powered-By: PHP/5.2.0-8+etch1
Set-Cookie: ccc=1; expires=Thu, 18-Jun-2009 13:41:03 GMT; path=/
Set-Cookie: PHPSESSID=a76a192de6987caccd129938a46c38c5; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: private
Pragma: no-cache
Set-Cookie: 1337=0; path=/
Content-Type: text/html; charset=UTF-8
There is of course a temporary workaround to avoid that infinite wait(), consisting in setting the read timeout (HttpURLConnection.setReadTimeout(timeout) ). But I insist that this not addressing the issue since it will throw a java.net.SocketTimeoutException on a *valid* website.
Submitted On 18-JUN-2008
NicDumZ
Correcting my comment, this is reproducible in 1.6.0
Submitted On 21-JUL-2008
i noticed that digg's web server look for the browser agent and if it is not available it does not response to request. Here is the solution for that set browser agent in HttpURLConnection object
public int getResponse(String webUrl) throws IOException {
URL url = new URL(webUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setConnectTimeout(5000);
connection.setInstanceFollowRedirects(true);
connection.setAllowUserInteraction(true);
connection.setRequestProperty("User-Agent", "Mozilla/4.5");
connection.connect();
connection.disconnect();
return connection.getResponseCode();
}
Submitted On 21-JUL-2008
/**
*
*/
package com.ocricket.util;
import java.io.IOException;
import java.net.*;
/**
* @author Dhiraj Thakur
* @Email thakur.dheeraj@gmail.com
*
*/
public class InternetUtil {
/**
*
*/
public InternetUtil() {
// TODO Auto-generated constructor stub
}
public int getResponse(String webUrl) throws IOException {
URL url = new URL(webUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setConnectTimeout(5000);
connection.setInstanceFollowRedirects(true);
connection.setAllowUserInteraction(true);
connection.setRequestProperty("User-Agent", "Mozilla/4.5");
connection.connect();
connection.disconnect();
return connection.getResponseCode();
}
public static void main(String[] argv) throws IOException {
InternetUtil util = new InternetUtil();
int status = util
.getResponse("http://digg.com/odd_stuff/Dear_Charles_Manson_Little_Billy_Writes_to_Serial_Killers");
System.out.println("status is " + status);
}
}
Submitted On 11-FEB-2009
Got the same problem, in my case even the workaround doesnt do it.
Constellation is the request for a URL response code via a non existing proxy server (rich client application using a configured proxy that exists no more).
Without (non existing ) proxy server set, the connection timeout is honored.
Using java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|