[jira] Created: (VFS-194) Redirect of HTTP url using the header location

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (VFS-194) Redirect of HTTP url using the header location

JIRA jira@apache.org
Redirect of HTTP url using the header location
----------------------------------------------

                 Key: VFS-194
                 URL: https://issues.apache.org/jira/browse/VFS-194
             Project: Commons VFS
          Issue Type: Wish
         Environment: Windows XP/Linux/FreeBSD
            Reporter: Yves Zoundi


The http provider classes don't test the header location before resolving a file. If the redirection is reported as invalid by commons-httpclient, then the HttpFileObject is not resolved. Here is how to fix it in all the http provider implementation classes.


          int status = 0;//client.executeMethod(method);
            try{
                                status = client.executeMethod(method);
                                System.out.println("method executed");
                        }
                        catch(Exception e){
                                System.out.println("Exception co");
                                try{
                                        HostConfiguration config = client.getHostConfiguration();
                                        Header header = method.getResponseHeader("Location");
                                        System.out.println("Checking header");
                                        if (header != null) {
                                                 
                        String redirectUrl = header.getValue();  
                        config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
                        client.setHostConfiguration(config);
                        status = client.executeMethod(method);
                   
                                        }
                                }
                                catch(Exception err){
                                        throw new Exception(err);
                                }
                               
                        }
                         if ((status  >= 300) && (status < 400)) {
try{
                                        HostConfiguration config = client.getHostConfiguration();
                                        Header header = method.getResponseHeader("Location");
                                        if (header != null) {
                                                 
                        String redirectUrl = header.getValue();  
                                                method = new HeadMethod();
                                                 setupMethod(method);
                        config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
                        client.setHostConfiguration(config);
                        status = client.executeMethod(method);
                   
                                        }
                                }
                                catch(Exception err){
                                        throw new Exception(err);
                                }
                         }
 method.releaseConnection();
        if (status == HttpURLConnection.HTTP_OK)
        {
            return FileType.FILE;
        }
        else if (status == HttpURLConnection.HTTP_NOT_FOUND
            || status == HttpURLConnection.HTTP_GONE)
        {
            return FileType.IMAGINARY;
        }
        else
        {
            throw new FileSystemException("vfs.provider.http/head.error", getName());
        }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (VFS-194) Redirect of HTTP url using the header location

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/VFS-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12561011#action_12561011 ]

Mario Ivankovits commented on VFS-194:
--------------------------------------

could you attach a "svn diff" with the whole patch please.

Thanks!
Mario

> Redirect of HTTP url using the header location
> ----------------------------------------------
>
>                 Key: VFS-194
>                 URL: https://issues.apache.org/jira/browse/VFS-194
>             Project: Commons VFS
>          Issue Type: Wish
>         Environment: Windows XP/Linux/FreeBSD
>            Reporter: Yves Zoundi
>
> The http provider classes don't test the header location before resolving a file. If the redirection is reported as invalid by commons-httpclient, then the HttpFileObject is not resolved. Here is how to fix it in all the http provider implementation classes.
>           int status = 0;//client.executeMethod(method);
>             try{
> status = client.executeMethod(method);
> System.out.println("method executed");
> }
> catch(Exception e){
> System.out.println("Exception co");
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> System.out.println("Checking header");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
>
> }
> if ((status  >= 300) && (status < 400)) {
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
> method = new HeadMethod();
> setupMethod(method);
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
> }
>  method.releaseConnection();
>         if (status == HttpURLConnection.HTTP_OK)
>         {
>             return FileType.FILE;
>         }
>         else if (status == HttpURLConnection.HTTP_NOT_FOUND
>             || status == HttpURLConnection.HTTP_GONE)
>         {
>             return FileType.IMAGINARY;
>         }
>         else
>         {
>             throw new FileSystemException("vfs.provider.http/head.error", getName());
>         }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (VFS-194) Redirect of HTTP url using the header location

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/VFS-194?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Yves Zoundi updated VFS-194:
----------------------------

    Attachment: svn.diff

Here is a patch for the http provider. I added a check for URL redirections.

> Redirect of HTTP url using the header location
> ----------------------------------------------
>
>                 Key: VFS-194
>                 URL: https://issues.apache.org/jira/browse/VFS-194
>             Project: Commons VFS
>          Issue Type: Wish
>         Environment: Windows XP/Linux/FreeBSD
>            Reporter: Yves Zoundi
>         Attachments: svn.diff
>
>
> The http provider classes don't test the header location before resolving a file. If the redirection is reported as invalid by commons-httpclient, then the HttpFileObject is not resolved. Here is how to fix it in all the http provider implementation classes.
>           int status = 0;//client.executeMethod(method);
>             try{
> status = client.executeMethod(method);
> System.out.println("method executed");
> }
> catch(Exception e){
> System.out.println("Exception co");
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> System.out.println("Checking header");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
>
> }
> if ((status  >= 300) && (status < 400)) {
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
> method = new HeadMethod();
> setupMethod(method);
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
> }
>  method.releaseConnection();
>         if (status == HttpURLConnection.HTTP_OK)
>         {
>             return FileType.FILE;
>         }
>         else if (status == HttpURLConnection.HTTP_NOT_FOUND
>             || status == HttpURLConnection.HTTP_GONE)
>         {
>             return FileType.IMAGINARY;
>         }
>         else
>         {
>             throw new FileSystemException("vfs.provider.http/head.error", getName());
>         }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Issue Comment Edited: (VFS-194) Redirect of HTTP url using the header location

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/VFS-194?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12561167#action_12561167 ]

