From aa721fe490334ceb6e18e7258c6b1b245f62f912 Mon Sep 17 00:00:00 2001 From: dwarakaprasad Date: Sat, 22 Oct 2022 09:47:00 -0400 Subject: [PATCH 1/3] change response type of ExceptionTranslation to Object for ResponseEntityExceptionHandler support fixes jhipster/generator-jhipster#19991 --- .../tech/jhipster/web/rest/errors/ExceptionTranslation.java | 2 +- .../jhipster/web/rest/errors/ReactiveWebExceptionHandler.java | 4 ++-- .../web/rest/errors/ReactiveWebExceptionHandlerTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ExceptionTranslation.java b/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ExceptionTranslation.java index 3338e5fb4..92bc238d7 100644 --- a/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ExceptionTranslation.java +++ b/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ExceptionTranslation.java @@ -38,5 +38,5 @@ public interface ExceptionTranslation { * @param request The request that is being served * @return Returns the Responseentity containing the ProblemDetail */ - public Mono> handleAnyException(Throwable ex, ServerWebExchange request); + public Mono> handleAnyException(Throwable ex, ServerWebExchange request); } diff --git a/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandler.java b/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandler.java index 8dff3d7fe..fdbcbb1be 100644 --- a/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandler.java +++ b/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandler.java @@ -57,13 +57,13 @@ public ReactiveWebExceptionHandler(ExceptionTranslation translator, ObjectMapper @Override public Mono handle(final ServerWebExchange exchange, final Throwable throwable) { if (throwable instanceof ResponseStatusException) { - final Mono> entityMono = translator.handleAnyException(throwable, exchange); + final Mono> entityMono = translator.handleAnyException(throwable, exchange); return entityMono.flatMap(entity -> this.setHttpResponse(entity, exchange, mapper)); } return Mono.error(throwable); } - private Mono setHttpResponse(final ResponseEntity entity, final ServerWebExchange exchange, + private Mono setHttpResponse(final ResponseEntity entity, final ServerWebExchange exchange, final ObjectMapper mapper) { final ServerHttpResponse response = exchange.getResponse(); response.setStatusCode(entity.getStatusCode()); diff --git a/jhipster-framework/src/test/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandlerTest.java b/jhipster-framework/src/test/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandlerTest.java index 427c8aaf2..30653c7a0 100644 --- a/jhipster-framework/src/test/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandlerTest.java +++ b/jhipster-framework/src/test/java/tech/jhipster/web/rest/errors/ReactiveWebExceptionHandlerTest.java @@ -80,7 +80,7 @@ private static ProblemDetail getProblemDetail() { private static class TestExceptionTranslation implements ExceptionTranslation { @Override - public Mono> handleAnyException(Throwable ex, ServerWebExchange request) { + public Mono> handleAnyException(Throwable ex, ServerWebExchange request) { logger.trace("Stub ExceptionTranslation handleAnyException invoked"); ProblemDetail problem = getProblemDetail(); HttpHeaders header = new HttpHeaders(); From 070d8421da3747ad21880545b29b4edea1aae6e3 Mon Sep 17 00:00:00 2001 From: Matt Raible Date: Thu, 27 Oct 2022 10:32:30 +0100 Subject: [PATCH 2/3] Remove Zalando (problem-spring) dependencies --- jhipster-dependencies/pom.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/jhipster-dependencies/pom.xml b/jhipster-dependencies/pom.xml index 3238e682a..b41910169 100644 --- a/jhipster-dependencies/pom.xml +++ b/jhipster-dependencies/pom.xml @@ -67,9 +67,6 @@ 1.13.1 8.0.30 21.7.0.0 - 0.27.0 - ${problem-spring.version} - ${problem-spring.version} 0.15.0 3.17.7 0.10.1 @@ -258,16 +255,6 @@ ojdbc8 ${oracle-jdbc.version} - - org.zalando - problem-spring-web - ${problem-spring-web.version} - - - org.zalando - problem-spring-webflux - ${problem-spring-webflux.version} - io.prometheus simpleclient From dfd053880b4c73b5923fb66611fd300feba0d014 Mon Sep 17 00:00:00 2001 From: dwarakaprasad Date: Fri, 28 Oct 2022 18:25:55 -0400 Subject: [PATCH 3/3] ProblemDetail with cause information as nested ProblemDetail fix# jhipster/generator-jhipster#19991 --- .../rest/errors/ProblemDetailWithCause.java | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ProblemDetailWithCause.java diff --git a/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ProblemDetailWithCause.java b/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ProblemDetailWithCause.java new file mode 100644 index 000000000..30d9f23e3 --- /dev/null +++ b/jhipster-framework/src/main/java/tech/jhipster/web/rest/errors/ProblemDetailWithCause.java @@ -0,0 +1,117 @@ +/* + * Copyright 2016-2022 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package tech.jhipster.web.rest.errors; + +import java.net.URI; +import java.util.HashMap; +import java.util.Map; +import org.springframework.http.ProblemDetail; + +/* + * Class that extends Spring's ProblemDetail and has a Builder implementation. + */ +public class ProblemDetailWithCause extends ProblemDetail { + private ProblemDetailWithCause cause; + + ProblemDetailWithCause(int rawStatus) { + super(rawStatus); + } + + ProblemDetailWithCause(int rawStatus, ProblemDetailWithCause cause) { + super(rawStatus); + this.cause = cause; + } + + public ProblemDetailWithCause getCause() { + return cause; + } + + public void setCause(ProblemDetailWithCause cause) { + this.cause = cause; + } + + // The missing builder from Spring + public static class ProblemDetailWithCauseBuilder { + private static final URI BLANK_TYPE = URI.create("about:blank"); + // From Springs Problem Detail + private URI type = BLANK_TYPE; + private String title; + private int status; + private String detail; + private URI instance; + private Map properties = new HashMap<>(); + private ProblemDetailWithCause cause; + + public static ProblemDetailWithCauseBuilder instance(){ + return new ProblemDetailWithCauseBuilder(); + } + + public ProblemDetailWithCauseBuilder withType(URI type) { + this.type = type; + return this; + } + + public ProblemDetailWithCauseBuilder withTitle(String title) { + this.title = title; + return this; + } + + public ProblemDetailWithCauseBuilder withStatus(int status) { + this.status = status; + return this; + } + + public ProblemDetailWithCauseBuilder withDetail(String detail) { + this.detail = detail; + return this; + } + + public ProblemDetailWithCauseBuilder withInstance(URI instance) { + this.instance = instance; + return this; + } + + public ProblemDetailWithCauseBuilder withCause(ProblemDetailWithCause cause) { + this.cause = cause; + return this; + } + + public ProblemDetailWithCauseBuilder withProperties(Map properties) { + this.properties = properties; + return this; + } + + public ProblemDetailWithCauseBuilder withProperty(String key, Object value) { + this.properties.put(key, value); + return this; + } + + public ProblemDetailWithCause build() { + ProblemDetailWithCause cause = new ProblemDetailWithCause(this.status); + cause.setType(this.type); + cause.setTitle(this.title); + cause.setDetail(this.detail); + cause.setInstance(this.instance); + this.properties.forEach(cause::setProperty); + cause.setCause(this.cause); + return cause; + } + } +}