hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r632273 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt module-client/src/main/java/org/apache/http/client/utils/URLUtils.java module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
Date Fri, 29 Feb 2008 09:43:30 GMT
Author: olegk
Date: Fri Feb 29 01:43:28 2008
New Revision: 632273

URL: http://svn.apache.org/viewvc?rev=632273&view=rev
Log:
HTTPCLIENT-755: Workaround for known bugs in java.net.URI.resolve() (Bug ID: 4708535)
Contributed by Johannes Koch <johannes.koch at fit.fraunhofer.de>

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
    httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=632273&r1=632272&r2=632273&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Fri Feb 29 01:43:28 2008
@@ -1,3 +1,10 @@
+Changes since 4.0 Alpha 3
+-------------------
+
+* [HTTPCLIENT-755] Workaround for known bugs in java.net.URI.resolve()
+  Bug ID: 4708535
+  Contributed by Johannes Koch <johannes.koch at fit.fraunhofer.de>
+
 Release 4.0 Alpha 3
 -------------------
 

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java?rev=632273&r1=632272&r2=632273&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
Fri Feb 29 01:43:28 2008
@@ -195,6 +195,46 @@
     }
     
     /**
+     * Resolves a URI reference against a base URI. Work-around for bug in
+     * java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)
+     *
+     * @param baseURI the base URI
+     * @param reference the URI reference
+     * @return the resulting URI
+     */
+    public static URI resolve(final URI baseURI, final String reference) {
+        return URLUtils.resolve(baseURI, URI.create(reference));
+    }
+
+    /**
+     * Resolves a URI reference against a base URI. Work-around for bug in
+     * java.net.URI (<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535>)
+     *
+     * @param baseURI the base URI
+     * @param reference the URI reference
+     * @return the resulting URI
+     */
+    public static URI resolve(final URI baseURI, URI reference){
+        if (baseURI == null) {
+            throw new IllegalArgumentException("Base URI may nor be null");
+        }
+        if (reference == null) {
+            throw new IllegalArgumentException("Reference URI may nor be null");
+        }
+        boolean emptyReference = reference.toString().length() == 0;
+        if (emptyReference) {
+            reference = URI.create("#");
+        }
+        URI resolved = baseURI.resolve(reference);
+        if (emptyReference) {
+            String resolvedString = resolved.toString();
+            resolved = URI.create(resolvedString.substring(0,
+                resolvedString.indexOf('#')));
+        }
+        return resolved;
+    }
+
+    /**
      * This class should not be instantiated.
      */
     private URLUtils() {

Modified: httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java?rev=632273&r1=632272&r2=632273&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
(original)
+++ httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
Fri Feb 29 01:43:28 2008
@@ -138,7 +138,7 @@
             try {
                 URI requestURI = new URI(request.getRequestLine().getUri());
                 URI absoluteRequestURI = URLUtils.rewriteURI(requestURI, target, true);
-                uri = absoluteRequestURI.resolve(uri); 
+                uri = URLUtils.resolve(absoluteRequestURI, uri); 
             } catch (URISyntaxException ex) {
                 throw new ProtocolException(ex.getMessage(), ex);
             }



Mime
View raw message