Skip to content

Commit 264230e

Browse files
committed
small upgrades and cleanup work
1 parent b3cc3d1 commit 264230e

16 files changed

Lines changed: 126 additions & 509 deletions

File tree

‎m2-lesson1-start/pom.xml‎

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<groupId>org.springframework.boot</groupId>
1414
<artifactId>spring-boot-starter-parent</artifactId>
15-
<version>1.4.3.RELEASE</version>
15+
<version>1.5.2.RELEASE</version>
1616
<relativePath /> <!-- lookup parent from repository -->
1717
</parent>
1818

@@ -96,70 +96,31 @@
9696
</build>
9797

9898
<properties>
99-
99+
100100
<!-- non-dependencies -->
101101
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
102-
<java.version>1.8</java.version>
103-
104-
<!-- overriding Spring Boot -->
105-
<spring-hateoas.version>0.21.0.RELEASE</spring-hateoas.version>
106-
107-
<commons-collections.version>3.2.2</commons-collections.version>
108-
<hibernate.version>5.2.1.Final</hibernate.version>
109-
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
110-
<httpclient.version>4.5.2</httpclient.version>
111-
<javassist.version>3.20.0-GA</javassist.version>
112-
<mysql.version>5.1.39</mysql.version>
113-
114-
<slf4j.version>1.7.21</slf4j.version>
115-
116-
<!-- Spring related -->
117-
<aspectjweaver.version>1.8.9</aspectjweaver.version>
118-
119-
<!-- web -->
120-
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
121-
122-
<!-- marshalling -->
123-
<jaxb-api.version>2.2.12</jaxb-api.version>
124-
<jackson.version>2.8.6</jackson.version>
125-
126-
<!-- commons and utils -->
127-
<commons-lang3.version>3.4</commons-lang3.version>
128-
<guava.version>19.0</guava.version>
129-
130-
<!-- UNSORTED -->
131-
<commons-codec.version>1.10</commons-codec.version>
102+
<java.version>1.8</java.version>
132103

133104
<!-- persistence -->
134-
<querydsl.version>4.1.3</querydsl.version>
135-
<spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
136-
<h2.version>1.4.192</h2.version>
137-
<hsqldb.version>2.3.4</hsqldb.version>
138-
139105
<validation-api.version>1.1.0.Final</validation-api.version>
140-
141-
<!-- ops related -->
142-
<tomcat.version>8.5.4</tomcat.version>
143-
144-
<!-- logging -->
145-
<logback.version>1.1.7</logback.version>
146-
147-
<!-- testing -->
148-
<org.hamcrest.version>1.3</org.hamcrest.version>
149-
<junit.version>4.12</junit.version>
150-
<mockito.version>1.10.19</mockito.version>
151-
152-
<httpcore.version>4.4.5</httpcore.version>
106+
<hsqldb.version>2.3.4</hsqldb.version>
107+
108+
109+
<!-- commons and utils -->
110+
<guava.version>19.0</guava.version>
111+
<commons-lang3.version>3.4</commons-lang3.version>
112+
153113
<rest-assured.version>2.9.0</rest-assured.version>
154-
114+
115+
<!-- marshalling -->
116+
<jaxb-api.version>2.2.12</jaxb-api.version>
117+
155118
<!-- maven plugins -->
156119
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
157120
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
158121
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
159122
<cargo-maven2-plugin.version>1.5.0</cargo-maven2-plugin.version>
160-
<maven-war-plugin.version>2.6</maven-war-plugin.version>
161-
162-
123+
163124
</properties>
164125

165126
<modules>
Lines changed: 7 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,20 @@
11
package com.baeldung.common.web;
22

