src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java

changeset 53
6a8498291606
parent 47
57cfb94ab99f
child 54
77e01cda5a40
     1.1 --- a/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Sat May 16 15:11:07 2020 +0200
     1.2 +++ b/src/main/java/de/uapcore/lightpit/AbstractLightPITServlet.java	Sat May 16 15:45:06 2020 +0200
     1.3 @@ -324,13 +324,28 @@
     1.4          }
     1.5  
     1.6          // set some internal request attributes
     1.7 +        final String fullPath = Functions.fullPath(req);
     1.8          req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req));
     1.9 -        req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req));
    1.10 +        req.setAttribute(Constants.REQ_ATTR_PATH, fullPath);
    1.11          Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy));
    1.12  
    1.13 +        // if this is an error path, bypass the normal flow
    1.14 +        if (fullPath.startsWith("/error/")) {
    1.15 +            final var mapping = findMapping(method, req);
    1.16 +            if (mapping.isPresent()) {
    1.17 +                forwardAsSpecified(invokeMapping(mapping.get(), req, resp, null), req, resp);
    1.18 +            }
    1.19 +            return;
    1.20 +        }
    1.21 +
    1.22          // obtain a connection and create the data access objects
    1.23          final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME);
    1.24 -        try (final var connection = db.getDataSource().getConnection()) {
    1.25 +        final var ds = db.getDataSource();
    1.26 +        if (ds == null) {
    1.27 +            resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "JNDI DataSource lookup failed. See log for details.");
    1.28 +            return;
    1.29 +        }
    1.30 +        try (final var connection = ds.getConnection()) {
    1.31              final var dao = createDataAccessObjects(connection);
    1.32              try {
    1.33                  connection.setAutoCommit(false);

mercurial