56 |
56 |
57 private static final Logger LOG = LoggerFactory.getLogger(AbstractLightPITServlet.class); |
57 private static final Logger LOG = LoggerFactory.getLogger(AbstractLightPITServlet.class); |
58 |
58 |
59 private static final String SITE_JSP = Functions.jspPath("site"); |
59 private static final String SITE_JSP = Functions.jspPath("site"); |
60 |
60 |
61 /** |
|
62 * The EL proxy is necessary, because the EL resolver cannot handle annotation properties. |
|
63 */ |
|
64 private LightPITModule.ELProxy moduleInfo = null; |
|
65 |
61 |
66 @FunctionalInterface |
62 @FunctionalInterface |
67 protected interface SQLFindFunction<K, T> { |
63 protected interface SQLFindFunction<K, T> { |
68 T apply(K key) throws SQLException; |
64 T apply(K key) throws SQLException; |
69 |
65 |
99 * @return the module manager |
95 * @return the module manager |
100 */ |
96 */ |
101 protected final ModuleManager getModuleManager() { |
97 protected final ModuleManager getModuleManager() { |
102 return (ModuleManager) getServletContext().getAttribute(ModuleManager.SC_ATTR_NAME); |
98 return (ModuleManager) getServletContext().getAttribute(ModuleManager.SC_ATTR_NAME); |
103 } |
99 } |
|
100 |
|
101 /** |
|
102 * Returns the name of the resource bundle associated with this servlet. |
|
103 * @return the resource bundle base name |
|
104 */ |
|
105 protected abstract String getResourceBundleName(); |
104 |
106 |
105 |
107 |
106 /** |
108 /** |
107 * Creates a set of data access objects for the specified connection. |
109 * Creates a set of data access objects for the specified connection. |
108 * |
110 * |
148 } |
150 } |
149 } |
151 } |
150 |
152 |
151 @Override |
153 @Override |
152 public void init() throws ServletException { |
154 public void init() throws ServletException { |
153 moduleInfo = Optional.ofNullable(this.getClass().getAnnotation(LightPITModule.class)) |
155 scanForRequestMappings(); |
154 .map(LightPITModule.ELProxy::new).orElse(null); |
|
155 |
|
156 if (moduleInfo != null) { |
|
157 scanForRequestMappings(); |
|
158 } |
|
159 |
156 |
160 LOG.trace("{} initialized", getServletName()); |
157 LOG.trace("{} initialized", getServletName()); |
161 } |
158 } |
162 |
159 |
163 private void scanForRequestMappings() { |
160 private void scanForRequestMappings() { |
385 |
382 |
386 // set some internal request attributes |
383 // set some internal request attributes |
387 final String fullPath = Functions.fullPath(req); |
384 final String fullPath = Functions.fullPath(req); |
388 req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req)); |
385 req.setAttribute(Constants.REQ_ATTR_BASE_HREF, Functions.baseHref(req)); |
389 req.setAttribute(Constants.REQ_ATTR_PATH, fullPath); |
386 req.setAttribute(Constants.REQ_ATTR_PATH, fullPath); |
390 Optional.ofNullable(moduleInfo).ifPresent((proxy) -> req.setAttribute(Constants.REQ_ATTR_MODULE_INFO, proxy)); |
387 req.setAttribute(Constants.REQ_ATTR_RESOURCE_BUNDLE, getResourceBundleName()); |
391 |
388 |
392 // if this is an error path, bypass the normal flow |
389 // if this is an error path, bypass the normal flow |
393 if (fullPath.startsWith("/error/")) { |
390 if (fullPath.startsWith("/error/")) { |
394 final var mapping = findMapping(method, req); |
391 final var mapping = findMapping(method, req); |
395 if (mapping.isPresent()) { |
392 if (mapping.isPresent()) { |