diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveInterceptorScanner.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveInterceptorScanner.java index ccc0cbcca9eec..a2fed642be09f 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveInterceptorScanner.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/scanning/ResteasyReactiveInterceptorScanner.java @@ -11,6 +11,7 @@ import java.util.Set; import java.util.function.Function; +import jakarta.ws.rs.RuntimeType; import jakarta.ws.rs.container.ContainerRequestFilter; import jakarta.ws.rs.container.ContainerResponseFilter; @@ -24,6 +25,7 @@ import org.jboss.resteasy.reactive.common.model.ResourceInterceptor; import org.jboss.resteasy.reactive.common.model.ResourceInterceptors; import org.jboss.resteasy.reactive.common.processor.NameBindingUtil; +import org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames; import org.jboss.resteasy.reactive.spi.BeanFactory; /** @@ -221,6 +223,18 @@ private static ResourceInterceptor handleDiscoveredInterceptor( interceptorContainer.addNameRequestInterceptor(interceptor); } } + + RuntimeType runtimeType = null; + if (keepProviderResult == ApplicationScanningResult.KeepProviderResult.SERVER_ONLY) { + runtimeType = RuntimeType.SERVER; + } + AnnotationInstance constrainedToInstance = filterClass + .declaredAnnotation(ResteasyReactiveDotNames.CONSTRAINED_TO); + if (constrainedToInstance != null) { + runtimeType = RuntimeType.valueOf(constrainedToInstance.value().asEnum()); + } + interceptor.setRuntimeType(runtimeType); + return interceptor; } diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceInterceptor.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceInterceptor.java index ab224307bcd25..b4bdd4e8f09f0 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceInterceptor.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/model/ResourceInterceptor.java @@ -5,6 +5,7 @@ import java.util.Set; import jakarta.ws.rs.Priorities; +import jakarta.ws.rs.RuntimeType; import org.jboss.resteasy.reactive.spi.BeanFactory; @@ -25,7 +26,9 @@ public class ResourceInterceptor private String className; - public transient Map metadata; // by using 'public transient' we ensure that this field will not be populated at runtime + public transient Map metadata; // by using 'public transient' we ensure that this field will not be populated at runtime \ + + private RuntimeType runtimeType; public void setFactory(BeanFactory factory) { this.factory = factory; @@ -84,6 +87,14 @@ public void setWithFormRead(boolean withFormRead) { this.withFormRead = withFormRead; } + public RuntimeType getRuntimeType() { + return runtimeType; + } + + public void setRuntimeType(RuntimeType runtimeType) { + this.runtimeType = runtimeType; + } + // spec says that writer interceptors are sorted in ascending order @Override public int compareTo(ResourceInterceptor o) { diff --git a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeInterceptorDeployment.java b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeInterceptorDeployment.java index 4ff5dc74e2c2a..7679f9e2d0c44 100644 --- a/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeInterceptorDeployment.java +++ b/independent-projects/resteasy-reactive/server/runtime/src/main/java/org/jboss/resteasy/reactive/server/core/startup/RuntimeInterceptorDeployment.java @@ -10,6 +10,7 @@ import java.util.TreeMap; import java.util.function.Consumer; +import jakarta.ws.rs.RuntimeType; import jakarta.ws.rs.container.ContainerRequestFilter; import jakarta.ws.rs.container.ContainerResponseFilter; import jakarta.ws.rs.container.DynamicFeature; @@ -152,6 +153,9 @@ private LinkedHashMap, T> createInterceptorInstances( List> responseBeanInstances = new ArrayList<>(interceptors.size()); Collections.sort(interceptors); for (ResourceInterceptor interceptor : interceptors) { + if (RuntimeType.CLIENT.equals(interceptor.getRuntimeType())) { + continue; + } BeanFactory.BeanInstance beanInstance = interceptor.getFactory().createInstance(); responseBeanInstances.add(beanInstance); T containerResponseFilter = beanInstance.getInstance(); diff --git a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/response/CustomHeadersAndWriterInterceptorTest.java b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/response/CustomHeadersAndWriterInterceptorTest.java index 04a8b03e7aa9d..9a6a0550010d5 100644 --- a/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/response/CustomHeadersAndWriterInterceptorTest.java +++ b/independent-projects/resteasy-reactive/server/vertx/src/test/java/org/jboss/resteasy/reactive/server/vertx/test/response/CustomHeadersAndWriterInterceptorTest.java @@ -7,9 +7,11 @@ import java.io.IOException; import java.util.Date; +import jakarta.ws.rs.ConstrainedTo; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; +import jakarta.ws.rs.RuntimeType; import jakarta.ws.rs.WebApplicationException; import jakarta.ws.rs.core.MediaType; import jakarta.ws.rs.core.Response; @@ -28,7 +30,7 @@ public class CustomHeadersAndWriterInterceptorTest { @RegisterExtension static ResteasyReactiveUnitTest runner = new ResteasyReactiveUnitTest() .withApplicationRoot((jar) -> jar - .addClasses(TestResource.class, DummyWriterInterceptor.class)); + .addClasses(TestResource.class, DummyWriterInterceptor.class, FailingWriterInterceptor.class)); @Test void testResponseHeaders() { @@ -61,4 +63,14 @@ public void aroundWriteTo(WriterInterceptorContext context) throws IOException, } } + @Provider + @ConstrainedTo(RuntimeType.CLIENT) + public static class FailingWriterInterceptor implements WriterInterceptor { + + @Override + public void aroundWriteTo(WriterInterceptorContext context) throws WebApplicationException { + throw new RuntimeException("this is never called"); + } + } + }