3-
import javax.persistence.EntityNotFoundException;
4-
5-
import org.springframework.dao.DataAccessException;
6-
import org.springframework.dao.InvalidDataAccessApiUsageException;
7-
import org.springframework.http.HttpHeaders;
8-
import org.springframework.http.HttpStatus;
9-
import org.springframework.http.ResponseEntity;
3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
105
import org.springframework.web.bind.annotation.ControllerAdvice;
11-
import org.springframework.web.bind.annotation.ExceptionHandler;
12-
import org.springframework.web.context.request.WebRequest;
136
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
147

15-
import com.baeldung.common.persistence.exception.MyEntityNotFoundException;
16-
import com.baeldung.common.web.exception.MyConflictException;
17-
import com.baeldung.common.web.exception.MyForbiddenException;
18-
import com.baeldung.common.web.exception.MyPreconditionFailedException;
19-
208
@ControllerAdvice
219
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
2210

23-
// 400
24-
25-
// 403
11+
private Logger log = LoggerFactory.getLogger(getClass());
2612

27-
@ExceptionHandler({ MyForbiddenException.class })
28-
protected ResponseEntity<Object> handleForbidden(final MyForbiddenException ex, final WebRequest request) {
29-
final String bodyOfResponse = "This should be application specific";
30-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.FORBIDDEN, request);
13+
public RestResponseEntityExceptionHandler() {
14+
super();
3115
}
3216

33-
// 404
34-
35-
@ExceptionHandler({ MyEntityNotFoundException.class })
36-
protected ResponseEntity<Object> handleNotFound(final MyEntityNotFoundException ex, final WebRequest request) {
37-
final String bodyOfResponse = "This should be application specific";
38-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.NOT_FOUND, request);
39-
}
40-
41-
@ExceptionHandler(value = { EntityNotFoundException.class })
42-
protected ResponseEntity<Object> handleLibraryNotFound(final EntityNotFoundException ex, final WebRequest request) {
43-
final String bodyOfResponse = "This should be application specific";
44-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.NOT_FOUND, request);
45-
}
46-
47-
// 409
48-
49-
@ExceptionHandler({ InvalidDataAccessApiUsageException.class, DataAccessException.class, MyConflictException.class })
50-
protected ResponseEntity<Object> handleConflict(final RuntimeException ex, final WebRequest request) {
51-
final String bodyOfResponse = "This should be application specific";
52-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.CONFLICT, request);
53-
}
54-
55-
// 412
56-
57-
@ExceptionHandler({ MyPreconditionFailedException.class })
58-
protected ResponseEntity<Object> handlePreconditionFailed(final RuntimeException ex, final WebRequest request) {
59-
final String bodyOfResponse = "This should be application specific";
60-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.PRECONDITION_FAILED, request);
61-
}
62-
63-
// 500
64-
65-
@ExceptionHandler({ NullPointerException.class, IllegalArgumentException.class, IllegalStateException.class })
66-
protected ResponseEntity<Object> handleInternal(final RuntimeException ex, final WebRequest request) {
67-
logger.error("500 Status Code", ex);
68-
final String bodyOfResponse = "This should be application specific";
69-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
70-
}
17+
// API
7118

19+
// 400
7220
}

‎m2-lesson1-start/um-webapp/src/main/java/com/baeldung/um/spring/UmContextConfig.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.baeldung.um.spring;
22

33
import org.springframework.context.annotation.Bean;
4-
import org.springframework.context.annotation.ComponentScan;
54
import org.springframework.context.annotation.Configuration;
65
import org.springframework.context.annotation.EnableAspectJAutoProxy;
76
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
87
@Configuration
9-
@ComponentScan({ "com.baeldung.um.model" })
108
@EnableAspectJAutoProxy(proxyTargetClass = true)
119
public class UmContextConfig {
1210

‎m2-lesson1/pom.xml‎

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<parent>
1313
<groupId>org.springframework.boot</groupId>
1414
<artifactId>spring-boot-starter-parent</artifactId>
15-
<version>1.4.3.RELEASE</version>
15+
<version>1.5.2.RELEASE</version>
1616
<relativePath /> <!-- lookup parent from repository -->
1717
</parent>
1818

@@ -96,72 +96,33 @@
9696
</build>
9797

9898
<properties>
99-
99+
100100
<!-- non-dependencies -->
101101
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
102-
<java.version>1.8</java.version>
103-
104-
<!-- overriding Spring Boot -->
105-
<spring-hateoas.version>0.21.0.RELEASE</spring-hateoas.version>
106-
107-
<commons-collections.version>3.2.2</commons-collections.version>
108-
<hibernate.version>5.2.1.Final</hibernate.version>
109-
<hibernate-validator.version>5.2.4.Final</hibernate-validator.version>
110-
<httpclient.version>4.5.2</httpclient.version>
111-
<javassist.version>3.20.0-GA</javassist.version>
112-
<mysql.version>5.1.39</mysql.version>
113-
114-
<slf4j.version>1.7.21</slf4j.version>
115-
116-
<!-- Spring related -->
117-
<aspectjweaver.version>1.8.9</aspectjweaver.version>
118-
119-
<!-- web -->
120-
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
121-
122-
<!-- marshalling -->
123-
<jaxb-api.version>2.2.12</jaxb-api.version>
124-
<jackson.version>2.8.6</jackson.version>
125-
126-
<!-- commons and utils -->
127-
<commons-lang3.version>3.4</commons-lang3.version>
128-
<guava.version>19.0</guava.version>
129-
130-
<!-- UNSORTED -->
131-
<commons-codec.version>1.10</commons-codec.version>
102+
<java.version>1.8</java.version>
132103

133104
<!-- persistence -->
134-
<querydsl.version>4.1.3</querydsl.version>
135-
<spring-data-jpa.version>1.10.2.RELEASE</spring-data-jpa.version>
136-
<h2.version>1.4.192</h2.version>
137-
<hsqldb.version>2.3.4</hsqldb.version>
138-
139105
<validation-api.version>1.1.0.Final</validation-api.version>
140-
141-
<!-- ops related -->
142-
<tomcat.version>8.5.4</tomcat.version>
143-
144-
<!-- logging -->
145-
<logback.version>1.1.7</logback.version>
146-
147-
<!-- testing -->
148-
<org.hamcrest.version>1.3</org.hamcrest.version>
149-
<junit.version>4.12</junit.version>
150-
<mockito.version>1.10.19</mockito.version>
151-
152-
<httpcore.version>4.4.5</httpcore.version>
106+
<hsqldb.version>2.3.4</hsqldb.version>
107+
108+
109+
<!-- commons and utils -->
110+
<guava.version>19.0</guava.version>
111+
<commons-lang3.version>3.4</commons-lang3.version>
112+
153113
<rest-assured.version>2.9.0</rest-assured.version>
154-
114+
115+
<!-- marshalling -->
116+
<jaxb-api.version>2.2.12</jaxb-api.version>
117+
155118
<!-- maven plugins -->
156119
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
157120
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
158121
<maven-resources-plugin.version>3.0.1</maven-resources-plugin.version>
159122
<cargo-maven2-plugin.version>1.5.0</cargo-maven2-plugin.version>
160-
<maven-war-plugin.version>2.6</maven-war-plugin.version>
161-
162-
123+
163124
</properties>
164-
125+
165126
<modules>
166127
<module>common</module>
167128
<module>um-webapp</module>
Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package com.baeldung.common.web;
22

3-
import javax.persistence.EntityNotFoundException;
43
import javax.validation.ConstraintViolationException;
54

65
import org.apache.commons.lang3.exception.ExceptionUtils;
7-
import org.springframework.dao.DataAccessException;
6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
88
import org.springframework.dao.DataIntegrityViolationException;
9-
import org.springframework.dao.InvalidDataAccessApiUsageException;
109
import org.springframework.http.HttpHeaders;
1110
import org.springframework.http.HttpStatus;
1211
import org.springframework.http.ResponseEntity;
@@ -17,16 +16,20 @@
1716
import org.springframework.web.context.request.WebRequest;
1817
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
1918

20-
import com.baeldung.common.persistence.exception.MyEntityNotFoundException;
2119
import com.baeldung.common.web.exception.ApiError;
2220
import com.baeldung.common.web.exception.MyBadRequestException;
23-
import com.baeldung.common.web.exception.MyConflictException;
24-
import com.baeldung.common.web.exception.MyForbiddenException;
25-
import com.baeldung.common.web.exception.MyPreconditionFailedException;
2621

2722
@ControllerAdvice
2823
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
2924

25+
private Logger log = LoggerFactory.getLogger(getClass());
26+
27+
public RestResponseEntityExceptionHandler() {
28+
super();
29+
}
30+
31+
// API
32+
3033
// 400
3134

3235
@Override
@@ -51,51 +54,4 @@ private final ApiError message(final HttpStatus httpStatus, final Exception ex)
5154
return new ApiError(httpStatus.value(), message, devMessage);
5255
}
5356

