Skip to content

Commit

Permalink
Merge pull request #21138 from stuartwdouglas/rr-tests
Browse files Browse the repository at this point in the history
Copy some tests over to the RR independent project
  • Loading branch information
stuartwdouglas authored Nov 3, 2021
2 parents 992dc5d + 1745685 commit 6f76614
Show file tree
Hide file tree
Showing 100 changed files with 4,070 additions and 870 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand All @@ -15,28 +13,24 @@
import java.util.stream.Collectors;

import javax.ws.rs.Priorities;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.ext.RuntimeDelegate;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.Indexer;
import org.jboss.jandex.Type;
import org.jboss.resteasy.reactive.common.jaxrs.RuntimeDelegateImpl;
import org.jboss.resteasy.reactive.common.model.InterceptorContainer;
import org.jboss.resteasy.reactive.common.model.PreMatchInterceptorContainer;
import org.jboss.resteasy.reactive.common.model.ResourceInterceptor;
import org.jboss.resteasy.reactive.common.model.ResourceInterceptors;
import org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames;
import org.jboss.resteasy.reactive.common.processor.scanning.ApplicationScanningResult;
import org.jboss.resteasy.reactive.common.processor.scanning.ApplicationScanningResult.KeepProviderResult;
import org.jboss.resteasy.reactive.common.processor.scanning.ResourceScanningResult;
import org.jboss.resteasy.reactive.common.processor.scanning.ResteasyReactiveInterceptorScanner;
import org.jboss.resteasy.reactive.common.processor.scanning.ResteasyReactiveScanner;
import org.jboss.resteasy.reactive.common.processor.scanning.SerializerScanningResult;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
Expand All @@ -49,7 +43,6 @@
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.util.JandexUtil;
import io.quarkus.resteasy.reactive.common.runtime.JaxRsSecurityConfig;
import io.quarkus.resteasy.reactive.common.runtime.ResteasyReactiveConfig;
import io.quarkus.resteasy.reactive.spi.AbstractInterceptorBuildItem;
Expand Down Expand Up @@ -276,70 +269,16 @@ public void setupEndpoints(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem,
}

IndexView index = beanArchiveIndexBuildItem.getIndex();
Collection<ClassInfo> writers = index
.getAllKnownImplementors(ResteasyReactiveDotNames.MESSAGE_BODY_WRITER);
Collection<ClassInfo> readers = index
.getAllKnownImplementors(ResteasyReactiveDotNames.MESSAGE_BODY_READER);

