Bug 51644 - Unable to deploy applications with the name a#b.xml
Summary: Unable to deploy applications with the name a#b.xml
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 7.0.19
Hardware: All All
: P2 regression (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-10 10:00 UTC by Suveer
Modified: 2014-02-17 13:53 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Suveer 2011-08-10 10:00:36 UTC
When I try to deploy a context with the name "a#b.xml" I get the following exception.


SEVERE: Unable to process JNDI URL [jndi:/localhost/sample/one/WEB-INF/classes]
for annotations
java.io.FileNotFoundException: jndi:/localhost/sample/one/WEB-INF/classes
        at org.apache.naming.resources.DirContextURLConnection.list(DirContextUR
LConnection.java:452)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJndi(Cont
extConfig.java:1901)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(Conte
xtConfig.java:1828)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.jav
a:1295)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfi
g.java:896)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfi
g.java:322)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBa
se.java:89)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContex
t.java:5103)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase
.java:812)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:78
7)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:607)

        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.ja
va:633)
        at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.j
ava:558)
        at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:468
)
        at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1363)
        at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java
:294)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecycl
eSupport.java:119)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBa
se.java:89)
        at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBas
e.java:1233)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.p
rocessChildren(ContainerBase.java:1391)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.p
rocessChildren(ContainerBase.java:1401)
        at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.r
un(ContainerBase.java:1380)
        at java.lang.Thread.run(Thread.java:619)


I would have expected the application to be available in the URI a/b. The bug seems to be in the "list()" method "of DirContextURLConnection.java. The method assumes that context name does not have any "/" characters in it. See the developer note just before the "if" block. I have added the "else if" condition that seems to have solved the problem for me.

            try {
                String file = getURL().getFile();
                // This will be of the form /<hostname>/<contextpath>/file name
                // if <contextpath> is not empty otherwise this will be of the
                // form /<hostname>/file name
                // Strip off the hostname and the contextpath
                int start;
                if(context instanceof ProxyDirContext &&
                        "".equals(((ProxyDirContext)context).getContextPath())){
                    start = file.indexOf('/',1);
                }
                else if(context instanceof ProxyDirContext){
                	start="/".length()
                			+((ProxyDirContext)context).getHostName().length()
                			+((ProxyDirContext)context).getContextPath().length();
                	/*
                	 * Seems like a bug in Tomcat. below was the code in Tomcat.
                	 * How can it handle contextpath like "/sample/one". It cannot
                	 */
                    //start = file.indexOf('/', file.indexOf('/', 1) + 1);
                } else
                	start = file.indexOf('/', file.indexOf('/', 1) + 1);
                
                NamingEnumeration<NameClassPair> enumeration =
                    context.list(file.substring(start));
                while (enumeration.hasMoreElements()) {
                    NameClassPair ncp = enumeration.nextElement();
                    result.addElement(ncp.getName());
                }
            } catch (NamingException e) {
Comment 1 Mark Thomas 2011-08-10 18:00:49 UTC
Thanks for the report. This has been fixed in trunk and 7.0.x and will be included in 7.0.21 onwards.