Skip to content

Commit

Permalink
Register resource classes for reflection when ContainerResponseFilter…
Browse files Browse the repository at this point in the history
… exists

This is needed because those filters can call
setEntityStream which then forces the use of the
slow path for calling writers

Closes: #42537
  • Loading branch information
geoand committed Aug 26, 2024
1 parent 2105d46 commit 550b84b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,7 @@ public void additionalReflection(BeanArchiveIndexBuildItem beanArchiveIndexBuild
SetupEndpointsResultBuildItem setupEndpointsResult,
List<MessageBodyReaderBuildItem> messageBodyReaderBuildItems,
List<MessageBodyWriterBuildItem> messageBodyWriterBuildItems,
ResourceInterceptorsBuildItem resourceInterceptorsBuildItem,
BuildProducer<ReflectiveClassBuildItem> producer) {
List<ResourceClass> resourceClasses = setupEndpointsResult.getResourceClasses();
IndexView index = beanArchiveIndexBuildItem.getIndex();
Expand Down Expand Up @@ -1122,6 +1123,13 @@ public void additionalReflection(BeanArchiveIndexBuildItem beanArchiveIndexBuild
}
}
}

// when a ContainerResponseFilter exists, it can potentially do responseContext.setEntityStream()
// which then forces the use of the slow path for calling writers
if (!resourceInterceptorsBuildItem.getResourceInterceptors().getContainerResponseFilters().isEmpty()) {
serializersRequireResourceReflection = true;
}

if (serializersRequireResourceReflection) {
producer.produce(ReflectiveClassBuildItem
.builder(resourceClasses.stream().map(ResourceClass::getClassName).toArray(String[]::new))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public void sort() {
Collections.sort(nameResourceInterceptors);
}

public boolean isEmpty() {
return globalResourceInterceptors.isEmpty() && nameResourceInterceptors.isEmpty();
}

public ResourceInterceptor<T> create() {
return new ResourceInterceptor<>();
}
Expand Down

0 comments on commit 550b84b

Please sign in to comment.