mrcheeks edited comment on VFS-194 at 1/21/08 3:38 PM:
----------------------------------------------------------

Here is a patch for the http provider. I added a check for URL redirections. The patch is attached in the initial post. I used Windows, I hope it is not an issue with charsets, etc.

      was (Author: mrcheeks):
    Here is a patch for the http provider. I added a check for URL redirections.
 

> Redirect of HTTP url using the header location
> ----------------------------------------------
>
>                 Key: VFS-194
>                 URL: https://issues.apache.org/jira/browse/VFS-194
>             Project: Commons VFS
>          Issue Type: Wish
>         Environment: Windows XP/Linux/FreeBSD
>            Reporter: Yves Zoundi
>         Attachments: svn.diff
>
>
> The http provider classes don't test the header location before resolving a file. If the redirection is reported as invalid by commons-httpclient, then the HttpFileObject is not resolved. Here is how to fix it in all the http provider implementation classes.
>           int status = 0;//client.executeMethod(method);
>             try{
> status = client.executeMethod(method);
> System.out.println("method executed");
> }
> catch(Exception e){
> System.out.println("Exception co");
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> System.out.println("Checking header");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
>
> }
> if ((status  >= 300) && (status < 400)) {
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
> method = new HeadMethod();
> setupMethod(method);
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
> }
>  method.releaseConnection();
>         if (status == HttpURLConnection.HTTP_OK)
>         {
>             return FileType.FILE;
>         }
>         else if (status == HttpURLConnection.HTTP_NOT_FOUND
>             || status == HttpURLConnection.HTTP_GONE)
>         {
>             return FileType.IMAGINARY;
>         }
>         else
>         {
>             throw new FileSystemException("vfs.provider.http/head.error", getName());
>         }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (VFS-194) Redirect of HTTP url using the header location

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/VFS-194?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Yves Zoundi resolved VFS-194.
-----------------------------

    Resolution: Fixed

Issue resolved with the patch

> Redirect of HTTP url using the header location
> ----------------------------------------------
>
>                 Key: VFS-194
>                 URL: https://issues.apache.org/jira/browse/VFS-194
>             Project: Commons VFS
>          Issue Type: Wish
>         Environment: Windows XP/Linux/FreeBSD
>            Reporter: Yves Zoundi
>         Attachments: svn.diff
>
>
> The http provider classes don't test the header location before resolving a file. If the redirection is reported as invalid by commons-httpclient, then the HttpFileObject is not resolved. Here is how to fix it in all the http provider implementation classes.
>           int status = 0;//client.executeMethod(method);
>             try{
> status = client.executeMethod(method);
> System.out.println("method executed");
> }
> catch(Exception e){
> System.out.println("Exception co");
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> System.out.println("Checking header");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
>
> }
> if ((status  >= 300) && (status < 400)) {
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
> method = new HeadMethod();
> setupMethod(method);
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
> }
>  method.releaseConnection();
>         if (status == HttpURLConnection.HTTP_OK)
>         {
>             return FileType.FILE;
>         }
>         else if (status == HttpURLConnection.HTTP_NOT_FOUND
>             || status == HttpURLConnection.HTTP_GONE)
>         {
>             return FileType.IMAGINARY;
>         }
>         else
>         {
>             throw new FileSystemException("vfs.provider.http/head.error", getName());
>         }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Reopened: (VFS-194) Redirect of HTTP url using the header location

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

     [ https://issues.apache.org/jira/browse/VFS-194?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Simon Kitching reopened VFS-194:
--------------------------------


Yves, the "fixed" and "resolved" status for an issue is only meant to be set by developers after they have actually changed the code in svn.

When you attach a patch to an issue, you just leave it as "open".

> Redirect of HTTP url using the header location
> ----------------------------------------------
>
>                 Key: VFS-194
>                 URL: https://issues.apache.org/jira/browse/VFS-194
>             Project: Commons VFS
>          Issue Type: Wish
>         Environment: Windows XP/Linux/FreeBSD
>            Reporter: Yves Zoundi
>         Attachments: svn.diff
>
>
> The http provider classes don't test the header location before resolving a file. If the redirection is reported as invalid by commons-httpclient, then the HttpFileObject is not resolved. Here is how to fix it in all the http provider implementation classes.
>           int status = 0;//client.executeMethod(method);
>             try{
> status = client.executeMethod(method);
> System.out.println("method executed");
> }
> catch(Exception e){
> System.out.println("Exception co");
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> System.out.println("Checking header");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
>
> }
> if ((status  >= 300) && (status < 400)) {
> try{
> HostConfiguration config = client.getHostConfiguration();
> Header header = method.getResponseHeader("Location");
> if (header != null) {
>
>                         String redirectUrl = header.getValue();  
> method = new HeadMethod();
> setupMethod(method);
>                         config.setHost(new java.net.URL(redirectUrl).getHost(), config.getPort(), config.getProtocol());
>                         client.setHostConfiguration(config);
>                         status = client.executeMethod(method);
>                    
> }
> }
> catch(Exception err){
> throw new Exception(err);
> }
> }
>  method.releaseConnection();
>         if (status == HttpURLConnection.HTTP_OK)
>         {
>             return FileType.FILE;
>         }
>         else if (status == HttpURLConnection.HTTP_NOT_FOUND
>             || status == HttpURLConnection.HTTP_GONE)
>         {
>             return FileType.IMAGINARY;
>         }
>         else
>         {
>             throw new FileSystemException("vfs.provider.http/head.error", getName());
>         }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.