in testing/h2console/ui/src/main/java/org/h2/server/web/H2WebServletForJakarta.java [121:196]
public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException {
req.setCharacterEncoding("utf-8");
String file = req.getPathInfo();
if (file == null) {
resp.sendRedirect(req.getRequestURI() + "/");
return;
} else if (file.startsWith("/")) {
file = file.substring(1);
}
file = getAllowedFile(req, file);
// extract the request attributes
Properties attributes = new Properties();
Enumeration<?> en = req.getAttributeNames();
while (en.hasMoreElements()) {
String name = en.nextElement().toString();
String value = req.getAttribute(name).toString();
attributes.put(name, value);
}
en = req.getParameterNames();
while (en.hasMoreElements()) {
String name = en.nextElement().toString();
String value = req.getParameter(name);
attributes.put(name, value);
}
WebSession session = null;
String sessionId = attributes.getProperty("jsessionid");
if (sessionId != null) {
session = server.getSession(sessionId);
}
WebApp app = new WebApp(server);
app.setSession(session, attributes);
String ifModifiedSince = req.getHeader("if-modified-since");
String scheme = req.getScheme();
StringBuilder builder = new StringBuilder(scheme).append("://").append(req.getServerName());
int serverPort = req.getServerPort();
if (!(serverPort == 80 && scheme.equals("http") || serverPort == 443 && scheme.equals("https"))) {
builder.append(':').append(serverPort);
}
String path = builder.append(req.getContextPath()).toString();
file = app.processRequest(file, new NetworkConnectionInfo(path, req.getRemoteAddr(), req.getRemotePort()));
session = app.getSession();
String mimeType = app.getMimeType();
boolean cache = app.getCache();
if (cache && server.getStartDateTime().equals(ifModifiedSince)) {
resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
byte[] bytes = server.getFile(file);
if (bytes == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
bytes = ("File not found: " + file).getBytes(StandardCharsets.UTF_8);
} else {
if (session != null && file.endsWith(".jsp")) {
String page = new String(bytes, StandardCharsets.UTF_8);
page = PageParser.parse(page, session.map);
bytes = page.getBytes(StandardCharsets.UTF_8);
}
resp.setContentType(mimeType);
if (!cache) {
resp.setHeader("Cache-Control", "no-cache");
} else {
resp.setHeader("Cache-Control", "max-age=10");
resp.setHeader("Last-Modified", server.getStartDateTime());
}
}
if (bytes != null) {
ServletOutputStream out = resp.getOutputStream();
out.write(bytes);
}
}