Skip to content

Commit

Permalink
Allow disabling Jackson exception mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Oct 25, 2024
1 parent bec7366 commit 4194208
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 69 deletions.
32 changes: 19 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# Version 3.15.0 (2021-09-30)

* [new] Java 21 support.
* [new] Support for `jakarta.inject.*` while retaining `javax.inject.*` compatibility.
* [nfo] Other `jakarta.*` packages are not supported yet.
* [chg] Update javassist to 3.30.2-GA
* [chg] Update guice to 6.0.0
* [chg] Update guava to 33.1.0
* [chg] Update typetools to 0.6.3
* [chg] Update shiro to 1.13.0
* [chg] Update Undertow to 2.2.31.Final
* [chg] Update Jersey to 2.42
* [chg] Update Hibernate Validator to 6.1.7.Final
# Version 3.15.1 (2024-10-25)

* **[new]** Allow to disable Jackson exception mappers as they may disclose technical info to REST clients.
Set `rest.exceptionMapping.jackson` and `rest.exceptionMapping.detailedUserMessage` to `false`. The exception will
go through the default exception mapper, which logs them. To avoid this provide your own exception mapper.

# Version 3.15.0 (2024-04-17)

* **[new]** Java 21 support.
* **[new]** Support for `jakarta.inject.*` while retaining `javax.inject.*` compatibility.
* **[nfo]** Other `jakarta.*` packages are not supported yet.
* **[chg]** Update javassist to 3.30.2-GA
* **[chg]** Update guice to 6.0.0
* **[chg]** Update guava to 33.1.0
* **[chg]** Update typetools to 0.6.3
* **[chg]** Update shiro to 1.13.0
* **[chg]** Update Undertow to 2.2.31.Final
* **[chg]** Update Jersey to 2.42
* **[chg]** Update Hibernate Validator to 6.1.7.Final

# Version 3.14.0 (2021-09-30)

Expand Down
2 changes: 1 addition & 1 deletion cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-cli</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-core</artifactId>
Expand Down
8 changes: 6 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
Expand All @@ -38,7 +38,11 @@
<aopalliance.version>1.0</aopalliance.version>
<glassfish-javax.el.version>3.0.0</glassfish-javax.el.version>
<arquillian.version>1.4.0.Final</arquillian.version>
<tomcat.version>7.0.86</tomcat.version>
<tomcat.version>9.0.90</tomcat.version>
<javax.servlet.version>4.0.1</javax.servlet.version>
<javax.websocket-api.version>1.1</javax.websocket-api.version>
<rest-assured.version>5.4.0</rest-assured.version>
<arquillian-tomcat-embedded-9.version>1.1.0.Final</arquillian-tomcat-embedded-9.version>

<compatibility.version>3.1.0</compatibility.version>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion rest/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-rest-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ private void configureExceptionMappers() {
LOGGER.debug("Default exception mapping is enabled");
}

if (!restConfig.exceptionMapping().isJackson()) {
providers.remove(JsonMappingExceptionMapper.class);
providers.remove(JsonParseExceptionMapper.class);
LOGGER.debug("Jackson exception mapping is disabled");
} else {
LOGGER.debug("Jackson exception mapping is enabled");
}

