Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] URIUtil.equalsIgnoreEncodings not working on multi-byte characters?

What you hit is an effort to determine the alias of a FileResource from the URI provided during the lookup.
https://github.com/eclipse/jetty.project/blob/jetty-9.2.10.v20150310/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java#L113

This is "best effort" approach, and is often at odds with the modern realities of the web and internationalization.

When we started the Jetty 9.3 branch (for http2) we switched from FileResource (based on java.io.File) to PathResource (based on java.nio.file) starting in Jetty 9.3
This also means a ton of these sorts of issues are no longer handled by us, but rather by built-in java classes.

We even deprecated FileResource in Jetty 9.3
https://github.com/eclipse/jetty.project/blob/master/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java#L48-L51

The PathResource exists in Jetty 9.2 as well, but its not set as default behavior.
(Note: the version in Jetty 9.2 is an earlier implementation, but works well enough.  The version in 9.3 is better, and is tested to a much higher level)

http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/util/resource/PathResource.html

You can use the new PathResource in your WebAppContext by using the .setBaseResource(Resource) method on your context.

http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/handler/ContextHandler.html#setBaseResource(org.eclipse.jetty.util.resource.Resource)

Please switch your Embedded Jetty to use context.setBaseResource(new PathResource(new File("/path/to/webapp")))
This might have the desired effect you are going after.
Another approach would be to copy the 9.3 implementation from our master branch into your project to use it.
https://github.com/eclipse/jetty.project/blob/master/jetty-util/src/main/java/org/eclipse/jetty/util/resource/PathResource.java

This should help.



--
Joakim Erdfelt <joakim@xxxxxxxxxxx>
Expert advice, services and support from from the Jetty & CometD experts

On Fri, Apr 17, 2015 at 12:51 PM, michael reiche <michael.reiche@xxxxxxxxxx> wrote:
This had been working with jetty 6.x,  when we switched to 9.2.2 it no longer worked.

I have a resource which is a file with Chinese characters in the name. Jetty encodes the file name with escaped hex characters. The chinese character   (29420) becomes %E7%8B%AC.  In new FileResource(uri) URIUtil.equalsIgnoreEncodings decodes only the first byte, and compares E7 (231) with 29420 and finds they are not equal. ( If all three encoded bytes are treated as a multi-byte character (http://tools.ietf.org/html/rfc3629), they decode to 29420.

In new FileResource(uri), when equalsIgnoreEncodings returns false, an alias is created, and therefore getResource() is subject to alias checks.  The only alias check in the ContextHandler is ApproveNonexistantDirectoryAliases - which rejects existing directories.  And the logic in the alias checks is that if there are checks, and none of them pass, getResource() returns null. So the net effect of having only ApproveNonexistantDirectoryAliases by itself, is to make anything else fail (?)


2015-04-16 16:17:37.358:WARN:oejw.WebAppContext:main: Failed startup of context o.o.@776b7fa2{/oraclediagent,file:/scratch/mreiche/view_storage/mreiche_odi_1/odi/sah/user_projects/domains/base_domain/system_components/ODI/%E7%8B%AC%E7%AB%8B%E4%BB%A3%E7%90%86/webapp/,STARTING}{file:/scratch/mreiche/view_storage/mreiche_odi_1/odi/sah/odi/agent/lib/./oraclediagent.war}
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/WEB-INF/ctx/agent.xml]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/ctx/agent.xml]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:798)
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:789)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294)
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1341)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1334)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
        at org.eclipse.jetty.server.Server.start(Server.java:380)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
        at org.eclipse.jetty.server.Server.doStart(Server.java:347)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at oracle.odi.Agent.startAgent(Agent.java:452)
        at oracle.odi.Agent.main(Agent.java:854)
Caused by:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/ctx/agent.xml]
        at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:118)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
        at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:798)
        at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)
        at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:789)
        at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294)
        at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1341)
        at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1334)
        at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:497)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
        at org.eclipse.jetty.server.Server.start(Server.java:380)
        at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
        at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
        at org.eclipse.jetty.server.Server.doStart(Server.java:347)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
        at oracle.odi.Agent.startAgent(Agent.java:452)
        at oracle.odi.Agent.main(Agent.java:854)

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top