http bug

R

Roedy Green

I have noticed a program that has worked for a long time now just
freezes as if it had a infinite timeout on HTTP GETs. This started
happening with JDK 1,6.0_18. Has anyone else noticed this?
 
L

Lothar Kimmeringer

Roedy said:
I have noticed a program that has worked for a long time now just
freezes as if it had a infinite timeout on HTTP GETs. This started
happening with JDK 1,6.0_18. Has anyone else noticed this?

Until 1.5. AFAIR there was no setting in HttpUrlConnection
allowing you to reduce the timeout to something lower than
infinity, forcing you to do some workarounds to get a timeout
when connecting or working with Sockets created with
HttpUrlConnection (I assume you are talking about HttpUrlConnection).

Assuming specific timeout-settings is always a bad idea, so you
should set a timeout for yourself instead of hoping that the
default behavior of a VM keeps the same all time.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
L

Lew

Lothar Kimmeringer said:
Until 1.5. AFAIR there was no setting in HttpUrlConnection
allowing you to reduce the timeout to something lower than
infinity, forcing you to do some workarounds to get a timeout
when connecting or working with Sockets created with
HttpUrlConnection (I assume you are talking about HttpUrlConnection).

You know what you get when you assume. The OP provided a dearth of
information about exactly what he's doing. Perhaps he might consider
sharing the details, or even providing an SSCCE.
 
D

Daniel Pitts

Lothar said:
Until 1.5. AFAIR there was no setting in HttpUrlConnection
allowing you to reduce the timeout to something lower than
infinity, forcing you to do some workarounds to get a timeout
when connecting or working with Sockets created with
HttpUrlConnection (I assume you are talking about HttpUrlConnection).

Assuming specific timeout-settings is always a bad idea, so you
should set a timeout for yourself instead of hoping that the
default behavior of a VM keeps the same all time.


Regards, Lothar
I often find the standard HttpUrlConnection lacking, and usually go with
apache commons HttpClient instead. You have more control of the
process, if you care, but it also "works" out-of-the-box if you don't
want to configure it as much.
 
L

Lothar Kimmeringer

Daniel said:
I often find the standard HttpUrlConnection lacking, and usually go with
apache commons HttpClient instead. You have more control of the
process, if you care, but it also "works" out-of-the-box if you don't
want to configure it as much.

The last time I checked, GetMethod and PostMethod were two
classes sharing a lot of methods but not a common superclass.
So you end up with code like this

if (performGet) {
methodGet = new GetMethod(host + url);
methodGet.setQueryString(query);
methodGet.setDoAuthentication(authNeeded);
methodGet.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodGet.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodGet.setRequestHeader("Connection", "keep-alive");
methodGet.setRequestHeader("Cache-Control", "no-cache");
}
else {
methodPost = new PostMethod(host + url);
methodPost.setRequestHeader("Connection", "keep-alive");
methodPost.setDoAuthentication(authNeeded);
methodPost.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodPost.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodPost.setRequestHeader("Cache-Control", "no-cache");
}
if (methodGet != null){
statuscode = client.executeMethod(methodGet);
}
else{
statuscode = client.executeMethod(methodPost);
}

and so on. If you have a specific HTTP-session to handle
programmatically, HttpClient is nice, but if you have to
build different HTTP-requests in dependence of external
configurations, you have a lot of duplicate code that
is prone to errors.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
D

Daniel Pitts

Lothar said:
The last time I checked, GetMethod and PostMethod were two
classes sharing a lot of methods but not a common superclass.
So you end up with code like this

if (performGet) {
methodGet = new GetMethod(host + url);
methodGet.setQueryString(query);
methodGet.setDoAuthentication(authNeeded);
methodGet.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodGet.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodGet.setRequestHeader("Connection", "keep-alive");
methodGet.setRequestHeader("Cache-Control", "no-cache");
}
else {
methodPost = new PostMethod(host + url);
methodPost.setRequestHeader("Connection", "keep-alive");
methodPost.setDoAuthentication(authNeeded);
methodPost.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodPost.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodPost.setRequestHeader("Cache-Control", "no-cache");
}
if (methodGet != null){
statuscode = client.executeMethod(methodGet);
}
else{
statuscode = client.executeMethod(methodPost);
}

