Skip to content

Commit

Permalink
feat: Implement skipping feature using new build item that extension …
Browse files Browse the repository at this point in the history
…can produce

feat: Implement skipping feature using new build item that extension can produce
  • Loading branch information
poldinik committed Apr 27, 2024
1 parent 0864927 commit bffbb82
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,7 @@
import io.quarkus.resteasy.reactive.server.runtime.security.EagerSecurityHandler;
import io.quarkus.resteasy.reactive.server.runtime.security.EagerSecurityInterceptorHandler;
import io.quarkus.resteasy.reactive.server.runtime.security.SecurityContextOverrideHandler;
import io.quarkus.resteasy.reactive.server.spi.AnnotationsTransformerBuildItem;
import io.quarkus.resteasy.reactive.server.spi.ContextTypeBuildItem;
import io.quarkus.resteasy.reactive.server.spi.HandlerConfigurationProviderBuildItem;
import io.quarkus.resteasy.reactive.server.spi.MethodScannerBuildItem;
import io.quarkus.resteasy.reactive.server.spi.NonBlockingReturnTypeBuildItem;
import io.quarkus.resteasy.reactive.server.spi.PreExceptionMapperHandlerBuildItem;
import io.quarkus.resteasy.reactive.server.spi.ResumeOn404BuildItem;
import io.quarkus.resteasy.reactive.server.spi.*;
import io.quarkus.resteasy.reactive.spi.CustomExceptionMapperBuildItem;
import io.quarkus.resteasy.reactive.spi.DynamicFeatureBuildItem;
import io.quarkus.resteasy.reactive.spi.ExceptionMapperBuildItem;
Expand Down Expand Up @@ -414,7 +408,7 @@ public void setupEndpoints(ApplicationIndexBuildItem applicationIndexBuildItem,
CompiledJavaVersionBuildItem compiledJavaVersionBuildItem,
ResourceInterceptorsBuildItem resourceInterceptorsBuildItem,
Capabilities capabilities,
ResteasyReactiveServerConfig serverConfig) {
Optional<AllowNotRestParametersBuildItem> allowNotRestParametersBuildItem) {

if (!resourceScanningResultBuildItem.isPresent()) {
// no detected @Path, bail out
Expand Down Expand Up @@ -634,8 +628,8 @@ public Supplier<Boolean> apply(ClassInfo classInfo) {
}
});

serverConfig.allowNotRestMethodsParams()
.ifPresent(skip -> serverEndpointIndexerBuilder.skipAllNotMethodParameter(skip));
allowNotRestParametersBuildItem
.ifPresent(skip -> serverEndpointIndexerBuilder.skipAllNotMethodParameter(true));

if (!serverDefaultProducesHandlers.isEmpty()) {
List<DefaultProducesHandler> handlers = new ArrayList<>(serverDefaultProducesHandlers.size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,4 @@ public interface ResteasyReactiveServerConfig {
* This value is always resolved relative to {@code quarkus.http.root-path}.
*/
Optional<String> path();

/**
* Set this to allow
* JAX-RS resource method to support parameter not related to JAX-RS resource parameter
*/
Optional<Boolean> allowNotRestMethodsParams();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import java.util.function.Consumer;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.builder.BuildChainBuilder;
import io.quarkus.builder.BuildContext;
import io.quarkus.builder.BuildStep;
import io.quarkus.resteasy.reactive.server.spi.AllowNotRestParametersBuildItem;
import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.MixedParameterResource;
import io.quarkus.test.QuarkusUnitTest;

Expand All @@ -22,12 +26,19 @@ public class AllowNotResteasyParametersTest {

@RegisterExtension
static QuarkusUnitTest quarkusUnitTest = new QuarkusUnitTest()
.setArchiveProducer(() -> {
JavaArchive war = ShrinkWrap.create(JavaArchive.class);
war.addClasses(MixedParameterResource.class);
return war;
.addBuildChainCustomizer(new Consumer<BuildChainBuilder>() {
@Override
public void accept(BuildChainBuilder buildChainBuilder) {
buildChainBuilder.addBuildStep(new BuildStep() {
@Override
public void execute(BuildContext context) {
context.produce(new AllowNotRestParametersBuildItem());
}
}).produces(AllowNotRestParametersBuildItem.class).build();
}
})
.overrideConfigKey("quarkus.rest.allow-not-rest-methods-params", "true");
.withApplicationRoot((jar) -> jar
.addClass(MixedParameterResource.class));

@Test
@DisplayName("Test Resource Method with one param not related to RESTEasy")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.quarkus.resteasy.reactive.server.spi;

import io.quarkus.builder.item.SimpleBuildItem;

public final class AllowNotRestParametersBuildItem extends SimpleBuildItem {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.HTTP_HEADERS;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.INSTANT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.INTEGER;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.JAX_RS_ANNOTATIONS_FOR_FIELDS;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LIST;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LOCAL_DATE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LOCAL_DATE_TIME;
Expand Down Expand Up @@ -80,8 +81,6 @@
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.URI_INFO;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.YEAR;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.ZONED_DATE_TIME;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.JAX_RS_ANNOTATIONS_FOR_FIELDS;


import java.lang.reflect.Modifier;
import java.math.BigDecimal;
Expand Down Expand Up @@ -791,7 +790,8 @@ private Function<Map<DotName, AnnotationInstance>, Boolean> skipServerParameter(
@Override
public Boolean apply(Map<DotName, AnnotationInstance> anns) {
if (skipAllNotMethodParameter) {
return anns.size() > 0 && JAX_RS_ANNOTATIONS_FOR_FIELDS.stream().noneMatch(dotName -> anns.containsKey(dotName));
return anns.size() > 0
&& JAX_RS_ANNOTATIONS_FOR_FIELDS.stream().noneMatch(dotName -> anns.containsKey(dotName));
}
return false;
}
Expand Down

0 comments on commit bffbb82

Please sign in to comment.