Skip to content

Commit

Permalink
When skipping @Provider auto-discovery for REST clients, take ClientR…
Browse files Browse the repository at this point in the history
…equestFilters into consideration
  • Loading branch information
martin-kofoed-jyskebank-dk committed Nov 23, 2023
1 parent 63ff7b0 commit c7878f3
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import jakarta.inject.Singleton;
import jakarta.ws.rs.Priorities;
import jakarta.ws.rs.RuntimeType;
import jakarta.ws.rs.client.ClientRequestFilter;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;

Expand Down Expand Up @@ -297,17 +298,9 @@ void registerProvidersFromAnnotations(CombinedIndexBuildItem indexBuildItem,
}
}

List<DotName> providerInterfaceNames = providerClass.interfaceNames();
// don't register server specific types
if (providerInterfaceNames.contains(ResteasyReactiveDotNames.CONTAINER_REQUEST_FILTER)
|| providerInterfaceNames.contains(ResteasyReactiveDotNames.CONTAINER_RESPONSE_FILTER)
|| providerInterfaceNames.contains(ResteasyReactiveDotNames.EXCEPTION_MAPPER)) {
if (skipAutoDiscovery(providerClass.interfaceNames())) {
continue;
}

if (providerInterfaceNames.contains(ResteasyReactiveDotNames.FEATURE)) {
continue; // features should not be automatically registered for the client, see javadoc for Feature
}
}

DotName providerDotName = providerClass.name();
int priority = getAnnotatedPriority(index, providerDotName.toString(), Priorities.USER);
Expand Down Expand Up @@ -580,6 +573,28 @@ && isImplementorOf(index, target.asClass(), RESPONSE_EXCEPTION_MAPPER, Set.of(AP
}
}

/**
* Based on a list of interfaces implemented by @Provider class, determine if registration
* should be skipped or not. Server-specific types should be omitted unless implementation
* of a <code>ClientRequestFilter</code> exists on the same class explicitly.
* Features should always be omitted.
*/
private boolean skipAutoDiscovery(List<DotName> providerInterfaceNames) {
if (providerInterfaceNames.contains(ResteasyReactiveDotNames.FEATURE)) {
return true;
}
if (providerInterfaceNames.contains(ResteasyReactiveDotNames.CONTAINER_REQUEST_FILTER)
|| providerInterfaceNames.contains(ResteasyReactiveDotNames.CONTAINER_RESPONSE_FILTER)
|| providerInterfaceNames.contains(ResteasyReactiveDotNames.EXCEPTION_MAPPER)) {
if (providerInterfaceNames.contains(DotName.createSimple(ClientRequestFilter.class.getName()))) {
return false;
} else {
return true;
}
}
return false;
}

private Map<String, GeneratedClassResult> populateClientExceptionMapperFromAnnotations(
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, IndexView index) {
Expand Down

0 comments on commit c7878f3

Please sign in to comment.