and so on. If you have a specific HTTP-session to handle
programmatically, HttpClient is nice, but if you have to
build different HTTP-requests in dependence of external
configurations, you have a lot of duplicate code that
is prone to errors.


Regards, Lothar
Last time I checked, they both implement HttpMethod and are derived from
HttpMethodBase. Perhaps you had a really old version, or misinterpreted
something else.
 
L

Lew

Daniel said:
Last time I checked, they both implement HttpMethod and are derived from
HttpMethodBase.  Perhaps you had a really old version, or misinterpreted
something else.

I'm not seeing either one, nor 'HttpMethodBase', nor 'HttpMethod' in
the HttpClient Javadocs. I find 'HttpGet' and 'HttpPost', which
inherit from 'HttpRequestBase' and implement 'HttpMessage', and seem
roughly equivalent to what you're talking about.
<http://hc.apache.org/httpcomponents-client/httpclient/apidocs/
index.html>

From <http://hc.apache.org/>:
"HttpComponents Client is a successor of and replacement for Commons
HttpClient 3.x. Users of Commons HttpClient are strongly encouraged to
upgrade. ...
"Commons HttpClient 3.x codeline is nearing the end of life. All users
of Commons HttpClient 3.x are strongly encouraged to upgrade to
HttpClient 4.0."
 
D

Daniel Pitts

Lew said:
I'm not seeing either one, nor 'HttpMethodBase', nor 'HttpMethod' in
the HttpClient Javadocs. I find 'HttpGet' and 'HttpPost', which
inherit from 'HttpRequestBase' and implement 'HttpMessage', and seem
roughly equivalent to what you're talking about.
<http://hc.apache.org/httpcomponents-client/httpclient/apidocs/
index.html>

From <http://hc.apache.org/>:
"HttpComponents Client is a successor of and replacement for Commons
HttpClient 3.x. Users of Commons HttpClient are strongly encouraged to
upgrade. ...
"Commons HttpClient 3.x codeline is nearing the end of life. All users
of Commons HttpClient 3.x are strongly encouraged to upgrade to
HttpClient 4.0."
Our codebase has been using HttpClient 3.1, so that is why the
discrepancy.
 
A

Arne Vajhøj

The last time I checked, GetMethod and PostMethod were two
classes sharing a lot of methods but not a common superclass.

Sure?

HttpClient 2.0.2 has a common super class.
So you end up with code like this

if (performGet) {
methodGet = new GetMethod(host + url);
methodGet.setQueryString(query);
methodGet.setDoAuthentication(authNeeded);
methodGet.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodGet.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodGet.setRequestHeader("Connection", "keep-alive");
methodGet.setRequestHeader("Cache-Control", "no-cache");
}
else {
methodPost = new PostMethod(host + url);
methodPost.setRequestHeader("Connection", "keep-alive");
methodPost.setDoAuthentication(authNeeded);
methodPost.getParams().setParameter("http.socket.timeout",
Integer.valueOf(timeout));
methodPost.getParams().setParameter(
HttpMethodParams.RETRY_HANDLER, retryhandler);
methodPost.setRequestHeader("Cache-Control", "no-cache");
}
and so on. If you have a specific HTTP-session to handle
programmatically, HttpClient is nice, but if you have to
build different HTTP-requests in dependence of external
configurations, you have a lot of duplicate code that
is prone to errors.

Most HTTP request receivers are either POST or GET anyway.

I can not imagine sending the exact same data to an URL
just with different method should be that common.

Arne
 
A

Arne Vajhøj

I'm not seeing either one, nor 'HttpMethodBase', nor 'HttpMethod' in
the HttpClient Javadocs. I find 'HttpGet' and 'HttpPost', which
inherit from 'HttpRequestBase' and implement 'HttpMessage', and seem
roughly equivalent to what you're talking about.
<http://hc.apache.org/httpcomponents-client/httpclient/apidocs/
index.html>

