hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: URI.resolve() not woring properly?
Date Thu, 28 Feb 2008 14:10:55 GMT

On Thu, 2008-02-28 at 13:11 +0100, Johannes Koch wrote:
> Hi Oleg
> 
> Oleg Kalnichevski schrieb:
> > Is java.net.URI.resolve(String str) being used anywhere in HttpClient?
> 
> Yep, o.a.h..impl.client.DefaultRedirectHandler method getLocationURI.
> 
> > If so, what do you suggest we do?
> 
> Create a resolve(URI, String) method in o.a.h.client.utils.URLUtils? See 
> attached patch.
> 

Johannes,

Could you please open a JIRA ticket and attach this patch to it? You
should also select 'Grant license to ASF for inclusion in ASF works'
checkbox, if it is okay with to have this code licensed as ASLv2.    

Oleg 


> <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4708535> suggests:
> 
> Specially check for this case in invoking code,
> replace "" by "#" and then remove "#" manually later.
> (Review ID: 148122)
> 
> plain text document attachment (URIresolve_patch_20080228.txt)
> Index: C:/Dokumente und Einstellungen/Koch/Eigene Dateien/koch/opt/eclipse/workspace_p/httpclient_trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
> ===================================================================
> --- C:/Dokumente und Einstellungen/Koch/Eigene Dateien/koch/opt/eclipse/workspace_p/httpclient_trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
(revision 630775)
> +++ C:/Dokumente und Einstellungen/Koch/Eigene Dateien/koch/opt/eclipse/workspace_p/httpclient_trunk/module-client/src/main/java/org/apache/http/impl/client/DefaultRedirectHandler.java
(working copy)
> @@ -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);
>              }
> Index: C:/Dokumente und Einstellungen/Koch/Eigene Dateien/koch/opt/eclipse/workspace_p/httpclient_trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
> ===================================================================
> --- C:/Dokumente und Einstellungen/Koch/Eigene Dateien/koch/opt/eclipse/workspace_p/httpclient_trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
(revision 630775)
> +++ C:/Dokumente und Einstellungen/Koch/Eigene Dateien/koch/opt/eclipse/workspace_p/httpclient_trunk/module-client/src/main/java/org/apache/http/client/utils/URLUtils.java
(working copy)
> @@ -195,6 +195,45 @@
>      }
>      
>      /**
> +     * Resolves a URI reference aginast 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(URI baseURI, String reference)
> +    {
> +        return URLUtils.resolve(baseURI, URI.create(reference));
> +    }
> +
> +    /**
> +     * Resolves a URI reference aginast 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(URI baseURI, URI reference)
> +    {
> +        boolean emptyReference = "".equals(reference.toString());
> +        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() {
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message