for (ClassInfo writerClass : writers) {
KeepProviderResult keepProviderResult = applicationResultBuildItem.getResult().keepProvider(writerClass);
if (keepProviderResult != KeepProviderResult.DISCARD) {
RuntimeType runtimeType = null;
if (keepProviderResult == KeepProviderResult.SERVER_ONLY) {
runtimeType = RuntimeType.SERVER;
}
List<String> mediaTypeStrings = Collections.emptyList();
AnnotationInstance producesAnnotation = writerClass.classAnnotation(ResteasyReactiveDotNames.PRODUCES);
if (producesAnnotation != null) {
mediaTypeStrings = Arrays.asList(producesAnnotation.value().asStringArray());
}
List<Type> typeParameters = JandexUtil.resolveTypeParameters(writerClass.name(),
ResteasyReactiveDotNames.MESSAGE_BODY_WRITER,
index);
String writerClassName = writerClass.name().toString();
AnnotationInstance constrainedToInstance = writerClass.classAnnotation(ResteasyReactiveDotNames.CONSTRAINED_TO);
if (constrainedToInstance != null) {
runtimeType = RuntimeType.valueOf(constrainedToInstance.value().asEnum());
}
int priority = Priorities.USER;
AnnotationInstance priorityInstance = writerClass.classAnnotation(ResteasyReactiveDotNames.PRIORITY);
if (priorityInstance != null) {
priority = priorityInstance.value().asInt();
}
messageBodyWriterBuildItemBuildProducer.produce(new MessageBodyWriterBuildItem(writerClassName,
typeParameters.get(0).name().toString(), mediaTypeStrings, runtimeType, false, priority));
}
SerializerScanningResult serializers = ResteasyReactiveScanner.scanForSerializers(index,
applicationResultBuildItem.getResult());
for (var i : serializers.getReaders()) {
messageBodyReaderBuildItemBuildProducer.produce(new MessageBodyReaderBuildItem(i.getClassName(),
i.getHandledClassName(), i.getMediaTypeStrings(), i.getRuntimeType(), i.isBuiltin(), i.getPriority()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, false, i.getClassName()));
}

for (ClassInfo readerClass : readers) {
KeepProviderResult keepProviderResult = applicationResultBuildItem.getResult().keepProvider(readerClass);
if (keepProviderResult != KeepProviderResult.DISCARD) {
List<Type> typeParameters = JandexUtil.resolveTypeParameters(readerClass.name(),
ResteasyReactiveDotNames.MESSAGE_BODY_READER,
index);
RuntimeType runtimeType = null;
if (keepProviderResult == KeepProviderResult.SERVER_ONLY) {
runtimeType = RuntimeType.SERVER;
}
List<String> mediaTypeStrings = Collections.emptyList();
String readerClassName = readerClass.name().toString();
AnnotationInstance consumesAnnotation = readerClass.classAnnotation(ResteasyReactiveDotNames.CONSUMES);
if (consumesAnnotation != null) {
mediaTypeStrings = Arrays.asList(consumesAnnotation.value().asStringArray());
}
AnnotationInstance constrainedToInstance = readerClass.classAnnotation(ResteasyReactiveDotNames.CONSTRAINED_TO);
if (constrainedToInstance != null) {
runtimeType = RuntimeType.valueOf(constrainedToInstance.value().asEnum());
}
int priority = Priorities.USER;
AnnotationInstance priorityInstance = readerClass.classAnnotation(ResteasyReactiveDotNames.PRIORITY);
if (priorityInstance != null) {
priority = priorityInstance.value().asInt();
}
messageBodyReaderBuildItemBuildProducer.produce(new MessageBodyReaderBuildItem(readerClassName,
typeParameters.get(0).name().toString(), mediaTypeStrings, runtimeType, false, priority));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, false, readerClassName));
}
for (var i : serializers.getWriters()) {
messageBodyWriterBuildItemBuildProducer.produce(new MessageBodyWriterBuildItem(i.getClassName(),
i.getHandledClassName(), i.getMediaTypeStrings(), i.getRuntimeType(), i.isBuiltin(), i.getPriority()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.ClassType;
import org.jboss.jandex.DotName;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.IndexView;
Expand All @@ -23,11 +20,9 @@
import org.jboss.resteasy.reactive.common.ResteasyReactiveConfig;
import org.jboss.resteasy.reactive.common.processor.DefaultProducesHandler;
import org.jboss.resteasy.reactive.server.core.Deployment;
import org.jboss.resteasy.reactive.server.core.parameters.converters.GeneratedParameterConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.NoopParameterConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.LoadedParameterConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.ParameterConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.ParameterConverterSupplier;
import org.jboss.resteasy.reactive.server.core.parameters.converters.PathSegmentParamConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.RuntimeResolvedConverter;
import org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer;
import org.jboss.resteasy.reactive.server.processor.ServerIndexedParameter;
Expand All @@ -43,9 +38,6 @@
import io.quarkus.gizmo.ResultHandle;
import io.quarkus.resteasy.reactive.server.common.runtime.EndpointInvokerFactory;
import io.quarkus.resteasy.reactive.server.runtime.ResteasyReactiveRecorder;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;

public class QuarkusServerEndpointIndexer
extends ServerEndpointIndexer {
Expand All @@ -59,11 +51,6 @@ public class QuarkusServerEndpointIndexer
private final Map<String, String> multipartGeneratedPopulators = new HashMap<>();
private final Predicate<String> applicationClassPredicate;

private static final Set<DotName> CONTEXT_TYPES = Set.of(
DotName.createSimple(HttpServerRequest.class.getName()),
DotName.createSimple(HttpServerResponse.class.getName()),
DotName.createSimple(RoutingContext.class.getName()));

QuarkusServerEndpointIndexer(Builder builder) {
super(builder);
this.initConverters = builder.initConverters;
Expand All @@ -75,10 +62,6 @@ public class QuarkusServerEndpointIndexer
this.resteasyReactiveRecorder = builder.resteasyReactiveRecorder;
}

protected boolean isContextType(ClassType klass) {
return super.isContextType(klass) || CONTEXT_TYPES.contains(klass.name());
}

@Override
protected String[] applyAdditionalDefaults(Type nonAsyncReturnType) {
List<MediaType> defaultMediaTypes = defaultProducesHandler.handle(new DefaultProducesHandler.Context() {
Expand Down Expand Up @@ -116,28 +99,8 @@ protected boolean handleCustomParameter(Map<DotName, AnnotationInstance> anns, S
}

@Override
protected ParameterConverterSupplier extractConverter(String elementType, IndexView indexView,
protected ParameterConverterSupplier extractConverterImpl(String elementType, IndexView indexView,
Map<String, String> existingConverters, String errorLocation, boolean hasRuntimeConverters) {
if (elementType.equals(String.class.getName())) {
if (hasRuntimeConverters)
return new RuntimeResolvedConverter.Supplier().setDelegate(new NoopParameterConverter.Supplier());
// String needs no conversion
return null;
} else if (existingConverters.containsKey(elementType)) {
String className = existingConverters.get(elementType);
ParameterConverterSupplier delegate;
if (className == null)
delegate = null;
else
delegate = new GeneratedParameterConverter().setClassName(className);
if (hasRuntimeConverters)
return new RuntimeResolvedConverter.Supplier().setDelegate(delegate);
if (delegate == null)
throw new RuntimeException("Failed to find converter for " + elementType);
return delegate;
} else if (elementType.equals(PathSegment.class.getName())) {
return new PathSegmentParamConverter.Supplier();
}

MethodDescriptor fromString = null;
MethodDescriptor valueOf = null;
Expand Down Expand Up @@ -199,7 +162,7 @@ protected ParameterConverterSupplier extractConverter(String elementType, IndexV
mc.returnValue(ret);
}
}
delegate = new GeneratedParameterConverter().setClassName(baseName);
delegate = new LoadedParameterConverter().setClassName(baseName);
} else {
// let's not try this again
baseName = null;
Expand Down
Loading

0 comments on commit 6f76614

Please sign in to comment.