Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 40396 invoked from network); 7 Feb 2005 10:40:15 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Feb 2005 10:40:15 -0000 Received: (qmail 22520 invoked by uid 500); 7 Feb 2005 10:40:15 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 22500 invoked by uid 500); 7 Feb 2005 10:40:14 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 22487 invoked by uid 99); 7 Feb 2005 10:40:14 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from eagle.ericsson.se (HELO eagle.ericsson.se) (193.180.251.53) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 07 Feb 2005 02:40:13 -0800 Received: from esealmw126.eemea.ericsson.se ([153.88.254.123]) by eagle.ericsson.se (8.12.10/8.12.10/WIREfire-1.8b) with ESMTP id j17AdjP4003677 for ; Mon, 7 Feb 2005 11:40:10 +0100 Received: from esealmw128.eemea.ericsson.se ([153.88.254.172]) by esealmw126.eemea.ericsson.se with Microsoft SMTPSVC(6.0.3790.211); Mon, 7 Feb 2005 11:40:21 +0100 Received: from emyklnt164.ao.ericsson.se ([150.236.92.64]) by esealmw128.eemea.ericsson.se with Microsoft SMTPSVC(6.0.3790.211); Mon, 7 Feb 2005 11:40:21 +0100 Received: by emyklnt164.ao.ericsson.se with Internet Mail Service (5.5.2657.72) id ; Mon, 7 Feb 2005 18:39:59 +0800 Message-ID: <6BA346EB59B2D51194E200508B046FE107DFE78A@emyklnt151.ao.ericsson.se> From: "Christophe Bouhier (MC/ECM)" To: "'HttpClient User Discussion' (E-mail)" Subject: newbie authentication. Date: Mon, 7 Feb 2005 18:39:31 +0800 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2657.72) Content-Type: text/plain; charset="iso-8859-1" X-OriginalArrivalTime: 07 Feb 2005 10:40:21.0328 (UTC) FILETIME=[6C50A500:01C50D01] X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hello, I am trying to implement authentication and played around with the examples. The Method is a HEAD method, I first execute without authentication and if the result is a 401, I set credentials and setDoAuthentication and execute again. On this however I get a Connection Timeout exception. (I get the impression that the proxy settting is lost in the Header???) Propably a newbie issue, but I haven't been able to pinpoint. Can someone help? here is code: (See the code which checks for the 401/SC_UNAUTHORIZED status). public static ipNetHEADInfo getHeadInfo(URL url) throws ipException { ipNetHEADInfo head = null; HttpClient hClient = new HttpClient(); hClient.getParams().setSoTimeout(5000); // hClient.setTimeout(5000); deprecated in 3.0 client HostConfiguration hc = hClient.getHostConfiguration(); hc = setProxySetttings(hClient, hc); HeadMethod hMethod = null; try { hMethod = new HeadMethod(url.toString()); hMethod.setRequestHeader("cache-control", "no-cache"); int status = hClient.executeMethod(hMethod); if (status != HttpStatus.SC_OK) { // Check for redirection. if (status == HttpStatus.SC_MOVED_PERMANENTLY || status == HttpStatus.SC_MOVED_TEMPORARILY || status == HttpStatus.SC_SEE_OTHER || status == HttpStatus.SC_TEMPORARY_REDIRECT) { String redirectLocation; Header locationHeader = hMethod .getResponseHeader("location"); if (locationHeader != null) { redirectLocation = locationHeader.getValue(); hMethod = new HeadMethod(redirectLocation); status = hClient.executeMethod(hMethod); if (status != HttpStatus.SC_OK) { throw new ipException(hMethod.getStatusLine() .getReasonPhrase()); } } else { // The response is invalid and did not provide the new // location for // the resource. Report an error or possibly handle the // response // like a 404 Not Found error. } } else { if (status == HttpStatus.SC_UNAUTHORIZED) { // Retry with password. hClient.getState().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials("username", "password") ); hMethod = new HeadMethod(url.toString()); hMethod.setDoAuthentication(true); status = hClient.executeMethod(hMethod); if (status != HttpStatus.SC_OK) { throw new ipException(hMethod.getStatusLine() .getReasonPhrase()); } } throw new ipException(hMethod.getStatusLine() .getReasonPhrase()); } head = getHeadInfo(hMethod); } catch (HttpException he) { // Received Illegal redirect exception on some URLs throw new ipException(he.getMessage()); } catch (IOException ioe) { throw new ipException(ioe.getMessage()); } catch (java.lang.IllegalArgumentException iae) { throw new ipException(iae.getMessage()); } finally { if (hMethod != null) { hMethod.releaseConnection(); } } return head; } --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-user-help@jakarta.apache.org