Menu

#68 getResourcePaths not implemented

closed-fixed
5
2007-11-06
2004-12-21
Matt Raible
No

In order to use ant-style pattern matching with
Spring's ContextLoaderPlugin, the
ServletContextSimulator needs to implement
getResourcePaths(). Currently it does not:

[junit] ERROR - ContextLoaderPlugIn.init(228) |
Context initialization faile
d
[junit] java.lang.UnsupportedOperationException:
getResourcePaths operation
is not supported!
[junit] at
servletunit.ServletContextSimulator.getResourcePaths(ServletC
ontextSimulator.java:534)
[junit] at
org.springframework.web.context.support.ServletContextResourc
ePatternResolver.doRetrieveMatchingServletContextResources(ServletContextResourc
ePatternResolver.java:100)
[junit] at
org.springframework.web.context.support.ServletContextResourc
ePatternResolver.doFindPathMatchingFileResources(ServletContextResourcePatternRe
solver.java:79)
[junit] at
org.springframework.core.io.support.PathMatchingResourcePatte
rnResolver.findPathMatchingResources(PathMatchingResourcePatternResolver.java:22
8)

Here's how Spring implements it in its MockServletContext:

public Set getResourcePaths(String path) {
Resource resource =
this.resourceLoader.getResource(getResourceLocation(path));
try {
File file = resource.getFile();
String[] fileList = file.list();
String prefix = (path.endsWith("/") ? path : path +
"/");
Set resourcePaths = new HashSet(fileList.length);
for (int i = 0; i < fileList.length; i++) {
resourcePaths.add(prefix + fileList[i]);
}
return resourcePaths;
}
catch (IOException ex) {
logger.info("Couldn't get resource paths for " +
resource, ex);
return null;
}
}

A workaround is to specify each file individually in
the plugin settings.

Discussion

  • Bryan Hunt

    Bryan Hunt - 2005-02-18

    Logged In: YES
    user_id=469017

    Yep , due to this bug it is difficult to load stuff when you
    are working with WebLogic, specifically with Log4j.

    --b

     
  • Nobody/Anonymous

    Logged In: NO

    I fixed it as so .... here is my change so you can add it to cvs

    /**
    * Supported in this version ;-)
    */
    public Set getResourcePaths(String path) {

    File file = new File(this.getRealPath(path));
    String[] fileList = file.list();
    String prefix = (path.endsWith("/") ? path : path + "/");
    Set resourcePaths = new HashSet(fileList.length);
    for (int i = 0; i < fileList.length; i++) {
    resourcePaths.add(prefix + fileList[i]);
    }
    return resourcePaths;
    }

     
  • Ben Speakmon

    Ben Speakmon - 2007-11-06
    • assigned_to: nobody --> bspeakmon
    • status: open --> closed-fixed
     
  • Ben Speakmon

    Ben Speakmon - 2007-11-06

    Logged In: YES
    user_id=1909584
    Originator: NO

    Fixed in latest trunk; thanks for the patch.

     

Log in to post a comment.