Which you explain yourself:
From<http://hc.apache.org/>:
"HttpComponents Client is a successor of and replacement for Commons
HttpClient 3.x. Users of Commons HttpClient are strongly encouraged to
upgrade. ...
"Commons HttpClient 3.x codeline is nearing the end of life. All users
of Commons HttpClient 3.x are strongly encouraged to upgrade to
HttpClient 4.0."

Version 4.0 is relative new.

And the completely broke existing code, so a lot of people
will use 2.x and 3.x for a long time, because they don't
want to rewrite the code.

Arne
 
R

Roedy Green

You know what you get when you assume. The OP provided a dearth of
information about exactly what he's doing. Perhaps he might consider
sharing the details, or even providing an SSCCE.

The code is posted at http://mindprod.com/products1.html#VERCHECK

When I get a round tuit, I will prune this back to a SSCCE.

I was hoping someone else was having the problem and had solved it or
had read a post somewhere about timeouts not behaving the way they use
to.

Oddly, when I run the program a second time, usually it completes the
read immediately and successfully. This may be a Windows 7 64-bit
problem. I have found rebooting Win 7 often clears up a multitude of
strange behaviours.

The problem is not reproducible, the nastiest kind.
 
R

Roedy Green

The last time I checked, GetMethod and PostMethod were two
classes sharing a lot of methods but not a common superclass.
So you end up with code like this

Are you complaining about Sun or Apache?
 
A

Arne Vajhøj

The code is posted at http://mindprod.com/products1.html#VERCHECK

When I get a round tuit, I will prune this back to a SSCCE.

I was hoping someone else was having the problem and had solved it or
had read a post somewhere about timeouts not behaving the way they use
to.

Oddly, when I run the program a second time, usually it completes the
read immediately and successfully.

Sounds more like a very slow DNS server and your immediate DNS server
having the name cached the second time.

Arne
 
R

Roedy Green

Given that the code was explicit stated to be Apache, then
complaining to SUN would not make much sense.

He was not explicit. If you know that GetMethod and PostMethod are
unique to Apache, you could infer that. But Lothar did not state it
explicitly. The audience is wider than those who post. It always
helps to make things abundantly clear.
 
R

Roedy Green

Sounds more like a very slow DNS server and your immediate DNS server
having the name cached the second time.

Should not the GET timeout if the DNS server takes 4 minutes?
 
L

Lew

Arne Vajhøj wrote, quoted or indirectly quoted someone who said :

Roedy said:
He was not explicit. If you know that GetMethod and PostMethod are
unique to Apache, you could infer that. But Lothar did not state it
explicitly. The audience is wider than those who post. It always
helps to make things abundantly clear.

Lothar wasn't explicit, but Arne didn't say it was Lothar. Daniel was
explicit, in the post to which Lothar responded.
 
L

Lothar Kimmeringer

Roedy said:
He was not explicit. If you know that GetMethod and PostMethod are
unique to Apache, you could infer that.

Reading the quoted text of a post often helps. I was answering to
| I often find the standard HttpUrlConnection lacking, and usually go with
| apache commons HttpClient instead.
But Lothar did not state it
explicitly. The audience is wider than those who post. It always
helps to make things abundantly clear.

I'm quite sure that most of the lurkers were also able to
tell, what framework I was ranting about. ;-)


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
L

Lothar Kimmeringer

Arne said:
Sure?

HttpClient 2.0.2 has a common super class.

As I said: "The last time I checked" It's been quite a while
now, deciding to use HttpUrlConnection instead for implementing
my AS2-Connector. The code I posted was taken from another
application developed by a coworker. Since my decision I never
came back to the point of reconsideration because all the
features of HttpClient I in general don't need.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
L

Lew

Lothar said:
As I said: "The last time I checked" It's been quite a while now,

Really must have been quite a while, given that the April 25, 2001,
revision of 'GetMethod', marked "initial revision", and the same-date
version of 'PostMethod', also marked "initial revision", both inherit
from 'HttpMethodBase'; in fact, that version of 'PostMethod' directly
inherits from 'GetMethod'.

Given that "HttpClient was started in 2001 as a subproject of the
Jakarta Commons,"
<http://hc.apache.org/httpclient-3.x/index.html>
I don't think you could have been using it much earlier than that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top