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

Thu, 13 May 2021 19:31:09 +0200

author
Mike Becker <universe@uap-core.de>
date
Thu, 13 May 2021 19:31:09 +0200
changeset 198
94f174d591ab
parent 184
e8eecee6aadf
child 208
785820da6485
permissions
-rw-r--r--

fixes wrong handling of feeds - only one channel per feed is allowed

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
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 import java.sql.SQLException
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 import java.util.*
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 import javax.servlet.http.HttpServlet
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 import javax.servlet.http.HttpServletRequest
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 import javax.servlet.http.HttpServletResponse
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 abstract class AbstractServlet : LoggingTrait, HttpServlet() {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 /**
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 * Contains the GET request mappings.
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 private val getMappings = mutableMapOf<PathPattern, MappingMethod>()
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 /**
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45 * Contains the POST request mappings.
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 private val postMappings = mutableMapOf<PathPattern, MappingMethod>()
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 protected fun get(pattern: String, method: MappingMethod) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 getMappings[PathPattern(pattern)] = method
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 protected fun post(pattern: String, method: MappingMethod) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 postMappings[PathPattern(pattern)] = method
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 private fun notFound(http: HttpRequest, dao: DataAccessObject) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 http.response.sendError(HttpServletResponse.SC_NOT_FOUND)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 private fun findMapping(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 mappings: Map<PathPattern, MappingMethod>,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 req: HttpServletRequest
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 ): Pair<PathPattern, MappingMethod> {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 val requestPath = sanitizedRequestPath(req)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 val candidates = mappings.filter { it.key.matches(requestPath) }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 return if (candidates.isEmpty()) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 Pair(PathPattern(requestPath), ::notFound)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 } else {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 if (candidates.size > 1) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 logger().warn("Ambiguous mapping for request path '{}'", requestPath)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 candidates.entries.first().toPair()
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 }
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 private fun invokeMapping(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 mapping: Pair<PathPattern, MappingMethod>,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 req: HttpServletRequest,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 resp: HttpServletResponse,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 dao: DataAccessObject
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 ) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 val params = mapping.first.obtainPathParameters(sanitizedRequestPath(req))
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 val method = mapping.second
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 logger().trace("invoke {}", method)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 method(HttpRequest(req, resp, params), dao)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 private fun sanitizedRequestPath(req: HttpServletRequest) = req.pathInfo ?: "/"
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 doProcess(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 req: HttpServletRequest,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 resp: HttpServletResponse,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 mappings: Map<PathPattern, MappingMethod>
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 ) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 val session = req.session
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 // the very first thing to do is to force UTF-8
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 req.characterEncoding = "UTF-8"
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101 // 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
102 if (session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) == null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 val availableLanguages = availableLanguages()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 val reqLocale = req.locale
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 val sessionLocale = if (availableLanguages.contains(reqLocale)) reqLocale else availableLanguages.first()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 session.setAttribute(Constants.SESSION_ATTR_LANGUAGE, sessionLocale)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 logger().debug(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 "Setting language for new session {}: {}", session.id, sessionLocale.displayLanguage
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 } else {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 val sessionLocale = session.getAttribute(Constants.SESSION_ATTR_LANGUAGE) as Locale
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 resp.locale = sessionLocale
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 logger().trace("Continuing session {} with language {}", session.id, sessionLocale)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 // set some internal request attributes
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 val http = HttpRequest(req, resp)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 val fullPath = req.servletPath + Optional.ofNullable(req.pathInfo).orElse("")
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 req.setAttribute(Constants.REQ_ATTR_BASE_HREF, http.baseHref)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 req.setAttribute(Constants.REQ_ATTR_PATH, fullPath)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 req.getHeader("Referer")?.let {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 // TODO: add a sanity check to avoid link injection
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 req.setAttribute(Constants.REQ_ATTR_REFERER, it)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 // if this is an error path, bypass the normal flow
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127 if (fullPath.startsWith("/error/")) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 http.styleSheets = listOf("error")
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 http.render("error")
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 return
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 // obtain a connection and create the data access objects
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 val dsp = req.servletContext.getAttribute(SC_ATTR_NAME) as DataSourceProvider
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 val dialect = dsp.dialect
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 val ds = dsp.dataSource
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 if (ds == null) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138 resp.sendError(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 HttpServletResponse.SC_SERVICE_UNAVAILABLE,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 "JNDI DataSource lookup failed. See log for details."
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 return
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 try {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 ds.connection.use { connection ->
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 val dao = createDataAccessObject(dialect, connection)
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 connection.autoCommit = false
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 invokeMapping(findMapping(mappings, req), req, resp, dao)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 connection.commit()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 } catch (ex: SQLException) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 logger().warn("Database transaction failed (Code {}): {}", ex.errorCode, ex.message)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 logger().debug("Details: ", ex)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 resp.sendError(
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 "Unhandled Transaction Error - Code: " + ex.errorCode
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 )
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 connection.rollback()
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 }
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 } catch (ex: SQLException) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 logger().error("Severe Database Exception (Code {}): {}", ex.errorCode, ex.message)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 logger().debug("Details: ", ex)
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 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
165 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 override fun doGet(req: HttpServletRequest, resp: HttpServletResponse) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 doProcess(req, resp, getMappings)
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
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 override fun doPost(req: HttpServletRequest, resp: HttpServletResponse) {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 doProcess(req, resp, postMappings)
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
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 protected fun availableLanguages(): List<Locale> {
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177 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
178 val locales = langTags.map(Locale::forLanguageTag).filter { it.language.isNotEmpty() }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 return if (locales.isEmpty()) listOf(Locale.ENGLISH) else locales
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 }
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181
e8eecee6aadf completes kotlin migration
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 }

mercurial