Skip to content

Commit b53ddab

Browse files
committed
404 page
1 parent d90c6eb commit b53ddab

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
- [x] donwload als parameter nicht url `/download`
2828
- [x] set response header on donwload
2929

30-
- [ ] send 404 for unknown links and don't log
30+
- [x] send 404 for unknown links and don't log
3131
- [x] generate preview page as blurry jpeg. extracting the first page from the PDF does not reduce file size much
3232
- [ ] set proper filename for download
3333

src/main/java/com/headissue/servlet/SeePdfs.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ public SeePdfs(
6363
}
6464

6565
@Override
66-
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
66+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
6767
String accessId = getAccessId(req);
6868
Path accessYaml = getAccessYaml(accessId);
69-
checkExistence(accessId, accessYaml);
69+
if (Files.notExists(accessYaml)) {
70+
req.getRequestDispatcher("/404").forward(req, resp);
71+
return;
72+
}
7073
AccessRule accessRule = yaml.loadAs(new FileInputStream(accessYaml.toFile()), AccessRule.class);
7174
if (isExpired(accessYaml)) {
7275
writeExpiredPage(resp, accessRule);

src/main/java/com/headissue/servlet/TemplateRendering.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.headissue.servlet;
22

33
import com.github.jknack.handlebars.Handlebars;
4+
import jakarta.servlet.ServletException;
45
import jakarta.servlet.http.HttpServlet;
56
import jakarta.servlet.http.HttpServletRequest;
67
import jakarta.servlet.http.HttpServletResponse;
8+
9+
import java.io.FileNotFoundException;
710
import java.io.IOException;
811
import org.eclipse.jetty.http.MimeTypes;
912

@@ -16,13 +19,17 @@ public TemplateRendering(Handlebars handlebars) {
1619
}
1720

1821
@Override
19-
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
22+
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
2023
resp.setContentType(MimeTypes.Type.TEXT_HTML_UTF_8.asString());
2124
String pathInfo = req.getPathInfo();
2225
if (pathInfo.equals("/")) {
2326
handlebars.compile("index.hbs").apply(null, resp.getWriter());
2427
} else {
25-
handlebars.compile(pathInfo).apply(null, resp.getWriter());
28+
try {
29+
handlebars.compile(pathInfo + ".hbs").apply(null, resp.getWriter());
30+
} catch (FileNotFoundException e) {
31+
req.getRequestDispatcher("/404").forward(req, resp);
32+
}
2633
}
2734
}
2835
}

src/main/resources/static/404.hbs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<title>404</title>
5+
{{> "head.hbs"}}
6+
</head>
7+
<body style="background: url('/img/Solid-polymeric-foam.jpg'); background-size: cover">
8+
<main style="display: flex;
9+
flex-direction: column;
10+
flex-wrap: wrap;
11+
justify-content: space-between;
12+
align-content: flex-end;">
13+
<div style="padding: 10px">
14+
<h1 style="text-shadow: 1px 1px #888; color: red">404 Not Found</h1>
15+
<h2 style="text-shadow: 1px 1px #888;">The resource you are looking for does not exist</h2>
16+
</div>
17+
<div style="text-shadow: 1px 1px #888; font-size: 0.8rem">
18+
<a href="https://commons.wikimedia.org/wiki/File:Solid-polymeric-foam.jpg">Giovanna Canu, Eva Santini</a>, <a
19+
href="https://creativecommons.org/licenses/by/4.0">CC BY 4.0</a>, via Wikimedia Commons
20+
</div>
21+
</main>
22+
23+
{{> "molecule/footer.hbs" }}
24+
</body>
25+
</html>

0 commit comments

Comments
 (0)