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

changeset 53
6a8498291606
parent 47
57cfb94ab99f
child 54
77e01cda5a40
equal deleted inserted replaced
52:67a02e79b7a1 53:6a8498291606
322 resp.setLocale(sessionLocale); 322 resp.setLocale(sessionLocale);
323 LOG.trace("Continuing session {} with language {}", session.getId(), sessionLocale); 323 LOG.trace("Continuing session {} with language {}", session.getId(), sessionLocale);
324 } 324 }
325 325
326 // set some internal request attributes 326 // set some internal request attributes
327 final String fullPath = Functions.fullPath(req);
327 req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req)); 328 req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req));
328 req.setAttribute(Constants.REQ_ATTR_PATH, Functions.fullPath(req)); 329 req.setAttribute(Constants.REQ_ATTR_PATH, fullPath);
329 Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); 330 Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy));
331
332 // if this is an error path, bypass the normal flow
333 if (fullPath.startsWith("/error/")) {
334 final var mapping = findMapping(method, req);
335 if (mapping.isPresent()) {
336 forwardAsSpecified(invokeMapping(mapping.get(), req, resp, null), req, resp);
337 }
338 return;
339 }
330 340
331 // obtain a connection and create the data access objects 341 // obtain a connection and create the data access objects
332 final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME); 342 final var db = (DatabaseFacade) req.getServletContext().getAttribute(DatabaseFacade.SC_ATTR_NAME);
333 try (final var connection = db.getDataSource().getConnection()) { 343 final var ds = db.getDataSource();
344 if (ds == null) {
345 resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "JNDI DataSource lookup failed. See log for details.");
346 return;
347 }
348 try (final var connection = ds.getConnection()) {
334 final var dao = createDataAccessObjects(connection); 349 final var dao = createDataAccessObjects(connection);
335 try { 350 try {
336 connection.setAutoCommit(false); 351 connection.setAutoCommit(false);
337 // call the handler, if available, or send an HTTP 404 error 352 // call the handler, if available, or send an HTTP 404 error
338 final var mapping = findMapping(method, req); 353 final var mapping = findMapping(method, req);

mercurial