Merge pull request #34503 from vy

* gh-34503:
  Polish "Allow ProblemDetailsExceptionHandlers to be proxied"
  Allow ProblemDetailsExceptionHandlers to be proxied

Closes gh-34503
This commit is contained in:
Andy Wilkinson 2023-03-23 20:54:41 +00:00
commit 4375f44979
4 changed files with 54 additions and 2 deletions

View File

@ -26,6 +26,6 @@ import org.springframework.web.reactive.result.method.annotation.ResponseEntityE
* @author Brian Clozel
*/
@ControllerAdvice
final class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
}

View File

@ -26,6 +26,6 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExcep
* @author Brian Clozel
*/
@ControllerAdvice
final class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
class ProblemDetailsExceptionHandler extends ResponseEntityExceptionHandler {
}

View File

@ -32,12 +32,17 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import jakarta.validation.ValidatorFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.aop.support.AopUtils;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
import org.springframework.boot.autoconfigure.validation.ValidatorAdapter;
import org.springframework.boot.autoconfigure.web.ServerProperties;
@ -645,6 +650,17 @@ class WebFluxAutoConfigurationTests {
.run((context) -> assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class));
}
@Test
void problemDetailsExceptionHandlerDoesNotPreventProxying() {
this.contextRunner.withConfiguration(AutoConfigurations.of(AopAutoConfiguration.class))
.withBean(ExceptionHandlerInterceptor.class)
.withPropertyValues("spring.webflux.problemdetails.enabled:true")
.run((context) -> {
assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class);
assertThat(AopUtils.isCglibProxy(context.getBean(ProblemDetailsExceptionHandler.class)));
});
}
@Test
void problemDetailsBacksOffWhenExceptionHandler() {
this.contextRunner.withPropertyValues("spring.webflux.problemdetails.enabled:true")
@ -957,4 +973,14 @@ class WebFluxAutoConfigurationTests {
}
@Aspect
static class ExceptionHandlerInterceptor {
@AfterReturning(pointcut = "@annotation(org.springframework.web.bind.annotation.ExceptionHandler)",
returning = "returnValue")
void exceptionHandlerIntercept(JoinPoint joinPoint, Object returnValue) {
}
}
}

View File

@ -36,9 +36,14 @@ import java.util.function.Consumer;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.ValidatorFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.junit.jupiter.api.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.boot.autoconfigure.http.HttpMessageConvertersAutoConfiguration;
@ -988,6 +993,17 @@ class WebMvcAutoConfigurationTests {
.run((context) -> assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class));
}
@Test
void problemDetailsExceptionHandlerDoesNotPreventProxying() {
this.contextRunner.withConfiguration(AutoConfigurations.of(AopAutoConfiguration.class))
.withBean(ExceptionHandlerInterceptor.class)
.withPropertyValues("spring.mvc.problemdetails.enabled:true")
.run((context) -> {
assertThat(context).hasSingleBean(ProblemDetailsExceptionHandler.class);
assertThat(AopUtils.isCglibProxy(context.getBean(ProblemDetailsExceptionHandler.class)));
});
}
@Test
void problemDetailsBacksOffWhenExceptionHandler() {
this.contextRunner.withPropertyValues("spring.mvc.problemdetails.enabled:true")
@ -1539,4 +1555,14 @@ class WebMvcAutoConfigurationTests {
}
@Aspect
static class ExceptionHandlerInterceptor {
@AfterReturning(pointcut = "@annotation(org.springframework.web.bind.annotation.ExceptionHandler)",
returning = "returnValue")
void exceptionHandlerIntercept(JoinPoint joinPoint, Object returnValue) {
}
}
}