[jboss-jira] [JBoss JIRA] (AS7-6249) ServletContext.getResource() doesn't work correctly for files containing hash characters

Christian Kaltepoth (JIRA) jira-events at lists.jboss.org
Mon Dec 24 09:55:08 EST 2012


     [ https://issues.jboss.org/browse/AS7-6249?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Christian Kaltepoth updated AS7-6249:
-------------------------------------

    Steps to Reproduce: 
Deploy the attached sample project to JBoss AS 7.1.3.Final. A ServletContextListener will try to load a problematic file and print the results to the console. The console will show something like this:

{code}
15:34:00,036 INFO  [stdout] (MSC service thread 1-2) =============================================================
15:34:00,039 INFO  [stdout] (MSC service thread 1-2) url.toString():   jndi:/default-host/tomcat-url-bug/file#1.txt
15:34:00,040 INFO  [stdout] (MSC service thread 1-2) url.getPath():    /default-host/tomcat-url-bug/file
15:34:00,040 INFO  [stdout] (MSC service thread 1-2) url.getRef():     1.txt
15:34:00,041 INFO  [stdout] (MSC service thread 1-2) url.openStream(): java.io.FileNotFoundException
15:34:00,042 INFO  [stdout] (MSC service thread 1-2) =============================================================
{code}

Expected output:

{code}
15:34:10,382 INFO  [stdout] (MSC service thread 1-1) =============================================================
15:34:10,383 INFO  [stdout] (MSC service thread 1-1) url.toString():   jndi:/default-host/tomcat-url-bug/file%231.txt
15:34:10,383 INFO  [stdout] (MSC service thread 1-1) url.getPath():    /default-host/tomcat-url-bug/file%231.txt
15:34:10,384 INFO  [stdout] (MSC service thread 1-1) url.getRef():     null
15:34:10,384 INFO  [stdout] (MSC service thread 1-1) url.openStream(): SUCCESS
15:34:10,385 INFO  [stdout] (MSC service thread 1-1) =============================================================
{code}

Note: {{#}} has to be encoded as {{%23}}.

  was:
Deploy the attached sample project to JBoss AS 7.1.3.Final. A ServletContextListener will try to load a problematic file and print the results to the console. The console will show something like this:

{code}
15:34:00,036 INFO  [stdout] (MSC service thread 1-2) =============================================================
15:34:00,039 INFO  [stdout] (MSC service thread 1-2) url.toString():   jndi:/default-host/tomcat-url-bug/file#1.txt
15:34:00,040 INFO  [stdout] (MSC service thread 1-2) url.getPath():    /default-host/tomcat-url-bug/file
15:34:00,040 INFO  [stdout] (MSC service thread 1-2) url.getRef():     1.txt
15:34:00,041 INFO  [stdout] (MSC service thread 1-2) url.openStream(): java.io.FileNotFoundException
15:34:00,042 INFO  [stdout] (MSC service thread 1-2) =============================================================
{code}

Expected output:

{code}
15:34:10,382 INFO  [stdout] (MSC service thread 1-1) =============================================================
15:34:10,383 INFO  [stdout] (MSC service thread 1-1) url.toString():   jndi:/default-host/tomcat-url-bug/file%231.txt
15:34:10,383 INFO  [stdout] (MSC service thread 1-1) url.getPath():    /default-host/tomcat-url-bug/file%231.txt
15:34:10,384 INFO  [stdout] (MSC service thread 1-1) url.getRef():     null
15:34:10,384 INFO  [stdout] (MSC service thread 1-1) url.openStream(): SUCCESS
15:34:10,385 INFO  [stdout] (MSC service thread 1-1) =============================================================
{code}



    
> ServletContext.getResource() doesn't work correctly for files containing hash characters
> ----------------------------------------------------------------------------------------
>
>                 Key: AS7-6249
>                 URL: https://issues.jboss.org/browse/AS7-6249
>             Project: Application Server 7
>          Issue Type: Bug
>          Components: Web
>    Affects Versions: 7.1.3.Final (EAP)
>         Environment: Linux 3.2.0-30-generic Ubuntu SMP x86_64 GNU/Linux
>            Reporter: Christian Kaltepoth
>            Assignee: Remy Maucherat
>         Attachments: as7-url-bug.zip
>
>
> {{ServletContext.getResource()}} returns an invalid URL if the file name contains {{#}} characters.
> Example:
> {code:java}
> URL url = servletContext.getResource("/file#1.txt");
> {code}
> The resulting URL object will be spitted at the {{#}} character like this:
> {code}
> url.toString():   jndi:/default-host/tomcat-url-bug/file#1.txt
> url.getPath():    /default-host/tomcat-url-bug/file
> url.getRef():     1.txt
> {code}
> Calling {{url.openStream()}} will throw a {{FileNotFoundException}}.
> This is a known Tomcat issue fixed in 7.0.28.
> References:
> https://issues.apache.org/bugzilla/show_bug.cgi?id=53257
> https://issues.apache.org/bugzilla/show_bug.cgi?id=51584
> According to the discussion on the Tomcat issue tracker, there are also problems for other characters which have special meaning in URLs.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira


More information about the jboss-jira mailing list