john_brinnand
Mar 27th, 2007, 01:02 PM
H,
The ever present problem of accessing web resources in a test environment and how to solve it. It appears that XmlWebApplicationContext has a getResourceByPath(...) method. And some folks have over-ridden this in a test environment to access resources using FileSystemResource(...) class. Here is the code:
ctx = new XmlWebApplicationContext(){
protected Resource getResourceByPath(String path)
if (path.startsWith("classpath:")) {
return super.getResourceByPath(path);
}
if (path != null && path.startsWith("/WEB-INF")) {
path = scheme + basePath + WEBINF "/asi-tiles-config.xml";
}
log.info("Returning the path:" + path);
return new FileSystemResource(path);
}
};
When this code is run, the getResourceByPath(..) never appears to be invoked.
So, short of always fiddling with the CLASSPATH and writing another ClassLoader, is there a way to extend XmlWebApplicationContext so that resources can be accessed uniformly in a test environment.
Thanks in advance for any help,
John
The ever present problem of accessing web resources in a test environment and how to solve it. It appears that XmlWebApplicationContext has a getResourceByPath(...) method. And some folks have over-ridden this in a test environment to access resources using FileSystemResource(...) class. Here is the code:
ctx = new XmlWebApplicationContext(){
protected Resource getResourceByPath(String path)
if (path.startsWith("classpath:")) {
return super.getResourceByPath(path);
}
if (path != null && path.startsWith("/WEB-INF")) {
path = scheme + basePath + WEBINF "/asi-tiles-config.xml";
}
log.info("Returning the path:" + path);
return new FileSystemResource(path);
}
};
When this code is run, the getResourceByPath(..) never appears to be invoked.
So, short of always fiddling with the CLASSPATH and writing another ClassLoader, is there a way to extend XmlWebApplicationContext so that resources can be accessed uniformly in a test environment.
Thanks in advance for any help,
John