Skip to content

Commit

Permalink
feat: quarkusio#39979 Init skipMethodParameter with defined predicate…
Browse files Browse the repository at this point in the history
… by user

[ResteasyReactiveProcessor inits skipMethodParameter if there is a predicate annotated with @RestEasyParamsFilter by user. This allows to ignore params chosen by user logic marking them as SKIPPED in order to use different annotated params with respect JAXRS api]
  • Loading branch information
poldinik committed Apr 11, 2024
1 parent 6b171d0 commit 7cc8eda
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -64,6 +65,7 @@
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.RestEasyParamsFilter;
import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.core.SingletonBeanFactory;
import org.jboss.resteasy.reactive.common.model.InjectableBean;
Expand Down Expand Up @@ -230,6 +232,7 @@ public class ResteasyReactiveProcessor {
DotName.createSimple(RoutingContext.class.getName()));
private static final DotName FILE = DotName.createSimple(File.class.getName());
private static final DotName ENDPOINT_DISABLED = DotName.createSimple(EndpointDisabled.class.getName());
private static final DotName RESTEASY_PARAM_FILTER = DotName.createSimple(RestEasyParamsFilter.class.getName());

private static final int SECURITY_EXCEPTION_MAPPERS_PRIORITY = Priorities.USER + 1;
private static final String[] EMPTY_STRING_ARRAY = new String[0];
Expand Down Expand Up @@ -634,6 +637,19 @@ public Supplier<Boolean> apply(ClassInfo classInfo) {
}
});

for (AnnotationInstance ann : index.getAnnotations(RESTEASY_PARAM_FILTER)) {
Class<Predicate<Map<DotName, AnnotationInstance>>> predicate = loadClass(ann.target().asClass().name());
if (predicate == null) {
break;
}
try {
serverEndpointIndexerBuilder.setSkipMethodParameter(predicate.getDeclaredConstructor().newInstance());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException(e);
}
break;
}

if (!serverDefaultProducesHandlers.isEmpty()) {
List<DefaultProducesHandler> handlers = new ArrayList<>(serverDefaultProducesHandlers.size());
for (ServerDefaultProducesHandlerBuildItem bi : serverDefaultProducesHandlers) {
Expand Down Expand Up @@ -740,6 +756,14 @@ public Supplier<Boolean> apply(ClassInfo classInfo) {
handleDateFormatReflection(reflectiveClassBuildItemBuildProducer, index);
}

private static <T> Class<T> loadClass(DotName filterDotName) {
try {
return (Class<T>) Class.forName(filterDotName.toString(), false, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException classNotFoundException) {
return null;
}
}

private boolean filtersAccessResourceMethod(ResourceInterceptors resourceInterceptors) {
AtomicBoolean ab = new AtomicBoolean(false);
ResourceInterceptors.FiltersVisitor visitor = new ResourceInterceptors.FiltersVisitor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.jboss.resteasy.reactive;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RestEasyParamsFilter {
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ public RuntimeResource buildResourceMethod(ResourceClass clazz,
addHandlers(handlers, clazz, method, info, HandlerChainCustomizer.Phase.RESOLVE_METHOD_PARAMETERS);
for (int i = 0; i < parameters.length; i++) {
ServerMethodParameter param = (ServerMethodParameter) parameters[i];
if (param.parameterType.equals(ParameterType.SKIPPED))
continue;
ParameterExtractor extractor = parameterExtractor(pathParameterIndexes, locatableResource, param);
ParameterConverter converter = null;
ParamConverterProviders paramConverterProviders = info.getParamConverterProviders();
Expand Down

0 comments on commit 7cc8eda

Please sign in to comment.