Changeset 74:e5ff09208c28 in AnnotationManagerN4J for src


Ignore:
Timestamp:
Mar 12, 2014, 11:42:28 AM (10 years ago)
Author:
casties
Branch:
default
Message:

search files in webapp in WEB-INF folder.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java

    r73 r74  
    337337
    338338    /**
    339      * returns resource from path (in webapp) as InputStream.
     339     * returns resource from path as InputStream.
     340     *
     341     * Tries path in webapp first, then uses classpath loader.
     342     * Relative paths in webapp start in /WEB-INF/.
    340343     *
    341344     * @param sc
     
    348351            // no servlet context -> use class loader
    349352            ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
    350             /* Request request = new Request(Method.GET, "riap://component/ping");
    351                Response response = getContext().getClientDispatcher().handle(request);
    352                Representation repr = response.getEntity(); */
    353353        } else {
    354354            // try path in webapp first
    355             ps = sc.getResourceAsStream(path);
     355            String webPath = path;
     356            if (!webPath.startsWith("/")) {
     357                // relative path in webapp starts in WEB-INF
     358                webPath = "WEB-INF/" + webPath;
     359            }
     360            ps = sc.getResourceAsStream(webPath);
    356361            if (ps == null) {
    357362                // try as file
    358                 File pf = new File(sc.getRealPath(path));
     363                File pf = new File(sc.getRealPath(webPath));
    359364                if (pf.canRead()) {
    360365                    logger.debug("trying file for: " + pf);
     
    377382     *
    378383     * If filename starts with "/" its treated as absolute else the path is
    379      * appended to the base directory of the web-app.
     384     * appended to the /WEB-INF/ directory in the web-app.
    380385     *
    381386     * @param filename
     
    388393        if (!f.isAbsolute() && sc != null) {
    389394            // relative path -> use getRealPath to resolve in webapp
    390             filename = sc.getRealPath(filename);
     395            filename = sc.getRealPath("WEB-INF/" + filename);
    391396        }
    392397        return filename;
Note: See TracChangeset for help on using the changeset viewer.