Skip to content

Commit 4a60bbd

Browse files
Spring boot run in Heroku
1 parent b9b5c09 commit 4a60bbd

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

pom.xml

-11
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,6 @@
141141
<artifactId>spring-boot-starter-log4j2</artifactId>
142142
</dependency>
143143

144-
<!-- asynchronous loggers -->
145-
<dependency>
146-
<groupId>com.lmax</groupId>
147-
<artifactId>disruptor</artifactId>
148-
<version>3.4.2</version>
149-
</dependency>
150-
<!-- <dependency>
151-
<groupId>org.springframework.data</groupId>
152-
<artifactId>spring-data-commons</artifactId>
153-
</dependency>-->
154-
155144
</dependencies>
156145

157146
<build>

src/main/java/abdullah/todomanagement/controller/TodoController.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.servlet.http.HttpServletResponse;
88
import javax.validation.Valid;
99

10+
import abdullah.todomanagement.config.TokenException;
1011
import abdullah.todomanagement.config.TokenManager;
1112
import org.springframework.beans.factory.annotation.Autowired;
1213
import org.springframework.beans.propertyeditors.CustomDateEditor;
@@ -96,7 +97,7 @@ public String addTodo(ModelMap model,HttpServletRequest request
9697
}
9798

9899
if (!TokenManager.isTokenValid(request)) {
99-
return "redirect:/list-todos";
100+
throw new TokenException("Wrong synchronizer token passed. Please refresh page before operation");
100101
}
101102

102103
todo.setUserName(getLoggedInUserName(model));

src/main/java/abdullah/todomanagement/exception/GlobalExceptionHandler.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
55
import org.springframework.core.annotation.AnnotationUtils;
6+
import org.springframework.http.HttpStatus;
67
import org.springframework.web.bind.annotation.ControllerAdvice;
78
import org.springframework.web.bind.annotation.ExceptionHandler;
89
import org.springframework.web.bind.annotation.ResponseStatus;
910
import org.springframework.web.servlet.ModelAndView;
1011
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
1112

1213
import javax.servlet.http.HttpServletRequest;
14+
import javax.servlet.http.HttpServletResponse;
1315

1416
@ControllerAdvice
1517
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
@@ -18,7 +20,7 @@ public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
1820
private final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
1921

2022
@ExceptionHandler(value = Exception.class)
21-
public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
23+
public ModelAndView defaultErrorHandler(HttpServletRequest req, HttpServletResponse res, Exception e) throws Exception {
2224

2325
logger.error("[URL] : {}", req.getRequestURL(), e);
2426

@@ -34,6 +36,7 @@ public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) thr
3436
mav.addObject("exception", e);
3537
mav.addObject("url", req.getRequestURL());
3638
mav.setViewName(DEFAULT_ERROR_VIEW);
39+
res.sendError(HttpStatus.NOT_ACCEPTABLE.value(), e.getLocalizedMessage());
3740
return mav;
3841
}
3942

src/main/webapp/WEB-INF/jsp/error.jsp

+27-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
1+
<%@ page session="false"%>
2+
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
3+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
18
<%@ include file="common/header.jspf"%>
29
<%@ include file="common/navigation.jspf"%>
3-
<div class="container">
4-
An exception occurred! Please contact Support!
5-
</div>
6-
<%@ include file="common/footer.jspf"%>
10+
11+
<body>
12+
13+
<div class="container">
14+
15+
<h1>Error Page</h1>
16+
17+
<p>${exception.message}</p>
18+
<!-- Exception: ${exception.message}.
19+
<c:forEach items="${exception.stackTrace}" var="stackTrace">
20+
${stackTrace}
21+
</c:forEach>
22+
-->
23+
24+
</div>
25+
26+
<%@ include file="common/footer.jspf"%>
27+
28+
</body>
29+
</html>

0 commit comments

Comments
 (0)