Skip to content

Commit accf886

Browse files
ready for publication
1 parent 2189227 commit accf886

File tree

2 files changed

+43
-58
lines changed

2 files changed

+43
-58
lines changed

README.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ wherein each instance of error code enum represents an error scenario.
3939
An exception class could be either checked or unchecked, but handling of exception is no different.
4040
For almost all error scenarios unchecked exception can serve the purpose really well,
4141
saving developers from explicitly writing `try` `catch` blocks and `throws` clauses. Though not recommended but
42-
limited checked exceptions can be created and thrown from methods where calling programs can take some recovery measures.
42+
limited, checked exceptions can be created and thrown from methods where calling programs can take some recovery measures.
4343

4444
Standard way of handling exceptions in Spring is `@ControllerAdvice` using AOP,
4545
following the same principles **spring-boot-problem-handler** makes available everything related to exception handling
@@ -70,26 +70,26 @@ Gradle
7070
implementation 'io.github.officiallysingh:spring-boot-problem-handler:1.9'
7171
```
7272

73-
It does all hard part, A lot of advices are out of box available which are autoconfigured as `ControllerAdvice`s
73+
It does all hard part, A lot of advices are out of box available that are autoconfigured as `ControllerAdvice`s
7474
depending on the jars in classpath of consumer application.
7575
**Even for exceptions for which no advices are defined**, respective error response can be specified by
7676
messages in `properties` file, elaborated in [*Usage*](https://github.com/officiallysingh/spring-boot-problem-handler#usage) section.
77-
New custom advices could be required only in cases where it is required to take some data from exception instance
77+
New custom advice could be required only in cases where it is required to take some data from exception instance
7878
to dynamically derive [*Error key*](https://github.com/officiallysingh/spring-boot-problem-handler#error-key)
79-
or to use this data to resolve any placeholders in error message. In such cases consumer application can define
79+
or to use this data to resolve any placeholders in an error message. In such cases consumer application can define
8080
their own custom `ControllerAdvice`'s,
8181
Any existing advice can be referred to weave the custom advice into the framework.
8282

8383
> A default set of `ControllerAdvice`s are always configured irrespective of the fact that whether
84-
the application is Spring Web or Spring Webflux, but few advices are conditional
84+
the application is Spring Web or Spring Webflux. However, few advices are conditional
8585
such as for Handling Security, OpenAPI and Dao related exceptions, which are elaborated in their respective sections.
8686

8787
## Features
8888

8989
* A lot of inbuilt `ControllerAdvice`'s out of box available to handle most common exceptions.
90-
* Extendable to add more advices or override existing advices in consumer applications, weaving them into aligned framework for exception handling.
90+
* Extendable to add more advices or override existing advices in consumer applications, weaving them into an aligned framework for exception handling.
9191
* Customizable Error response structure.
92-
* Provides mechanism to specify error response for any kind of exception without defining any `ControllerAdvice`.
92+
* Provides a mechanism to specify error response for any kind of exception without defining any `ControllerAdvice`.
9393
* Works with both Spring Web and Spring Webflux applications.
9494
* Customizable to override the default attributes in error response by overriding the same in `properties` file.
9595
* The autoconfigured advices can be disabled or overridden or extended as per needs.
@@ -189,7 +189,7 @@ These advices are autoconfigured as a bean `SecurityExceptionHandler` if followi
189189
and [**`ProblemAccessDeniedHandler`**](src/main/java/com/ksoot/problem/spring/advice/security/ProblemAccessDeniedHandler.java)
190190
are autoconfigured as `authenticationEntryPoint` and `accessDeniedHandler` beans respectively.
191191

192-
But to make it work following needs to be done in application's Spring Security configuration.
192+
But to make it work, the following needs to be done in the application's Spring Security configuration.
193193
Refer to example [**`WebSecurityConfiguration`**](https://github.com/officiallysingh/problem-handler-web-demo/blob/main/src/main/java/com/ksoot/problem/demo/config/WebSecurityConfiguration.java)
194194
```java
195195
@Autowired
@@ -232,7 +232,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
232232
and [**`ProblemServerAccessDeniedHandler`**](src/main/java/com/ksoot/problem/spring/advice/security/ProblemServerAccessDeniedHandler.java)
233233
are autoconfigured as `authenticationEntryPoint` and `accessDeniedHandler` beans respectively.
234234

