You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Daniel Bergholm (JIRA)" <ji...@apache.org> on 2012/06/29 14:48:42 UTC

[jira] [Created] (VFS-426) HTTP URL query string not part of cache key

Daniel Bergholm created VFS-426:
-----------------------------------

             Summary: HTTP URL query string not part of cache key
                 Key: VFS-426
                 URL: https://issues.apache.org/jira/browse/VFS-426
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 2.0
            Reporter: Daniel Bergholm


I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).

I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

RE: [jira] [Created] (VFS-426) HTTP URL query string not part of cache key

Posted by Gary Gregory <GG...@rocketsoftware.com>.
Hi Daniel ,

Can you bottle that up in a unit test or a sample class?

Thank you,
Gary

-----Original Message-----
From: Daniel Bergholm (JIRA) [mailto:jira@apache.org] 
Sent: Friday, June 29, 2012 8:49 AM
To: issues@commons.apache.org
Subject: [jira] [Created] (VFS-426) HTTP URL query string not part of cache key

Daniel Bergholm created VFS-426:
-----------------------------------

             Summary: HTTP URL query string not part of cache key
                 Key: VFS-426
                 URL: https://issues.apache.org/jira/browse/VFS-426
             Project: Commons VFS
          Issue Type: Bug
    Affects Versions: 2.0
            Reporter: Daniel Bergholm


I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).

I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (VFS-426) HTTP URL query string not part of cache key

Posted by "Daniel Bergholm (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13404167#comment-13404167 ] 

Daniel Bergholm commented on VFS-426:
-------------------------------------

Certainly:
{code:java}
@Test
public void shouldResolveUrls() throws FileSystemException {
        String firstUrl = "http://commons.apache.org/vfs";
        String secondUrl = "http://commons.apache.org/vfs?query=string";

        FileSystemManager fileSystemManager = VFS.getManager();

        FileObject firstResult = fileSystemManager.resolveFile(firstUrl);
        assertEquals(firstUrl, firstResult.getURL().toExternalForm());

        FileObject secondResult = fileSystemManager.resolveFile(secondUrl);
        assertEquals(secondUrl, secondResult.getURL().toExternalForm()); // fails
}{code}
                
> HTTP URL query string not part of cache key
> -------------------------------------------
>
>                 Key: VFS-426
>                 URL: https://issues.apache.org/jira/browse/VFS-426
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Daniel Bergholm
>
> I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).
> I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (VFS-426) HTTP URL query string not part of cache key

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13404493#comment-13404493 ] 

Gary D. Gregory commented on VFS-426:
-------------------------------------

I added the following test case to illustrate the issue:

org.apache.commons.vfs2.provider.http.test.HttpFilesCacheTestCase

Changing {{org.apache.commons.vfs2.provider.AbstractFileName#getKey(}} to:

{code:java}
    private String getKey()
    {
        if (key == null)
        {
            key = createURI();
        }
        return key;
    }
{code}


or better:

{code:java}
    private String getKey()
    {
        if (key == null)
        {
            key = getURI();
        }
        return key;
    }
{code}

does work for the new test case and no other test fails.

Note that this can make the {{key}} and the {{uri}} ivars the same depending on the implementation of {{createURI()}}.

*Does anyone see a problem with this?*

*I'll wait a day or so for comments before committing.*


                
> HTTP URL query string not part of cache key
> -------------------------------------------
>
>                 Key: VFS-426
>                 URL: https://issues.apache.org/jira/browse/VFS-426
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Daniel Bergholm
>
> I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).
> I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Updated] (VFS-426) HTTP URL query string not part of cache key

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/VFS-426?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory updated VFS-426:
--------------------------------

    Attachment: vfs-426.diff

Proposed fix and test.
                
