Issue 1:
chris tam opened SPR-3250 and commented

The problem is reported by Mark Menard in Spring support forum. I have checked the source code and find out the problem come from LangNamespaceHandler "init" method. Currently the "init" method contains the following code:

...

public void init() {

registerScriptBeanDefinitionParser("groovy", GroovyScriptFactory.class);

registerScriptBeanDefinitionParser("jruby", JRubyScriptFactory.class);

registerScriptBeanDefinitionParser("bsh", BshScriptFactory.class);

}

...

The above code will throw ClassNotFoundException when either groovy, beanshell or jruby library is not found in the classpath. The DefaultNamespaceHandlerResolver will not register the "lang" namespace when "init" method throws the ClassNotFoundException. The lang namespace requires that both groovy, beanshell and jruby library must be in the classpath. Is it possible to add some checking to the init method of LangNamespaceHandler to avoid the above dependency. For example:

...

public void init() {

if (checkGroovyExists()) {

registerScriptBeanDefinitionParser("groovy", GroovyScriptFactory.class);

}

if (checkJRubyExists()) {

registerScriptBeanDefinitionParser("jruby", JRubyScriptFactory.class);

}

if (checkBshExists()) {

registerScriptBeanDefinitionParser("bsh", BshScriptFactory.class);

}

// what to do if all the above jars are not found???

}

private boolean checkGroovyExists() {

try {

Class.forName("groovy.lang.GroovyObject") ;

return true ;

} catch(Exception e) {

return false ;

}

}

private boolean checkBshExists() {

try {

Class.forName("bsh.Interpreter") ;

return true ;

} catch(Exception e) {

return false ;

}

}

private boolean checkJRubyExists() {

try {

Class.forName("org.jruby.runtime.builtin.IRubyObject") ;

return true ;

} catch(Exception e) {

return false ;

}

}

...

Thanks for all the help from spring team.

cheers

chris tam

xenium

Affects: 2.0.3

Issue Links:

#7942 Cannot find "lang" namespace handler unless all library jars are present ("is duplicated by")

#7958 NoClassDefFoundError when groovy isn't on classpath ("is duplicated by")

Issue 2:
Oliver Siegmar opened SPR-9067 and commented

Consider this configuration:

<mvc:resources mapping="/static/**" location="/WEB-INF/resources/immutable/"/>

The resource directory /WEB-INF/resources/immutable/ contains several files and subdirectories. One subdirectory is called images.

A browser request to /static/nonexistingfile.png results in a 404 HTTP error. But a request to /static/images (existing directory, without a file name specified) results in a FileNotFoundException:

java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/resources/immutable/images]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:118) ~[spring-web-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.writeContent(ResourceHttpRequestHandler.java:240) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:141) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778) ~[spring-webmvc-3.1.0.RELEASE.jar:3.1.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) ~[servlet-api.jar:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) ~[servlet-api.jar:na]

I think the getResource(HttpServletRequest) method in ResourceHttpRequestHandler should also check if the requested resources is a File.

On a high volume website this can cause tons of FileNotFoundExceptions due to robot visits. This is why I classified this issue with major priority.

Affects: 3.1 GA

Issue Links:

#13712 Spring MVC resources handler generates a 500 internal error when accessing a directory resource ("is duplicated by")

Referenced from: commits f8238f5