Return-Path: Delivered-To: apmail-jakarta-httpcomponents-dev-archive@www.apache.org Received: (qmail 37819 invoked from network); 22 Nov 2006 16:11:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Nov 2006 16:11:28 -0000 Received: (qmail 9499 invoked by uid 500); 22 Nov 2006 16:11:36 -0000 Delivered-To: apmail-jakarta-httpcomponents-dev-archive@jakarta.apache.org Received: (qmail 9457 invoked by uid 500); 22 Nov 2006 16:11:36 -0000 Mailing-List: contact httpcomponents-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient Project" Delivered-To: mailing list httpcomponents-dev@jakarta.apache.org Received: (qmail 9444 invoked by uid 99); 22 Nov 2006 16:11:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Nov 2006 08:11:36 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Nov 2006 08:11:25 -0800 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 0FF6F7142D7 for ; Wed, 22 Nov 2006 08:11:04 -0800 (PST) Message-ID: <3188463.1164211864062.JavaMail.jira@brutus> Date: Wed, 22 Nov 2006 08:11:04 -0800 (PST) From: =?utf-8?Q?Ortwin_Gl=C3=BCck_=28JIRA=29?= To: httpcomponents-dev@jakarta.apache.org Subject: [jira] Commented: (HTTPCLIENT-606) HttpMethodDirector fails when redirecting to a encoded URL location MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org [ http://issues.apache.org/jira/browse/HTTPCLIENT-606?page=3Dcomments#a= ction_12451978 ]=20 =20 Ortwin Gl=C3=BCck commented on HTTPCLIENT-606: ----------------------------------------- Samuel, This server is misbehaving. It returns non-ASCII characters in a HTTP heade= r, which is a gross violation of the spec: 2006/11/22 17:08:26:625 CET [DEBUG] header - -<< "Location: http://www.dipu= alba.es/municipios/F?rez/[\r][\n]" The server must URL-encode the URL (in UTF-8) correctly. There is nothing w= e can do. > HttpMethodDirector fails when redirecting to a encoded URL location > ------------------------------------------------------------------- > > Key: HTTPCLIENT-606 > URL: http://issues.apache.org/jira/browse/HTTPCLIENT-606 > Project: HttpComponents HttpClient > Issue Type: Bug > Components: HttpClient > Affects Versions: 3.0.1 > Environment: Windows XP , JDK 1.5.0_09, Intel plattform > Reporter: samuel sanchez > Priority: Minor > Fix For: 3.1 Final > > Attachments: httpmethoddir.patch, patch.txt > > > When HttpMethodDirector handles the case of redirecting the incoming conn= ection to the location specified in the header of the http caller method, i= f this location has any "special" charset encoding (extended charsets like = ISO 8859-1,etc.) the redirection fails this way: > dd-MMM-YYYY hh:mm:ss org.apache.commons.httpclient.HttpMethodDirector pro= cessRedirectResponse > WARNING: Redirected location 'http://www.anyCharsetEncodedUrl.ko' is malf= ormed > You can test it using this class: > public class SimpleHttpTestNotWorking { > =09public static int urlStatus(String pUrl) throws org.apache.commons.htt= pclient.HttpException,java.io.IOException{ > =09=09org.apache.commons.httpclient.HttpClient client =3D new org.apache.= commons.httpclient.HttpClient(); > =09=09org.apache.commons.httpclient.HttpMethod method =3D new org.apache.= commons.httpclient.methods.GetMethod(pUrl); > =09=09return client.executeMethod(method); > =09} > =09=09 > =09public static void main(String[] args) { > =09=09try{ > =09=09=09String url =3D "http://www.dipualba.es/municipios/F%E9rez"; //kn= own problematic URL > =09=09=09System.out.println("Return code for ["+url+"]: "+SimpleHttpTestW= orking.urlStatus(url)); > =09=09}catch(Exception e){ > =09=09=09e.printStackTrace(); > =09=09} > =09} > } > What I've done to solve it for my particular case has been: > 1) In the requester side, I've modified the calling: > public class SimpleHttpTestWorking { > =09public static int urlStatus(String pUrl) throws org.apache.commons.htt= pclient.HttpException,java.io.IOException{ > =09=09org.apache.commons.httpclient.HttpClient client =3D new org.apache.= commons.httpclient.HttpClient(); > =09=09org.apache.commons.httpclient.HttpMethod method; > =09 String encoding =3D (String)client.getParams().getParameter("http.= protocol.content-charset"); > =09 client.getParams().setParameter("http.protocol.element-charset", e= ncoding); > =09 try{ > =09 =09method =3D new org.apache.commons.httpclient.methods.GetMethod(= pUrl); > =09 }catch(IllegalArgumentException iae){ > =09=09 try{ > =09=09 =09org.apache.commons.httpclient.URI uri =3D new org.apache.com= mons.httpclient.URI(pUrl,true); > =09=09 =09method =3D new org.apache.commons.httpclient.methods.GetMeth= od(uri.getURI()); > =09=09 }catch(org.apache.commons.httpclient.URIException ue){ > =09=09 =09org.apache.commons.httpclient.URI uri =3D new org.apache.com= mons.httpclient.URI(pUrl,false,encoding); > =09=09=09 method =3D new org.apache.commons.httpclient.methods.GetMeth= od(uri.getEscapedURI()); > =09=09 }=09=09 =09 > =09 }=09=09 > =09=09return client.executeMethod(method); > =09} > =09=09=09 > =09public static void main(String[] args) { > =09=09try{ > =09=09=09String url =3D "http://www.dipualba.es/municipios/F=C3=A9rez"; /= /the same problematic URL > =09=09=09System.out.println("Return code for ["+url+"]: "+SimpleHttpTestW= orking.urlStatus(url)); > =09=09}catch(Exception e){ > =09=09=09e.printStackTrace(); > =09=09} > =09} > } > 2) In org.apache.commons.httpclient.HttpMethodDirector.processRedirectRes= ponse(HttpMethod method) , I've replaced > ... > redirectUri =3D new URI(location, true); > ... > for the following code: > ... > /* > * [2006-11-14]=20 > * Handles redirections to encoded URI locations=20 > * (only if URI and Connection encoding charset has been properly setted) > * */=20 > try{ > =09redirectUri =3D new URI(location, true); > }catch(URIException ue){ > =09Object encoding =3D this.conn.getParams().getParameter("http.protocol.= element-charset"); > =09if(encoding !=3D null){ > =09=09redirectUri =3D new URI(location, false, (String)encoding); > =09}else{ > =09=09throw ue; > =09} > } > ... > Hope it helps! --=20 This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: htt= p://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira --------------------------------------------------------------------- To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org