1 /* |
1 /* |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 * |
3 * |
4 * Copyright 2018 Mike Becker. All rights reserved. |
4 * Copyright 2018 Mike Becker. All rights reserved. |
5 * |
5 * |
6 * Redistribution and use in source and binary forms, with or without |
6 * Redistribution and use in source and binary forms, with or without |
7 * modification, are permitted provided that the following conditions are met: |
7 * modification, are permitted provided that the following conditions are met: |
8 * |
8 * |
9 * 1. Redistributions of source code must retain the above copyright |
9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. |
10 * notice, this list of conditions and the following disclaimer. |
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 * |
27 * |
28 */ |
28 */ |
29 package de.uapcore.lightpit.modules; |
29 package de.uapcore.lightpit.modules; |
30 |
30 |
31 import de.uapcore.lightpit.LightPITModule; |
31 import de.uapcore.lightpit.*; |
32 import de.uapcore.lightpit.AbstractLightPITServlet; |
32 |
33 import de.uapcore.lightpit.HttpMethod; |
|
34 import de.uapcore.lightpit.RequestMapping; |
|
35 import de.uapcore.lightpit.ResponseType; |
|
36 import javax.servlet.annotation.WebServlet; |
33 import javax.servlet.annotation.WebServlet; |
37 import javax.servlet.http.HttpServletRequest; |
34 import javax.servlet.http.HttpServletRequest; |
38 import javax.servlet.http.HttpServletResponse; |
35 import javax.servlet.http.HttpServletResponse; |
39 |
36 |
40 /** |
37 /** |
49 @WebServlet( |
46 @WebServlet( |
50 name = "ErrorModule", |
47 name = "ErrorModule", |
51 urlPatterns = "/error/*" |
48 urlPatterns = "/error/*" |
52 ) |
49 ) |
53 public final class ErrorModule extends AbstractLightPITServlet { |
50 public final class ErrorModule extends AbstractLightPITServlet { |
54 |
51 |
55 public static final String REQ_ATTR_ERROR_CODE = "errorCode"; |
52 public static final String REQ_ATTR_ERROR_CODE = "errorCode"; |
56 |
53 |
57 private ResponseType handle(HttpServletRequest req, HttpServletResponse resp, int sc) { |
54 private ResponseType handle(HttpServletRequest req, HttpServletResponse resp, int sc) { |
58 |
55 |
59 req.setAttribute(REQ_ATTR_ERROR_CODE, sc); |
56 req.setAttribute(REQ_ATTR_ERROR_CODE, sc); |
60 setStylesheet(req, "error"); |
57 setStylesheet(req, "error"); |
61 setDynamicFragment(req, "error"); |
58 setDynamicFragment(req, "error"); |
62 |
59 |
63 return ResponseType.HTML_FULL; |
60 return ResponseType.HTML_FULL; |
64 } |
61 } |
65 |
62 |
66 @RequestMapping(requestPath = "404", method = HttpMethod.GET) |
63 @RequestMapping(requestPath = "404", method = HttpMethod.GET) |
67 public ResponseType handle404(HttpServletRequest req, HttpServletResponse resp) { |
64 public ResponseType handle404(HttpServletRequest req, HttpServletResponse resp) { |
68 return handle(req, resp, 404); |
65 return handle(req, resp, 404); |
69 } |
66 } |
70 |
67 |
71 @RequestMapping(requestPath = "403", method = HttpMethod.GET) |
68 @RequestMapping(requestPath = "403", method = HttpMethod.GET) |
72 public ResponseType handle403(HttpServletRequest req, HttpServletResponse resp) { |
69 public ResponseType handle403(HttpServletRequest req, HttpServletResponse resp) { |
73 return handle(req, resp, 403); |
70 return handle(req, resp, 403); |
74 } |
71 } |
75 |
72 |
76 @RequestMapping(requestPath = "500", method = HttpMethod.GET) |
73 @RequestMapping(requestPath = "500", method = HttpMethod.GET) |
77 public ResponseType handle500(HttpServletRequest req, HttpServletResponse resp) { |
74 public ResponseType handle500(HttpServletRequest req, HttpServletResponse resp) { |
78 return handle(req, resp, 500); |
75 return handle(req, resp, 500); |
79 } |
76 } |
80 } |
77 } |