Skip to content

Commit

Permalink
feat: Skip all not jax rs method params if configuration is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
poldinik committed Apr 20, 2024
1 parent ce901c9 commit b680af3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 95 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
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 @@ -231,8 +230,6 @@ 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 @@ -415,7 +412,8 @@ public void setupEndpoints(ApplicationIndexBuildItem applicationIndexBuildItem,
List<ContextTypeBuildItem> contextTypeBuildItems,
CompiledJavaVersionBuildItem compiledJavaVersionBuildItem,
ResourceInterceptorsBuildItem resourceInterceptorsBuildItem,
Capabilities capabilities)
Capabilities capabilities,
ResteasyReactiveServerConfig serverConfig)
throws NoSuchMethodException {

if (!resourceScanningResultBuildItem.isPresent()) {
Expand Down Expand Up @@ -637,18 +635,8 @@ 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;
}

serverConfig.skipAllNotMethodParameter().ifPresent(skip -> serverEndpointIndexerBuilder.skipAllNotMethodParameter(skip));

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,4 +18,5 @@ public interface ResteasyReactiveServerConfig {
* This value is always resolved relative to {@code quarkus.http.root-path}.
*/
Optional<String> path();
Optional<Boolean> skipAllNotMethodParameter();
}
Original file line number Diff line number Diff line change
@@ -1,82 +1,7 @@
package org.jboss.resteasy.reactive.common.processor;

import static java.util.Map.entry;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.BEAN_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.BIG_DECIMAL;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.BIG_INTEGER;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.BLOCKING;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.BOOLEAN;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.CHARACTER;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COMPLETABLE_FUTURE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COMPLETION_STAGE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.CONFIGURATION;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.CONSUMES;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.CONTEXT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COOKIE_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.DEFAULT_VALUE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.DOUBLE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.DUMMY_ELEMENT_TYPE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.ENCODED;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.FLOAT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.FORM_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.HEADER_PARAM;
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.LIST;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LOCAL_DATE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LOCAL_DATE_TIME;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LOCAL_TIME;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.LONG;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MATRIX_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI_PART_DATA_INPUT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI_PART_FORM_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.NON_BLOCKING;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.OBJECT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.OFFSET_DATE_TIME;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.OFFSET_TIME;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.OPTIONAL;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PATH;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PATH_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PATH_SEGMENT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRIMITIVE_BOOLEAN;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRIMITIVE_CHAR;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRIMITIVE_DOUBLE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRIMITIVE_FLOAT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRIMITIVE_INTEGER;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRIMITIVE_LONG;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PRODUCES;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PROVIDERS;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.QUERY_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REQUEST;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.RESOURCE_CONTEXT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.RESOURCE_INFO;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.RESPONSE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_COOKIE_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_FORM_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_HEADER_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_MATRIX_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_MULTI;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_PATH_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_QUERY_PARAM;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_RESPONSE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_SSE_ELEMENT_TYPE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.REST_STREAM_ELEMENT_TYPE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.RUN_ON_VIRTUAL_THREAD;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SECURITY_CONTEXT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SERVER_REQUEST_CONTEXT;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SET;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SORTED_SET;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SSE;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SSE_EVENT_SINK;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.STRING;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.SUSPENDED;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.TRANSACTIONAL;
import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.UNI;
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.*;

import java.lang.reflect.Modifier;
import java.math.BigDecimal;
Expand Down Expand Up @@ -234,6 +159,7 @@ public abstract class EndpointIndexer<T extends EndpointIndexer<T, PARAM, METHOD
private final Function<ClassInfo, Supplier<Boolean>> isDisabledCreator;

private final Predicate<Map<DotName, AnnotationInstance>> skipMethodParameter;
private final boolean skipAllNotMethodParameter;
private SerializerScanningResult serializerScanningResult;

protected EndpointIndexer(Builder<T, ?, METHOD> builder) {
Expand All @@ -259,6 +185,7 @@ protected EndpointIndexer(Builder<T, ?, METHOD> builder) {
this.targetJavaVersion = builder.targetJavaVersion;
this.isDisabledCreator = builder.isDisabledCreator;
this.skipMethodParameter = builder.skipMethodParameter;
this.skipAllNotMethodParameter = builder.skipAllNotMethodParameter;
}

public Optional<ResourceClass> createEndpoints(ClassInfo classInfo, boolean considerApplication) {
Expand Down Expand Up @@ -572,8 +499,7 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
boolean encoded = anns.containsKey(ENCODED);
Type paramType = currentMethodInfo.parameterType(i);
String errorLocation = "method " + currentMethodInfo + " on class " + currentMethodInfo.declaringClass();

if (skipParameter(anns)) {
if (skipClientParameter(anns) || skipServerParameter(skipAllNotMethodParameter).apply(anns)) {
parameterResult = createIndexedParam()
.setCurrentClassInfo(currentClassInfo)
.setActualEndpointInfo(actualEndpointInfo)
Expand Down Expand Up @@ -771,7 +697,20 @@ private ResourceMethod createResourceMethod(ClassInfo currentClassInfo, ClassInf
}
}

protected boolean skipParameter(Map<DotName, AnnotationInstance> anns) {
private Function<Map<DotName, AnnotationInstance>, Boolean> skipServerParameter(boolean skipAllNotMethodParameter) {
return new Function<Map<DotName, AnnotationInstance>, Boolean>() {
@Override
public Boolean apply(Map<DotName, AnnotationInstance> anns) {
if(skipAllNotMethodParameter){
return JAX_RS_ANNOTATIONS_FOR_FIELDS.stream()
.noneMatch(dotName -> anns.containsKey(dotName));
}
return false;
}
};
}

protected boolean skipClientParameter(Map<DotName, AnnotationInstance> anns) {
return skipMethodParameter != null && skipMethodParameter.test(anns);
}

Expand Down Expand Up @@ -1667,6 +1606,7 @@ public boolean handleMultipartForReturnType(AdditionalWriters additionalWriters,
private Function<ClassInfo, Supplier<Boolean>> isDisabledCreator = null;

private Predicate<Map<DotName, AnnotationInstance>> skipMethodParameter = null;
private boolean skipAllNotMethodParameter = false;

public B setMultipartReturnTypeIndexerExtension(MultipartReturnTypeIndexerExtension multipartReturnTypeHandler) {
this.multipartReturnTypeIndexerExtension = multipartReturnTypeHandler;
Expand Down Expand Up @@ -1790,6 +1730,11 @@ public B setSkipMethodParameter(
return (B) this;
}

public B skipAllNotMethodParameter(boolean skipAllNotMethodParameter){
this.skipAllNotMethodParameter = skipAllNotMethodParameter;
return (B) this;
}

public abstract T build();
}

Expand Down

0 comments on commit b680af3

Please sign in to comment.