Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from Zalando to Spring Framework 6 problem support implementation #19991[skip-ci] #20080

Merged
merged 15 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ inputs:
jhipster-bom-repository:
description: 'JHipster BOM repository'
required: false
default: https://github.com/jhipster/jhipster-bom.git
default: https://github.com/dwarakaprasad/jhipster-bom
mshima marked this conversation as resolved.
Show resolved Hide resolved
jhipster-bom-branch:
description: 'JHipster BOM branch'
required: false
default: spring-boot-3.0-m4
default: fix_19991_spring_boot3_problem
mshima marked this conversation as resolved.
Show resolved Hide resolved
jhipster-bom-directory:
description: 'JHipster BOM path'
required: false
Expand Down
5 changes: 0 additions & 5 deletions generators/server/templates/pom.xml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,6 @@
<scope>test</scope>
</dependency>
<%_ } _%>
<dependency>
<groupId>org.zalando</groupId>
<artifactId>problem-spring-web<% if (reactive) { %>flux<%_ } _%></artifactId>
</dependency>
<%_ if (!reactive) { _%>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -1384,7 +1380,6 @@
<apiPackage><%= packageName %>.web.api</apiPackage>
<modelPackage><%= packageName %>.service.api.dto</modelPackage>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<importMappings>Problem=org.zalando.problem.Problem</importMappings>
<skipValidateSpec>false</skipValidateSpec>
<configOptions>
<%_ if (reactive) { _%>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.zalando.problem.jackson.ProblemModule;
import org.zalando.problem.violations.ConstraintViolationProblemModule;

@Configuration
public class JacksonConfiguration {
Expand Down Expand Up @@ -55,20 +53,4 @@ public class JacksonConfiguration {
return new Hibernate5JakartaModule();
}
<%_ } _%>

/*
* Module for serialization/deserialization of RFC7807 Problem.
*/
@Bean
public ProblemModule problemModule() {
return new ProblemModule();
}

/*
* Module for serialization/deserialization of ConstraintViolationProblem.
*/
@Bean
public ConstraintViolationProblemModule constraintViolationProblemModule() {
return new ConstraintViolationProblemModule();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.reactive.config.WebFluxConfigurer;
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolver;
import org.springframework.web.server.WebExceptionHandler;
import org.zalando.problem.spring.webflux.advice.ProblemExceptionHandler;
import org.zalando.problem.spring.webflux.advice.ProblemHandling;
import <%= packageName %>.web.rest.errors.ExceptionTranslator;
import tech.jhipster.web.rest.errors.ReactiveWebExceptionHandler;
<%_ } _%>
<%_ if (!reactive) { _%>

Expand Down Expand Up @@ -215,13 +215,12 @@ public class WebConfigurer implements <% if (!reactive) { %>ServletContextInitia
}
<%_ } _%>

/*
@Bean
@Order(-2) // The handler must have precedence over WebFluxResponseStatusExceptionHandler and Spring Boot's ErrorWebExceptionHandler
DanielFran marked this conversation as resolved.
Show resolved Hide resolved
public WebExceptionHandler problemExceptionHandler(ObjectMapper mapper, ProblemHandling problemHandling) {
return new ProblemExceptionHandler(mapper, problemHandling);
public WebExceptionHandler problemExceptionHandler(ObjectMapper mapper, ExceptionTranslator problemHandling) {
return new ReactiveWebExceptionHandler(problemHandling, mapper);
}
*/

<%_ if (!skipClient) { _%>

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
-%>
package <%= packageName %>.web.rest.errors;

import org.zalando.problem.AbstractThrowableProblem;
import org.zalando.problem.Status;
import org.springframework.http.HttpStatus;
import org.springframework.web.ErrorResponseException;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("java:S110") // Inheritance tree of classes should not be too deep
public class BadRequestAlertException extends AbstractThrowableProblem {
public class BadRequestAlertException extends ErrorResponseException {

private static final long serialVersionUID = 1L;

Expand All @@ -39,7 +39,11 @@ public class BadRequestAlertException extends AbstractThrowableProblem {
}

public BadRequestAlertException(URI type, String defaultMessage, String entityName, String errorKey) {
super(type, defaultMessage, Status.BAD_REQUEST, null, null, null, getAlertParameters(entityName, errorKey));
super(HttpStatus.BAD_REQUEST);
this.getBody().setProperty("message", "error." + errorKey);
this.getBody().setProperty("params", entityName);
this.setType(type);
this.setTitle(defaultMessage);
this.entityName = entityName;
this.errorKey = errorKey;
}
Expand Down
Loading