if (!isDynamicValidationSupported() || !restConfig.exceptionMapping().isValidation()) {
providers.remove(ValidationExceptionMapper.class);
LOGGER.debug("Validation exception mapping is disabled");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
package org.seedstack.seed.rest.internal.exceptionmapper;

import org.seedstack.seed.Application;
import org.seedstack.seed.core.Seed;
import org.seedstack.seed.rest.RestConfig;
import org.seedstack.shed.exception.BaseException;
import org.slf4j.Logger;
Expand Down Expand Up @@ -41,29 +40,28 @@ public InternalErrorExceptionMapper(Application application) {
@Override
public Response toResponse(Exception exception) {
String uuid = UUID.randomUUID().toString();
BaseException translatedException = Seed.translateException(exception);
LOGGER.error(buildServerMessage(uuid, translatedException), translatedException);
LOGGER.error(buildServerMessage(uuid, exception), exception);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(buildUserMessage(uuid, translatedException))
.entity(buildUserMessage(uuid, exception))
.build();
}

private String buildUserMessage(String uuid, BaseException baseException) {
private String buildUserMessage(String uuid, Exception exception) {
StringBuilder sb = new StringBuilder(16384);
sb.append("Internal server error [").append(uuid).append("]");
if (exceptionMappingConfig.isDetailedUserMessage()) {
sb.append(": ").append(baseException.getDescription());
sb.append(": ").append(exception instanceof BaseException ? ((BaseException) exception).getDescription() : exception.getMessage());
}
return sb.toString();
}

private String buildServerMessage(String uuid, BaseException baseException) {
private String buildServerMessage(String uuid, Exception exception) {
StringBuilder sb = new StringBuilder(16384);
sb.append("JAX-RS request error [").append(uuid).append("] on ").append(request.getRequestURI()).append("\n");
if (exceptionMappingConfig.isDetailedLog()) {
sb.append(baseException.toString());
sb.append(exception.toString());
} else {
sb.append(baseException.getMessage());
sb.append(exception.getMessage());
}
return sb.toString();
}
Expand Down
18 changes: 9 additions & 9 deletions rest/jersey2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-rest-jersey2</artifactId>
Expand Down Expand Up @@ -154,8 +154,8 @@
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.1.Final</version>
<artifactId>arquillian-tomcat-embedded-9</artifactId>
<version>${arquillian-tomcat-embedded-9.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -170,12 +170,12 @@
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.tomcat.embed</groupId>-->
<!-- <artifactId>tomcat-embed-logging-juli</artifactId>-->
<!-- <version>${tomcat.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-rest</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion rest/specs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-rest</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-rest-specs</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public static class ExceptionMappingConfig {
private boolean validation = true;
private boolean detailedLog = true;
private boolean detailedUserMessage = true;
private boolean jackson = true;

public boolean isSecurity() {
return security;
Expand All @@ -146,6 +147,10 @@ public boolean isDetailedLog() {
return detailedLog;
}

public boolean isJackson() {
return jackson;
}

public boolean isDetailedUserMessage() {
return detailedUserMessage;
}
Expand Down
2 changes: 1 addition & 1 deletion security/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-security</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-security-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-security</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion security/specs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-security</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-security-specs</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion specs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-specs</artifactId>
Expand Down
18 changes: 9 additions & 9 deletions testing/arquillian/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-testing</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-testing-arquillian</artifactId>
Expand Down Expand Up @@ -67,8 +67,8 @@
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.1.Final</version>
<artifactId>arquillian-tomcat-embedded-9</artifactId>
<version>${arquillian-tomcat-embedded-9.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -77,12 +77,12 @@
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.tomcat.embed</groupId>-->
<!-- <artifactId>tomcat-embed-logging-juli</artifactId>-->
<!-- <version>${tomcat.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion testing/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-testing</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-testing-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion testing/junit4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-testing</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-testing-junit4</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-testing</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion testing/specs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-testing</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-testing-specs</artifactId>
Expand Down
18 changes: 9 additions & 9 deletions web/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-web-core</artifactId>
Expand Down Expand Up @@ -101,8 +101,8 @@
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-tomcat-embedded-7</artifactId>
<version>1.0.1.Final</version>
<artifactId>arquillian-tomcat-embedded-9</artifactId>
<version>${arquillian-tomcat-embedded-9.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -117,12 +117,12 @@
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-logging-juli</artifactId>
<version>${tomcat.version}</version>
<scope>test</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.tomcat.embed</groupId>-->
<!-- <artifactId>tomcat-embed-logging-juli</artifactId>-->
<!-- <version>${tomcat.version}</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public void sessionCookieConfigIsHonored() {
.statusCode(200)
.cookie("CUSTOM_SESSION_ID", RestAssuredMatchers.detailedCookie()
.maxAge(15)
.comment("Custom")
.httpOnly(true)
)
.when()
Expand Down
2 changes: 1 addition & 1 deletion web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-web</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion web/security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.seedstack.seed</groupId>
<artifactId>seed-web</artifactId>
<version>3.15.0-SNAPSHOT</version>
<version>3.15.1-SNAPSHOT</version>
</parent>

<artifactId>seed-web-security</artifactId>
Expand Down
Loading

0 comments on commit 4194208

Please sign in to comment.