File tree Expand file tree Collapse file tree 4 files changed +40
-5
lines changed
java/com/headissue/servlet Expand file tree Collapse file tree 4 files changed +40
-5
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change 11package com .headissue .servlet ;
22
33import com .github .jknack .handlebars .Handlebars ;
4+ import jakarta .servlet .ServletException ;
45import jakarta .servlet .http .HttpServlet ;
56import jakarta .servlet .http .HttpServletRequest ;
67import jakarta .servlet .http .HttpServletResponse ;
8+
9+ import java .io .FileNotFoundException ;
710import java .io .IOException ;
811import 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}
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments