From 0b2c0c116a3956eb14a92bc2bd3b3a6057264dce Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Mon, 6 Dec 2021 17:34:20 +0200 Subject: [PATCH] Allow the use of UriInfo in @ServerResponseFilter Fixes: #21956 --- .../test/customproviders/CustomContainerResponseFilter.java | 5 ++++- .../processor/generation/filters/CustomFilterGenerator.java | 5 +++++ .../jboss/resteasy/reactive/server/ServerResponseFilter.java | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customproviders/CustomContainerResponseFilter.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customproviders/CustomContainerResponseFilter.java index 7b4315c568fb7..bab2ffa503052 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customproviders/CustomContainerResponseFilter.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive/deployment/src/test/java/io/quarkus/resteasy/reactive/server/test/customproviders/CustomContainerResponseFilter.java @@ -1,10 +1,12 @@ package io.quarkus.resteasy.reactive.server.test.customproviders; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.core.UriInfo; import org.jboss.resteasy.reactive.server.ServerResponseFilter; import org.jboss.resteasy.reactive.server.SimpleResourceInfo; @@ -14,10 +16,11 @@ public class CustomContainerResponseFilter { @ServerResponseFilter public void whatever(SimpleResourceInfo simplifiedResourceInfo, ContainerResponseContext responseContext, - ContainerRequestContext requestContext, Throwable t) { + ContainerRequestContext requestContext, UriInfo uriInfo, Throwable t) { assertTrue( PreventAbortResteasyReactiveContainerRequestContext.class.isAssignableFrom(requestContext.getClass())); assertNull(t); + assertNotNull(uriInfo); if (simplifiedResourceInfo != null) { responseContext.getHeaders().putSingle("java-method", simplifiedResourceInfo.getMethodName()); } diff --git a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java index 1395c8c9e5fcb..0f119441e6c0a 100644 --- a/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java +++ b/independent-projects/resteasy-reactive/server/processor/src/main/java/org/jboss/resteasy/reactive/server/processor/generation/filters/CustomFilterGenerator.java @@ -488,6 +488,11 @@ private static ResultHandle[] getResponseFilterResultHandles(MethodInfo targetMe targetMethodParamHandles[i] = filterMethod.getMethodParam(1); } else if (unwrappableTypes.contains(paramDotName)) { targetMethodParamHandles[i] = GeneratorUtils.unwrapObject(filterMethod, rrReqCtxHandle, paramDotName); + } else if (URI_INFO.equals(paramDotName)) { + GeneratorUtils.paramHandleFromReqContextMethod(filterMethod, rrReqCtxHandle, targetMethodParamHandles, + i, + "getUriInfo", + URI_INFO); } else if (RESOURCE_INFO.equals(paramDotName)) { targetMethodParamHandles[i] = getResourceInfoHandle(filterMethod, rrReqCtxHandle); } else if (ResteasyReactiveServerDotNames.SIMPLIFIED_RESOURCE_INFO.equals(paramDotName)) { diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/ServerResponseFilter.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/ServerResponseFilter.java index daf7fa44c1e1c..4247098221019 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/ServerResponseFilter.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/ServerResponseFilter.java @@ -8,6 +8,7 @@ import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerResponseContext; import javax.ws.rs.container.ResourceInfo; +import javax.ws.rs.core.UriInfo; /** * When used on a method, then an implementation of {@link javax.ws.rs.container.ContainerResponseContext} is generated @@ -41,6 +42,7 @@ *
  • {@link ContainerRequestContext} *
  • {@link ContainerResponseContext} *
  • {@link ResourceInfo} + *
  • {@link UriInfo} *
  • {@link SimpleResourceInfo} *
  • {@link Throwable} - The thrown exception - or {@code null} if no exception was thrown *