235-
But to make it work following needs to be done in application Spring Security configuration.
235+
But to make it work, the following needs to be done in application Spring Security configuration.
236236
Refer to example [**`WebFluxSecurityConfiguration`**](https://github.com/officiallysingh/problem-handler-webflux-demo/blob/main/src/main/java/com/ksoot/problem/demo/config/WebFluxSecurityConfiguration.java)
237237
```java
238238
@Autowired
@@ -293,7 +293,7 @@ in addition also requires the following configuration:
293293
spring.mvc.throw-exception-if-no-handler-found=true
294294
```
295295

296-
While using Dao advices, set database platform as follows, set value as per the database being used.
296+
While using Dao advice, set database platform as follows, set value as per the database being used.
297297
```properties
298298
spring.jpa.database=POSTGRESQL
299299
```
@@ -316,7 +316,7 @@ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.
316316

317317
Specify message source bundles as follows. Make sure to include `i18n/problems` bundled in the library, as it
318318
has default messages for certain exception. And it should be last in the list of `basenames`,
319-
so that it has lowest priority and any default messages coming from `problems.properties` can be overridden
319+
so that it has the lowest priority and any default messages coming from `problems.properties` can be overridden
320320
by specifying the property with different value in application's `errors.properties`
321321
```properties
322322
spring.messages.basename=i18n/errors,i18n/problems
@@ -350,7 +350,7 @@ problem.open-api.req-validation-enabled=true
350350
problem.open-api.res-validation-enabled=false
351351
```
352352

353-
* `problem.enabled`:- To enable or disable autoconfigurations, default is `true`.
353+
* `problem.enabled`:- To enable or disable autoconfiguration, default is `true`.
354354
In case consumer applications are interested to avail advices but want full control over configurations,
355355
then it can be set to `false` and required advices can be configured as Spring beans similar to how they are autoconfigured.
356356
* `problem.type-url`:- The base `URL` for **Help page** describing errors. For different exceptions respective code for exception is appended to it followed by a `#`
@@ -361,12 +361,12 @@ problem.open-api.res-validation-enabled=false
361361
* `problem.cause-chains-enabled`:- To enable or disable cause chains, default is `false`.
362362
Elaborated in [*Usage*](https://github.com/officiallysingh/spring-boot-problem-handler#usage) section.
363363
* `problem.jackson-module-enabled`:- To enable or disable Jackson Problem Module autoconfiguration, default is `true`.
364-
Set it to `false` in case consumer application need to define Serialization/Deserialization explicitly.
365-
Or if `Gson` is to be used instead of `Jackson`. If disabled the required serializers need to be defined by consumer application.
364+
Set it to `false` in case consumer application needs to define Serialization/Deserialization explicitly.
365+
Or if `Gson` is to be used instead of `Jackson`. If disabled, the required serializers need to be defined by consumer application.
366366
* `problem.dao-advice-enabled`:- To enable or disable Dao advice autoconfiguration, default is `true`.
367367
Set it to `false` in case consumer application need to define Dao advice configurations explicitly.
368368
* `problem.security-advice-enabled`:- To enable or disable Security advice autoconfiguration, default is `true`.
369-
Set it to `false` in case consumer application need to define Security advice configurations explicitly.
369+
Set it to `false` in case a consumer application needs to define Security advice configurations explicitly.
370370
* `problem.open-api.path`:- OpenAPI Specification path. Ideally should be in classpath and start with`/`.
371371
If not specified, OpenAPI Specification validation is not enabled.
372372
* `problem.open-api.exclude-patterns`:- List of `URI` Ant patterns to be excluded from OpenAPI specification validation. Default is empty.
@@ -377,7 +377,7 @@ problem.open-api.res-validation-enabled=false
377377
The main concept behind specifying the error attributes in `properties` file is **Error key**, which is mandatory to be unique for each error scenario.
378378
**It is either derived or specified by application** while throwing exception and used to externalize the error attributes in `properties` file.
379379

380-
For example if error key for some exception is `some.error.key`, then error response attributes can be specified in `properties` file as follows.
380+
For example, if error key for some exception is `some.error.key`, then error response attributes can be specified in `properties` file as follows.
381381
```properties
382382
code.some.error.key=some-error
383383
title.some.error.key=Some Error
@@ -433,7 +433,7 @@ content-type: application/problem+xml
433433
Used in `type`. Commonly used to set unique codes for different business error scenarios.
434434

435435
## Message resolvers
436-
To know how to define the error attributes in properties file, enable debugging as follows.
436+
To know how to define the error attributes in the properties file, enable debugging as follows.
437437
```properties
438438
problem.debug-enabled=true
439439
```
@@ -480,7 +480,7 @@ For example in case of `ConstraintViolationException` `codes` would be multiple
480480
}
481481
}
482482
```
483-
Respective codes for corresponding attribute can be copied and message can be specified for same in `properties` file.
483+
Respective codes for corresponding attribute can be copied, and a message can be specified for the same in `properties` file.
484484

485485
> [!NOTE]
486486
> `org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException` i.e. fully qualified name of exception is the [*Error key*](https://github.com/officiallysingh/spring-boot-problem-handler#error-key) in above case.
@@ -497,8 +497,8 @@ detail.org.springframework.batch.core.repository.JobInstanceAlreadyCompleteExcep
497497
```
498498

499499
To minimize the number of properties following defaults are taken if `HttpStatus` is specified as `status.`(error key) property.
500-
* **Code** is taken as specified `HttpStatus`'s int code e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Code default would be `417`
501-
* **Title** is taken as specified `HttpStatus`'s reason phrase e.g. if `HttpStatus` is given as `EXPECTATION_FAILED` then the Title default would be `Expectation Failed`
500+
* **Code** is taken as specified `HttpStatus`'s int code e.g., if `HttpStatus` is given as `EXPECTATION_FAILED` then the Code default would be `417`
501+
* **Title** is taken as specified `HttpStatus`'s reason phrase e.g., if `HttpStatus` is given as `EXPECTATION_FAILED` then the Title default would be `Expectation Failed`
502502
* **Detail** default is taken from thrown exception's `exception.getMessage()`.
503503

504504
> [!NOTE]
@@ -521,7 +521,7 @@ It provides multiple fluent methods to build and throw exceptions.
521521
throw Problems.newInstance("sample.problem").throwAble(HttpStatus.EXPECTATION_FAILED);
522522
```
523523
Error response attributes `code`, `title` and `detail` are expected from the message source (`properties` file) available as follows.
524-
Notice the [*Error key*](https://github.com/officiallysingh/spring-boot-problem-handler#error-key) **sample.problem** in following properties
524+
Notice the [*Error key*](https://github.com/officiallysingh/spring-boot-problem-handler#error-key) **sample.problem** in the following properties
525525

526526
```properties
527527
code.sample.problem=AYX123
@@ -576,7 +576,7 @@ throw problem;
576576

577577
* Applications may also define `enum`s implementing [**`ErrorType`**](src/main/java/com/ksoot/problem/core/ErrorType.java) interface
578578
with attributes for error scenarios and creating exceptions as follows. Default error attributes `detail`, `status` etc. can be customized in `properties` file for given `errorKey`,
579-
otherwise the enum only is sufficient.
579+
otherwise the enum only is enough.
580580
```java
581581
@Getter
582582
public enum AppErrors implements ErrorType {
@@ -803,7 +803,7 @@ class CustomMethodArgumentNotValidExceptionHandler implements MethodArgumentNotV
803803
There should not be any need to create any custom exception hence new advices, but if there is a pressing need to do so,
804804
custom exception can be created and corresponding custom `ControllerAdvice` implementing [**`AdviceTrait`**](src/main/java/com/ksoot/problem/spring/advice/AdviceTrait.java)
805805
can be defined for the same, though not recommended.
806-
Following example demonstrates a new advice for some custom exception `MyCustomException`.
806+
Following example demonstrates new advice for some custom exception `MyCustomException`.
807807

808808
> For Spring Web applications
809809
```java
@@ -1179,4 +1179,4 @@ as examples to see usage and **example error responses** for different kind of e
11791179

11801180
## Known Issues
11811181
* If an application uses multiple vendor relational databases then the [**`ConstraintNameResolver`**](src/main/java/com/ksoot/problem/spring/advice/dao/ConstraintNameResolver.java)
1182-
may not work properly, needs further testing. For example if it is using Postgres and SQL Server both.
1182+
may not work properly, needs further testing. For example, if it is using Postgres and SQL Server both.

pom.xml

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232

3333
<properties>
3434
<java.version>17</java.version>
35-
<spring-boot.version>3.2.5</spring-boot.version>
36-
<spring-cloud.version>2023.0.1</spring-cloud.version>
35+
<spring-boot.version>3.3.4</spring-boot.version>
36+
<spring-cloud.version>2023.0.3</spring-cloud.version>
3737
<jakarta.servlet-api.version>6.0.0</jakarta.servlet-api.version>
3838
<jakarta.annotation-api.version>2.1.1</jakarta.annotation-api.version>
3939
<swagger-request-validator-spring-webmvc.version>2.40.0</swagger-request-validator-spring-webmvc.version>
4040
<commons-collections4.version>4.4</commons-collections4.version>
41-
<guava.version>33.1.0-jre</guava.version>
41+
<guava.version>32.1.3-jre</guava.version>
4242
<failsafe.version>2.4.4</failsafe.version>
4343

4444
<scm.connection>scm:git:git@github.com:officiallysingh/spring-boot-problem-handler.git</scm.connection>
@@ -51,6 +51,7 @@
5151

5252
<fmt-maven-plugin.version>2.23</fmt-maven-plugin.version>
5353
<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
54+
<central-publishing-maven-plugin.version>0.6.0</central-publishing-maven-plugin.version>
5455

5556
<maven.compiler.source>${java.version}</maven.compiler.source>
5657
<maven.compiler.target>${java.version}</maven.compiler.target>
@@ -92,6 +93,7 @@
9293
<dependency>
9394
<groupId>org.apache.commons</groupId>
9495
<artifactId>commons-collections4</artifactId>
96+
<version>${commons-collections4.version}</version>
9597
</dependency>
9698
<dependency>
9799
<groupId>jakarta.annotation</groupId>
@@ -150,6 +152,12 @@
150152
<artifactId>lombok</artifactId>
151153
<scope>provided</scope>
152154
</dependency>
155+
156+
<dependency>
157+
<groupId>org.sonatype.central</groupId>
158+
<artifactId>central-publishing-maven-plugin</artifactId>
159+
<version>${central-publishing-maven-plugin.version}</version>
160+
</dependency>
153161
</dependencies>
154162

155163
<scm>
@@ -173,32 +181,9 @@
173181
<goals>
174182
<goal>format</goal>
175183
</goals>
176-
177184
</execution>
178185
</executions>
179186
</plugin>
180-
181-
<!-- Apply checkstyle -->
182-
<!-- <plugin>-->
183-
<!-- <groupId>org.apache.maven.plugins</groupId>-->
184-
<!-- <artifactId>maven-checkstyle-plugin</artifactId>-->
185-
<!-- <version>${maven-checkstyle-plugin.version}</version>-->
186-
<!-- <configuration>-->
187-
<!-- <configLocation>${project.basedir}/tooling/checkstyle.xml</configLocation>-->
188-
<!-- <suppressionsLocation>-->
189-
<!-- ${project.basedir}/tooling/checkstyle-suppressions.xml</suppressionsLocation>-->
190-
<!-- <excludes>**/package-info.java</excludes>-->
191-
<!-- <includeTestSourceDirectory>true</includeTestSourceDirectory>-->
192-
<!-- <skip>true</skip>-->
193-
<!-- </configuration>-->
194-
<!-- <executions>-->
195-
<!-- <execution>-->
196-
<!-- <goals>-->
197-
<!-- <goal>check</goal>-->
198-
<!-- </goals>-->
199-
<!-- </execution>-->
200-
<!-- </executions>-->
201-
<!-- </plugin>-->
202187
</plugins>
203188
</build>
204189

@@ -212,11 +197,11 @@
212197
<distributionManagement>
213198
<snapshotRepository>
214199
<id>ossrh</id>
215-
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
200+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
216201
</snapshotRepository>
217202
<repository>
218203
<id>ossrh</id>
219-
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
204+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
220205
</repository>
221206
</distributionManagement>
222207

@@ -276,14 +261,14 @@
276261
</executions>
277262
</plugin>
278263
<plugin>
279-
<groupId>org.sonatype.plugins</groupId>
280-
<artifactId>nexus-staging-maven-plugin</artifactId>
281-
<version>${nexus-staging-maven-plugin.version}</version>
264+
<groupId>org.sonatype.central</groupId>
265+
<artifactId>central-publishing-maven-plugin</artifactId>
266+
<version>${central-publishing-maven-plugin.version}</version>
282267
<extensions>true</extensions>
283268
<configuration>
284-
<serverId>ossrh</serverId>
285-
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
286-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
269+
<publishingServerId>central</publishingServerId>
270+
<autoPublish>true</autoPublish>
271+
<waitUntil>published</waitUntil>
287272
</configuration>
288273
</plugin>
289274
</plugins>

0 commit comments

Comments
 (0)