[Actionframework-users] finding ActionConfig via getRealPath
Status: Inactive
Brought to you by:
ptoman
From: Mark D. A. <md...@di...> - 2002-09-16 01:57:35
|
Currently things are a bit of a mess about how to resolve unqualified paths in configuration: web.xml/ActionConfig - ActionServlet will attempt to load as File (relying on current directory), and then will attempt servlet.getClass().getResource("/" + f) (relying on classloader). WEB-INF/classes will only work if the servlet instance has a class loader from this webapp, which is not reliable (if for example the app is using ActionServlet directly and not a subclass). I have a patch below to ActionRuntime.java to make it attempt a getRealPath also. web.xml/properties - Done by Velocity. See org.apache.velocity.servlet.VelocityServlet.INIT_PROPS_KEY It tries ServletConfig.getInitParameter and ServletContext.getInitParameter. Then it does getServletContext().getRealPath(propsFile). velocity.properties/file.resource.loader.path - Massaged by actionframework, and used by velocity. In actionframework's org/actionframework/engines/velocity/VelocityServlet.java it does a getRealPath on the value. Here is a patch to ActionRuntime.java to make it do a getRealPath as well, so all three will support that: try { // support for ActionConfig reloading actionConfigFile = new File(configFilename); in = new FileInputStream(actionConfigFile); log.info("loaded '" + configFilename + "' as File"); } catch (FileNotFoundException e) { URL url = servlet.getClass().getResource("/" + configFilename); if (url == null) { String realPath = servlet.getServletContext().getRealPath(configFilename); if ( realPath == null ) { throw new FileNotFoundException("ActionConfig '" + configFilename + "' not found as file, in classpath, or as ServletContext.getRealPath"); } else { in = new FileInputStream(realPath); log.info("loaded '" + configFilename + "' via servlet getRealPath from " + realPath); } } else { actionConfigFile = new File(url.getFile()); in = new FileInputStream(actionConfigFile); log.info("loaded '" + configFilename + "' as resource from " + url.getFile()); } } -mda |