> HTTP URL query string not part of cache key
> -------------------------------------------
>
>                 Key: VFS-426
>                 URL: https://issues.apache.org/jira/browse/VFS-426
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Daniel Bergholm
>         Attachments: vfs-426.diff
>
>
> I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).
> I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Resolved] (VFS-426) HTTP URL query string not part of cache key

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/VFS-426?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gary D. Gregory resolved VFS-426.
---------------------------------

       Resolution: Fixed
    Fix Version/s: 2.1

commit -m "[VFS-426] HTTP URL query string not part of cache key " C:/svn/org/apache/commons/trunks-proper/vfs/src/changes/changes.xml C:/svn/org/apache/commons/trunks-proper/vfs/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpFilesCacheTestCase.java C:/svn/org/apache/commons/trunks-proper/vfs/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java
    Sending        C:/svn/org/apache/commons/trunks-proper/vfs/core/src/main/java/org/apache/commons/vfs2/provider/AbstractFileName.java
    Sending        C:/svn/org/apache/commons/trunks-proper/vfs/core/src/test/java/org/apache/commons/vfs2/provider/http/test/HttpFilesCacheTestCase.java
    Sending        C:/svn/org/apache/commons/trunks-proper/vfs/src/changes/changes.xml
    Transmitting file data ...
    Committed revision 1356923.
                
> HTTP URL query string not part of cache key
> -------------------------------------------
>
>                 Key: VFS-426
>                 URL: https://issues.apache.org/jira/browse/VFS-426
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Daniel Bergholm
>             Fix For: 2.1
>
>         Attachments: vfs-426.diff
>
>
> I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).
> I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (VFS-426) HTTP URL query string not part of cache key

Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13403962#comment-13403962 ] 

Gary D. Gregory commented on VFS-426:
-------------------------------------

Daniel,

Can you provide a unit test or example?

Thank you,
Gary
                
> HTTP URL query string not part of cache key
> -------------------------------------------
>
>                 Key: VFS-426
>                 URL: https://issues.apache.org/jira/browse/VFS-426
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Daniel Bergholm
>
> I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).
> I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (VFS-426) HTTP URL query string not part of cache key

Posted by "Daniel Bergholm (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/VFS-426?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13404228#comment-13404228 ] 

Daniel Bergholm commented on VFS-426:
-------------------------------------

My workaround is to use a FileSystemManager with a NullFilesCache (Spring bean declaration):
{code:xml}<bean id="fileSystemManager" class="org.apache.commons.vfs2.impl.StandardFileSystemManager" init-method="init" destroy-method="close">
        <property name="filesCache">
            <bean class="org.apache.commons.vfs2.cache.NullFilesCache"/>
        </property>
</bean>{code}
Of course this workaround might not be good enough in cases where the performance hit of not using a cache is a problem. 


I think a fix for this bug would be to use {{org.apache.commons.vfs2.provider.AbstractFileName#createURI}} (which is then overriden in this case by {{org.apache.commons.vfs2.provider.URLFileName#createURI()}}) when creating the key in {{org.apache.commons.vfs2.provider.AbstractFileName#getKey()}}, since the key is then used in {{org.apache.commons.vfs2.provider.AbstractFileName#equals(Object o)}} and {{org.apache.commons.vfs2.provider.AbstractFileName#hashCode()}}, which are then used in cache implementations (such as HashMaps)
                
> HTTP URL query string not part of cache key
> -------------------------------------------
>
>                 Key: VFS-426
>                 URL: https://issues.apache.org/jira/browse/VFS-426
>             Project: Commons VFS
>          Issue Type: Bug
>    Affects Versions: 2.0
>            Reporter: Daniel Bergholm
>
> I am using commons-vfs amongst other things to download http files. When resolving different URLs where only the query string differs, the default cache returns the wrong URL sometimes (returning a previously accessed URL where only the query string differs).
> I think this is because the key property of URLFileName does not include the query string. The {code:java}createURI(){code} method of URLFileName does include it, but when constructing the key the {code:java}createURI(boolean useAbsolutePath, boolean usePassword){code} method of AbstractFileName is used. This method only includes the path. 

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira