Skip to content

Commit

Permalink
Spring Boot 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
midovlvn committed Nov 27, 2022
1 parent 18bab25 commit 8983ac0
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
33 changes: 12 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,24 @@ Example 2. `curl -v localhost:8080/manve -d '{ "p1": -1, "p2": -1}' -H "Content-
```

### Installation

For Spring Boot 2.x:

<dependency>
<groupId>io.github.michaldo</groupId>
<artifactId>sanchero-starter</artifactId>
<version>0.0.1</version>
</dependency>

Sanchero is compiled with dependency to Spring Boot 2.7.3 and with Java 17.
For Spring Boot 3.x:

<dependency>
<groupId>io.github.michaldo</groupId>
<artifactId>sanchero-starter</artifactId>
<version>1.0.0</version>
</dependency>

Sanchero is compiled with Java 17.

If for any reason the library must be customized, I recommend copy-paste source code. It is just one file.

Expand All @@ -146,23 +157,3 @@ If for any reason the library must be customized, I recommend copy-paste source
> It is not clear to me how to fix that. Fortunately, often ConstraintViolationException is thrown only from
> `Conroller` layer.
### Sanchero vs RFC 7807 "Problem details for HTTP APIs"

RFC 7807 https://www.rfc-editor.org/rfc/rfc7807 defines standard error format.
The standard is published in 2016 and not popular so far.

Sanchero follows Spring Boot error format.

### Sanchero vs Zalando Problem library

zalando/problem https://github.com/zalando/problem is RFC 7807 implementation.

zalando/problem Spring implementation is built over `@ControllerAdvice` and has the following drawbacks:
1. Does not handle exceptions thrown in Filter
2. Does not handle `HttpServletResponse.sendError(...)`
3. Modifies security configuration:

> For `http.authorizeRequests().anyRequest().authenticated().and().build();` response code
is 403 for vanilla Spring Boot and 401 for Spring Boot + problem-spring-web-starter v. 0.27.0

Sanchero is built over combination `@ControllerAdvice`/`ErrorAttributes` and not affected by these drawbacks
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<version>3.0.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.github.michaldo</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.github.michaldo;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.ConstraintViolationException;
import jakarta.validation.Path;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.web.error.ErrorAttributeOptions;
Expand All @@ -9,14 +13,9 @@
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.WebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import javax.validation.Path;
import java.io.IOException;
import java.util.Comparator;
import java.util.Iterator;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/github/test/SancheroTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void testCve() {
"timestamp": "${json-unit.ignore}",
"status": 400,
"error": "Bad Request",
"exception": "javax.validation.ConstraintViolationException",
"exception": "jakarta.validation.ConstraintViolationException",
"message": "Validation failed",
"path": "/cve",
"errors": [
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/github/test/TestApplication.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.test;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.Min;

@SpringBootApplication
@RestController
Expand Down

0 comments on commit 8983ac0

Please sign in to comment.