src/main/kotlin/de/uapcore/lightpit/AbstractServlet.kt

Sun, 08 Jan 2023 17:57:05 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 08 Jan 2023 17:57:05 +0100
changeset 270
8c088c628a20
parent 254
55ca6cafc3dd
child 298
1275eb652008
permissions
-rw-r--r--

#15 add remove filter button

184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * Copyright 2021 Mike Becker. All rights reserved.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Redistribution and use in source and binary forms, with or without
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 * modification, are permitted provided that the following conditions are met:
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 *
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * 1. Redistributions of source code must retain the above copyright
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 * notice, this list of conditions and the following disclaimer.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 *
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 *
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 */
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 package de.uapcore.lightpit
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28 import de.uapcore.lightpit.DataSourceProvider.Companion.SC_ATTR_NAME
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 import de.uapcore.lightpit.dao.DataAccessObject
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30 import de.uapcore.lightpit.dao.createDataAccessObject
254
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
31 import jakarta.servlet.http.HttpServlet
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
32 import jakarta.servlet.http.HttpServletRequest
55ca6cafc3dd #233 migrate to Jakarta EE and update dependencies
Mike Becker <universe@uap-core.de>
parents: 247
diff changeset
33 import jakarta.servlet.http.HttpServletResponse
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 import java.sql.SQLException
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 import java.util.*
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
37 abstract class AbstractServlet : HttpServlet() {
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
38
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
39 protected val logger = MyLogger()
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 /**
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 * Contains the GET request mappings.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 */
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 private val getMappings = mutableMapOf<PathPattern, MappingMethod>()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 /**
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 * Contains the POST request mappings.
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 */
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49 private val postMappings = mutableMapOf<PathPattern, MappingMethod>()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 protected fun get(pattern: String, method: MappingMethod) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 getMappings[PathPattern(pattern)] = method
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 protected fun post(pattern: String, method: MappingMethod) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 postMappings[PathPattern(pattern)] = method
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 private fun notFound(http: HttpRequest, dao: DataAccessObject) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 http.response.sendError(HttpServletResponse.SC_NOT_FOUND)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 private fun findMapping(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 mappings: Map<PathPattern, MappingMethod>,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 req: HttpServletRequest
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 ): Pair<PathPattern, MappingMethod> {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 val requestPath = sanitizedRequestPath(req)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 val candidates = mappings.filter { it.key.matches(requestPath) }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 return if (candidates.isEmpty()) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 Pair(PathPattern(requestPath), ::notFound)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 } else {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 if (candidates.size > 1) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
73 logger.warn("Ambiguous mapping for request path '{0}'", requestPath)
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 candidates.entries.first().toPair()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 private fun invokeMapping(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 mapping: Pair<PathPattern, MappingMethod>,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 req: HttpServletRequest,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 resp: HttpServletResponse,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 dao: DataAccessObject
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 ) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 val params = mapping.first.obtainPathParameters(sanitizedRequestPath(req))
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 val method = mapping.second
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
87 logger.trace("invoke {0}", method)
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 method(HttpRequest(req, resp, params), dao)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 private fun sanitizedRequestPath(req: HttpServletRequest) = req.pathInfo ?: "/"
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 private fun doProcess(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 req: HttpServletRequest,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 resp: HttpServletResponse,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 mappings: Map<PathPattern, MappingMethod>
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 ) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 val session = req.session
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 // the very first thing to do is to force UTF-8
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 req.characterEncoding = "UTF-8"
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 // choose the requested language as session language (if available) or fall back to english, otherwise
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 if (session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) == null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 val availableLanguages = availableLanguages()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 val reqLocale = req.locale
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 val sessionLocale = if (availableLanguages.contains(reqLocale)) reqLocale else availableLanguages.first()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 session.setAttribute(Constants.SESSION_ATTR_LANGUAGE, sessionLocale)
208
785820da6485 fixes response locale not set for new sessions
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
109 resp.locale = sessionLocale
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
110 logger.debug(
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
111 "Setting language for new session {0}: {1}", session.id, sessionLocale.displayLanguage
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 } else {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 val sessionLocale = session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) as Locale
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115 resp.locale = sessionLocale
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
116 logger.trace("Continuing session {0} with language {1}", session.id, sessionLocale)
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 // set some internal request attributes
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 val http = HttpRequest(req, resp)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 val fullPath = req.servletPath + Optional.ofNullable(req.pathInfo).orElse("")
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 req.setAttribute(Constants.REQ_ATTR_BASE_HREF, http.baseHref)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 req.setAttribute(Constants.REQ_ATTR_PATH, fullPath)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 req.getHeader("Referer")?.let {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 // TODO: add a sanity check to avoid link injection
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 req.setAttribute(Constants.REQ_ATTR_REFERER, it)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 // if this is an error path, bypass the normal flow
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 if (fullPath.startsWith("/error/")) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 http.styleSheets = listOf("error")
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 http.render("error")
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 return
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 // obtain a connection and create the data access objects
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 val dsp = req.servletContext.getAttribute(SC_ATTR_NAME) as DataSourceProvider
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 val dialect = dsp.dialect
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 val ds = dsp.dataSource
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 if (ds == null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 resp.sendError(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 HttpServletResponse.SC_SERVICE_UNAVAILABLE,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 "JNDI DataSource lookup failed. See log for details."
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 return
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 try {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 ds.connection.use { connection ->
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 val dao = createDataAccessObject(dialect, connection)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 try {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 connection.autoCommit = false
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 invokeMapping(findMapping(mappings, req), req, resp, dao)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 connection.commit()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 } catch (ex: SQLException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
155 logger.warn("Database transaction failed (Code {0}): {1}", ex.errorCode, ex.message)
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
156 logger.debug("Details: ", ex)
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 resp.sendError(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 "Unhandled Transaction Error - Code: " + ex.errorCode
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 connection.rollback()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 } catch (ex: SQLException) {
247
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
165 logger.error("Severe Database Exception (Code {0}): {1}", ex.errorCode, ex.message)
e71ae69c68c0 remove log4j entirely
Mike Becker <universe@uap-core.de>
parents: 208
diff changeset
166 logger.debug("Details: ", ex)
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Database Error - Code: " + ex.errorCode)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 doProcess(req, resp, getMappings)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 doProcess(req, resp, postMappings)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 protected fun availableLanguages(): List<Locale> {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 val langTags = servletContext.getInitParameter(Constants.CTX_ATTR_LANGUAGES)?.split(",")?.map(String::trim) ?: emptyList()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 val locales = langTags.map(Locale::forLanguageTag).filter { it.language.isNotEmpty() }
208
785820da6485 fixes response locale not set for new sessions
Mike Becker <universe@uap-core.de>
parents: 184
diff changeset
182 return locales.ifEmpty { listOf(Locale.ENGLISH) }
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185 }

mercurial