Return-Path: Mailing-List: contact commons-httpclient-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list commons-httpclient-dev@jakarta.apache.org Received: (qmail 14205 invoked by uid 98); 12 Jan 2003 18:16:50 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 14185 invoked from network); 12 Jan 2003 18:16:48 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 12 Jan 2003 18:16:48 -0000 Received: (qmail 67217 invoked by uid 500); 12 Jan 2003 18:15:25 -0000 Received: (qmail 67208 invoked from network); 12 Jan 2003 18:15:24 -0000 Received: from mxout1.cac.washington.edu (140.142.32.134) by daedalus.apache.org with SMTP; 12 Jan 2003 18:15:24 -0000 Received: from smtp.washington.edu (smtp.washington.edu [140.142.33.9]) by mxout1.cac.washington.edu (8.12.1+UW01.12/8.12.1+UW02.12) with ESMTP id h0CIFRUR021004 for ; Sun, 12 Jan 2003 10:15:27 -0800 Received: from u.washington.edu (pool-129-44-177-64.bos.east.verizon.net [129.44.177.64]) (authenticated bits=0) by smtp.washington.edu (8.12.1+UW01.12/8.12.1+UW02.12) with ESMTP id h0CIFPEn006010 (version=TLSv1/SSLv3 cipher=DES-CBC3-SHA bits=168 verify=NOT) for ; Sun, 12 Jan 2003 10:15:27 -0800 Date: Sun, 12 Jan 2003 13:15:26 -0500 Mime-Version: 1.0 (Apple Message framework v551) Content-Type: multipart/mixed; boundary=Apple-Mail-4--336383273 Subject: [PATCH]HttpMethodBase URI parse From: Michael Becke To: Commons Project Message-Id: X-Mailer: Apple Mail (2.551) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N --Apple-Mail-4--336383273 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed Attached is a patch that fixes a problem with HttpMethodBase where some URIs will not be parsed correctly. The previous code was using java.net.URL to parse the String URI and would fail if the protocol was unknown to URL. Since the protocol values we use don't necessarily have to correspond to those used by URL this code has been replaced by the parsing code of URI. Enjoy, Mike --Apple-Mail-4--336383273 Content-Disposition: attachment; filename=httpMethodURIParse.patch Content-Transfer-Encoding: 7bit Content-Type: application/octet-stream; x-unix-mode=0644; name="httpMethodURIParse.patch" Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.93 diff -u -r1.93 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 20 Dec 2002 09:22:07 -0000 1.93 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 12 Jan 2003 18:09:28 -0000 @@ -273,38 +273,37 @@ public HttpMethodBase(String uri) { try { - // is this an absolute URI? - URL url = new URL( uri ); + + // create a URI and allow for null/empty uri values + URI parsedURI = new URI( + uri == null || uri.equals( "" ) + ? "/" + : uri + ); + + if ( parsedURI.isAbsoluteURI() ) { + hostConfiguration = new HostConfiguration(); + hostConfiguration.setHost( + parsedURI.getHost(), + parsedURI.getPort(), + parsedURI.getScheme() + ); + } // set the path, defaulting to root setPath( - url.getPath() == null + parsedURI.getPath() == null ? "/" - : url.getPath() + : parsedURI.getPath() ); - setQueryString( url.getQuery() ); - hostConfiguration = new HostConfiguration(); - hostConfiguration.setHost( - url.getHost(), - url.getPort(), - url.getProtocol() - ); - - } catch ( MalformedURLException e ) { - // this is not a URL - int pa = uri.indexOf("?"); + setQueryString( parsedURI.getQuery() ); - if ( !uri.startsWith("/") ) { - // this path must be relative to root - uri = "/" + uri; - } + } catch ( URIException e ) { + + // this is not a valid URI + log.error( "uri is invalid: " + uri, e ); + throw new IllegalArgumentException( "uri is invalid: " + uri + ": " + e ); - if (pa < 0) { //its just a path - setPath(uri); - } else { //its a path with a query - setPath(path.substring(0, pa)); - setQueryString(uri.substring(pa+1, uri.length())); - } } } --Apple-Mail-4--336383273--