# HG changeset patch # User casties # Date 1394624548 -3600 # Node ID e5ff09208c28708668897634c2132007bf66ed54 # Parent 4b8c909cabf38222dc1b5b918f3d93150426ff84 search files in webapp in WEB-INF folder. diff -r 4b8c909cabf3 -r e5ff09208c28 src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java --- a/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Wed Mar 12 11:54:07 2014 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java Wed Mar 12 12:42:28 2014 +0100 @@ -336,7 +336,10 @@ } /** - * returns resource from path (in webapp) as InputStream. + * returns resource from path as InputStream. + * + * Tries path in webapp first, then uses classpath loader. + * Relative paths in webapp start in /WEB-INF/. * * @param sc * @param path @@ -347,15 +350,17 @@ if (sc == null) { // no servlet context -> use class loader ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); - /* Request request = new Request(Method.GET, "riap://component/ping"); - Response response = getContext().getClientDispatcher().handle(request); - Representation repr = response.getEntity(); */ } else { // try path in webapp first - ps = sc.getResourceAsStream(path); + String webPath = path; + if (!webPath.startsWith("/")) { + // relative path in webapp starts in WEB-INF + webPath = "WEB-INF/" + webPath; + } + ps = sc.getResourceAsStream(webPath); if (ps == null) { // try as file - File pf = new File(sc.getRealPath(path)); + File pf = new File(sc.getRealPath(webPath)); if (pf.canRead()) { logger.debug("trying file for: " + pf); try { @@ -376,7 +381,7 @@ * get a real file name for a web app file pathname. * * If filename starts with "/" its treated as absolute else the path is - * appended to the base directory of the web-app. + * appended to the /WEB-INF/ directory in the web-app. * * @param filename * @param sc @@ -387,7 +392,7 @@ // is the filename absolute? if (!f.isAbsolute() && sc != null) { // relative path -> use getRealPath to resolve in webapp - filename = sc.getRealPath(filename); + filename = sc.getRealPath("WEB-INF/" + filename); } return filename; }