cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leszek Gawron (JIRA)" <>
Subject [jira] [Created] (COCOON-2353) Cocoon 2.2 in servlet 3.0 environment fails to initialize when webjars present on classpath.
Date Wed, 28 Sep 2016 09:16:20 GMT
Leszek Gawron created COCOON-2353:

             Summary: Cocoon 2.2 in servlet 3.0 environment fails to initialize when webjars
present on classpath.
                 Key: COCOON-2353
             Project: Cocoon
          Issue Type: Bug
          Components: * Cocoon Core
    Affects Versions: 2.2
            Reporter: Leszek Gawron

 have found a problem that prevents deploying cocoon to 3.0 containers if the webapp contains
webjars - by webjar I mean a jar containing META-INF/resources folder which is specially treated
by sevlet container (the resources from that folder are served by container itself bypassing
any webapp setup).

This happens on jetty 9.x. No matter if I set webapp to be 2.5 servlet compliant or 3.0.
Does not happen on jetty 8 which is ancient as of now.

I try running my app in embedded Jetty 9 - it works - as long as there is no actual .war -
there is no scanning for META-INF resources.

As soon as I build a war this is how a configured context looks like:

startup of context o.e.j.w.WebAppContext@5bcab519{/,[


suddenly there is more than one root for static resources. 

This yields following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cocoon.Processor':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Unable to initialize Avalon component with role org.apache.cocoon.Processor; nested exception
is org.apache.avalon.framework.configuration.ConfigurationException: Cannot resolve context://sitemap.xmap
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(
        at org.eclipse.jetty.webapp.WebAppContext.startContext(
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(
        at org.eclipse.jetty.servlet.ServletContextHandler.doStart(
        at org.eclipse.jetty.webapp.WebAppContext.doStart(
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
        at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(
        at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(
        at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(
        at org.eclipse.jetty.deploy.DeploymentManager.addApp(
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(
        at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(
        at org.eclipse.jetty.util.Scanner.reportAddition(
        at org.eclipse.jetty.util.Scanner.reportDifferences(
        at org.eclipse.jetty.util.Scanner.scan(
        at org.eclipse.jetty.util.Scanner.doStart(
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
        at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
        at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(
        at org.eclipse.jetty.deploy.DeploymentManager.doStart(
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(
        at org.eclipse.jetty.server.Server.start(
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(
        at org.eclipse.jetty.server.Server.doStart(
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(
        at org.eclipse.jetty.xml.XmlConfiguration$
        at Method)
        at org.eclipse.jetty.xml.XmlConfiguration.main(
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.jetty.start.Main.invokeMain(
        at org.eclipse.jetty.start.Main.start(
        at org.eclipse.jetty.start.Main.main(
Caused by: org.springframework.beans.factory.BeanCreationException: Unable to initialize Avalon
component with role org.apache.cocoon.Processor; nested exception is org.apache.avalon.framework.configuration.ConfigurationException:
Cannot resolve context://sitemap.xmap
        at org.apache.cocoon.core.container.spring.avalon.AvalonBeanPostProcessor.postProcessBeforeInitialization(
        ... 54 more
Caused by: org.apache.avalon.framework.configuration.ConfigurationException: Cannot resolve
        at org.apache.cocoon.components.treeprocessor.TreeProcessor.configure(
        at org.apache.avalon.framework.container.ContainerUtil.configure(
        at org.apache.cocoon.core.container.spring.avalon.AvalonBeanPostProcessor.postProcessBeforeInitialization(
        ... 57 more
Caused by: context://sitemap.xmap could not be found. (possible
context problem)
        at org.apache.cocoon.components.source.impl.ContextSourceFactory.getSource(
        at org.apache.cocoon.components.source.CocoonSourceResolver.resolveURI(
        at org.apache.cocoon.components.source.CocoonSourceResolver.resolveURI(
        at org.apache.cocoon.components.treeprocessor.TreeProcessor.configure(
        ... 59 more

This is the problematic ContextSourceFactory code:

    public Source getSource(String location, Map parameters) throws IOException {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Creating source object for " + location);

        // Lookup resolver 
        SourceResolver resolver = null;
        try {
            resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);

            // Remove the protocol and the first '/'
            final int pos = location.indexOf(":/");
            final String scheme = location.substring(0, pos);
            final String path = location.substring(pos + 2);

            // fix for #24093, we don't give access to files outside the context:
            if (path.indexOf("../") != -1) {
                throw new MalformedURLException("Invalid path ('../' is not allowed) : " +

            URL u;

            // Try to get a file first and fall back to a resource URL
            String actualPath = this.servletContext.getRealPath(path);
            if (actualPath != null) {
                u = new File(actualPath).toURL();
            } else {
                u = this.servletContext.getResource(path);

            if (u != null) {
                Source source = resolver.resolveURI(u.toExternalForm());
                if ( parameters != null 
                     && BooleanUtils.toBoolean("force-traversable")
                     && this.servletContext != null 
                     && !(source instanceof TraversableSource) ) {
                    final Set children = this.servletContext.getResourcePaths(path + '/');
                    if ( children != null ) {
                        source = new TraversableContextSource(source, children, this, path,
                return source;                

            final String message = location + " could not be found. (possible context problem)";
            throw new MalformedURLException(message);
        } catch (ServiceException se) {
            throw new SourceException("Unable to lookup source resolver.", se);
        } finally {

If I use jetty 8
String actualPath = this.servletContext.getRealPath(path); 

never returns null - even if the path we ask for does not exist.

If I use jetty 9:
- if there is a single resource root (webapp directory) and no webjars - the path is returned

- if there is a multi resource setup (with webjars) - every webjar is scanned for sitemap.xmap
resource. The resource is nowhere to be found - null is returned which by jetty/servlet spec
api docs is a PROPER response.

if the path is null ContextSourceFactory falls back to:

 u = this.servletContext.getResource(path);

... which is also null in this problematic case. 

This response is also valid by ServletContext spec.

This message was sent by Atlassian JIRA

View raw message