54-
// 403
55-
56-
@ExceptionHandler({ MyForbiddenException.class })
57-
protected ResponseEntity<Object> handleForbidden(final MyForbiddenException ex, final WebRequest request) {
58-
final String bodyOfResponse = "This should be application specific";
59-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.FORBIDDEN, request);
60-
}
61-
62-
// 404
63-
64-
@ExceptionHandler({ MyEntityNotFoundException.class })
65-
protected ResponseEntity<Object> handleNotFound(final MyEntityNotFoundException ex, final WebRequest request) {
66-
final String bodyOfResponse = "This should be application specific";
67-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.NOT_FOUND, request);
68-
}
69-
70-
@ExceptionHandler(value = { EntityNotFoundException.class })
71-
protected ResponseEntity<Object> handleLibraryNotFound(final EntityNotFoundException ex, final WebRequest request) {
72-
final String bodyOfResponse = "This should be application specific";
73-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.NOT_FOUND, request);
74-
}
75-
76-
// 409
77-
78-
@ExceptionHandler({ InvalidDataAccessApiUsageException.class, DataAccessException.class, MyConflictException.class })
79-
protected ResponseEntity<Object> handleConflict(final RuntimeException ex, final WebRequest request) {
80-
final String bodyOfResponse = "This should be application specific";
81-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.CONFLICT, request);
82-
}
83-
84-
// 412
85-
86-
@ExceptionHandler({ MyPreconditionFailedException.class })
87-
protected ResponseEntity<Object> handlePreconditionFailed(final RuntimeException ex, final WebRequest request) {
88-
final String bodyOfResponse = "This should be application specific";
89-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.PRECONDITION_FAILED, request);
90-
}
91-
92-
// 500
93-
94-
@ExceptionHandler({ NullPointerException.class, IllegalArgumentException.class, IllegalStateException.class })
95-
protected ResponseEntity<Object> handleInternal(final RuntimeException ex, final WebRequest request) {
96-
logger.error("500 Status Code", ex);
97-
final String bodyOfResponse = "This should be application specific";
98-
return handleExceptionInternal(ex, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
99-
}
100-
10157
}

‎m2-lesson1/um-webapp/src/main/java/com/baeldung/um/spring/UmContextConfig.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.baeldung.um.spring;
22

33
import org.springframework.context.annotation.Bean;
4-
import org.springframework.context.annotation.ComponentScan;
54
import org.springframework.context.annotation.Configuration;
65
import org.springframework.context.annotation.EnableAspectJAutoProxy;
76
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
87
@Configuration
9-
@ComponentScan({ "com.baeldung.um.model" })
108
@EnableAspectJAutoProxy(proxyTargetClass = true)
119
public class UmContextConfig {
1210

0 commit comments

Comments
 (0)