You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Thorsten Scherler <th...@juntadeandalucia.es> on 2004/03/01 11:35:18 UTC
Once again 302 :(
Hello group,
I have a similar problem like Emre.
...but this time the problem depends on the plattform I am on. I am a
little bit confused because it is running fine on win but on linux not.
Site causing the problem:
andaluciajunta.es
Windows:
I get 302!
Linux (debian):
org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutException
My code:
public String getHttp(String address) throws Exception {
// Create an instance of HttpClient.
org.apache.commons.httpclient.HttpClient client =
new org.apache.commons.httpclient.HttpClient();
String url = null;
String protocol = "http://";
String protocolS = "https://";
//System.out.println("address->"+address);
if (address.indexOf(protocol) > -1) {
url = address;
} else if (address.indexOf(protocolS) > -1) {
url = address;
} else {
url = protocol + address;
}
// establish a connection within 5 seconds
client.setConnectionTimeout(5000);
// Create a method instance.
HttpMethod method = new GetMethod(url);
method.setFollowRedirects(true);
// Execute the method.
int statusCode = -1;
int attempt = 0;
// We will retry up to 3 times.
while (statusCode == -1 && attempt < 3) {
attempt += 1;
try {
// execute the method.
statusCode = client.executeMethod(method);
} catch (HttpRecoverableException e) {
System.err.println(
"A recoverable exception occurred, retrying."
+ e.getMessage());
} catch (IOException e) {
System.err.println("Failed to download file.");
e.printStackTrace();
return "666";
}
}
// Check that we didn't run out of retries.
if (statusCode == -1) {
System.err.println("Failed to recover from exception.");
return "666";
}
//Read the response code
try {
int code = method.getStatusCode();
//System.err.println(code);
//Release the connection.
method.releaseConnection();
return String.valueOf(code);
} catch (RuntimeException e1) {
e1.printStackTrace();
//Release the connection.
method.releaseConnection();
//this is not a valid HTTP code, it was choosen because of
that ;-)
return "666";
}
}
King regards
--
"Erare humanum est", Seneca
Thorsten Scherler
Tfno: 955 062 627
Email: thorsten.scherler.ext@juntadeandalucia.es
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
Michael Becke wrote:
> Hi Thorsten,
>
> Not sure what's happening here. I'm trying under RedHat and all is
> well. Please post the error stack trace as well as a wire log of the
> problem <http://jakarta.apache.org/commons/httpclient/logging.html>.
> This will help to narrow down the problem.
>
> Mike
>
I used the configuration on
<http://jakarta.apache.org/commons/httpclient/logging.html>.
...but no *I guess* a stupid question:
To which file will it be written?
--
"Erare humanum est", Seneca
Thorsten Scherler
Tfno: 955 062 627
Email: thorsten.scherler.ext@juntadeandalucia.es
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
Michael Becke wrote:
> Hi Thorsten,
>
> Not sure what's happening here. I'm trying under RedHat and all is well.
I installed the log4j and traced down the problem:
You said for you is working fine!
My local maschine (windows) as well is working fine with both addresses!
...but the server is in a different net! I can't "lynx
www.andaluciajunta.es" from the server the application is running! I
think that is because the server is before the firewall. You and I are
behind the firewall!
Fazit: No problem with the http-client at all! It is a problem of our
net config (firewall)!
Thank you for testing my code that was most valuable information.
This was why I was testing the lynx and found the root problem!
I appreciate your information!
King regards
--
"Erare humanum est", Seneca
Thorsten Scherler
Tfno: 955 062 627
Email: thorsten.scherler.ext@juntadeandalucia.es
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
Michael Becke wrote:
> Hi Thorsten,
>
> Not sure what's happening here. I'm trying under RedHat and all is well.
I installed the log4j and traced down the problem:
You said for you is working fine!
My local maschine (windows) as well is working fine with both addresses!
...but the server is in a different net! I can't "lynx
www.andaluciajunta.es" from the server the application is running! I
think that is because the server is before the firewall. You and I are
behind the firewall!
Fazit: No problem with the http-client at all! It is a problem of our
net config (firewall)!
Thank you for testing my code that was most valuable information.
This was why I was testing the lynx and found the root problem!
I appreciate your information!
P.S. we seem to have some problems with the mail server. This is a repost!
King regards
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Michael Becke <be...@u.washington.edu>.
Hi Thorsten,
Not sure what's happening here. I'm trying under RedHat and all is
well. Please post the error stack trace as well as a wire log of the
problem <http://jakarta.apache.org/commons/httpclient/logging.html>.
This will help to narrow down the problem.
Mike
On Mar 1, 2004, at 9:20 AM, Thorsten Scherler wrote:
> Site causing the problem:
>
>> andaluciajunta.es
>
> When I ask for www.andaluciajunta.es. I get an IO Exception.
>
> --
> "Erare humanum est", Seneca
>
> Thorsten Scherler
>
> Tfno: 955 062 627
> Email: thorsten.scherler.ext@juntadeandalucia.es
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> commons-httpclient-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
Site causing the problem:
> andaluciajunta.es
When I ask for www.andaluciajunta.es. I get an IO Exception.
--
"Erare humanum est", Seneca
Thorsten Scherler
Tfno: 955 062 627
Email: thorsten.scherler.ext@juntadeandalucia.es
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
Andre John Mas wrote:
> I am not really in a position to test the code, but could you see
> whether changing the value of the 'user-agent' header gives:
>
> method.setRequestHeader("user-agent",
> "Mozilla/5.0 (Windows; U; Windows NT 5.0;
> en-US; rv:1.6) Gecko/20040113");
>
> or
>
> method.setRequestHeader("user-agent",
> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021");
>
> Values taken from: http://nycbug.org/stat/agent_200312.html
>
> Also what JDK versions are you using?
Tried it but no differents. ...but cheers, dude!
I am using Version 1.4.2 on both!
King regards
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Thorsten Scherler <th...@juntadeandalucia.es>.
Andre John Mas wrote:
> I am not really in a position to test the code, but could you see
> whether changing the value of the 'user-agent' header gives:
>
> method.setRequestHeader("user-agent",
> "Mozilla/5.0 (Windows; U; Windows NT 5.0;
> en-US; rv:1.6) Gecko/20040113");
>
> or
>
> method.setRequestHeader("user-agent",
> "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021");
>
> Values taken from: http://nycbug.org/stat/agent_200312.html
>
> Also what JDK versions are you using?
Tried it but no differents. ...but cheers, dude!
I am using Version 1.4.2 on both!
King regards
--
"Erare humanum est", Seneca
Thorsten Scherler
Tfno: 955 062 627
Email: thorsten.scherler.ext@juntadeandalucia.es
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org
Re: Once again 302 :(
Posted by Andre John Mas <am...@expedia.com>.
I am not really in a position to test the code, but could you see
whether changing the value of the 'user-agent' header gives:
method.setRequestHeader("user-agent",
"Mozilla/5.0 (Windows; U; Windows NT 5.0;
en-US; rv:1.6) Gecko/20040113");
or
method.setRequestHeader("user-agent",
"Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021");
Values taken from: http://nycbug.org/stat/agent_200312.html
Also what JDK versions are you using?
Andre
Thorsten Scherler wrote:
> Hello group,
> I have a similar problem like Emre.
>
> ...but this time the problem depends on the plattform I am on. I am a
> little bit confused because it is running fine on win but on linux not.
>
> Site causing the problem:
> andaluciajunta.es
>
> Windows:
> I get 302!
>
> Linux (debian):
> org.apache.commons.httpclient.HttpConnection$ConnectionTimeoutException
>
> My code:
> public String getHttp(String address) throws Exception {
> // Create an instance of HttpClient.
> org.apache.commons.httpclient.HttpClient client =
> new org.apache.commons.httpclient.HttpClient();
> String url = null;
> String protocol = "http://";
> String protocolS = "https://";
> //System.out.println("address->"+address);
> if (address.indexOf(protocol) > -1) {
> url = address;
> } else if (address.indexOf(protocolS) > -1) {
> url = address;
> } else {
> url = protocol + address;
> }
> // establish a connection within 5 seconds
> client.setConnectionTimeout(5000); // Create a
> method instance.
> HttpMethod method = new GetMethod(url);
> method.setFollowRedirects(true);
> // Execute the method.
> int statusCode = -1;
> int attempt = 0;
> // We will retry up to 3 times.
> while (statusCode == -1 && attempt < 3) {
> attempt += 1;
> try {
> // execute the method.
> statusCode = client.executeMethod(method);
> } catch (HttpRecoverableException e) {
> System.err.println(
> "A recoverable exception occurred, retrying."
> + e.getMessage());
> } catch (IOException e) {
> System.err.println("Failed to download file.");
> e.printStackTrace();
> return "666";
> }
> }
> // Check that we didn't run out of retries.
> if (statusCode == -1) {
> System.err.println("Failed to recover from exception.");
> return "666";
> }
>
> //Read the response code
> try {
> int code = method.getStatusCode();
> //System.err.println(code);
> //Release the connection.
> method.releaseConnection();
> return String.valueOf(code);
> } catch (RuntimeException e1) {
> e1.printStackTrace();
> //Release the connection.
> method.releaseConnection();
> //this is not a valid HTTP code, it was choosen because of
> that ;-)
> return "666";
> }
> }
>
> King regards
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org