Skip to content

Commit

Permalink
Prevent loading Feature/DynamicFeature services multiple times.
Browse files Browse the repository at this point in the history
Signed-off-by: jansupol <jan.supol@oracle.com>
  • Loading branch information
jansupol committed Dec 20, 2021
1 parent bdb0dd0 commit 21115d4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import javax.ws.rs.RuntimeType;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -62,7 +63,7 @@ protected List<Class<T>> loadImplementations(Map<String, Object> applicationProp
* @param features list of features to be registered
* @param bootstrapBag place where features are being registered
*/
protected void registerFeatures(List<Class<T>> features,
protected void registerFeatures(Collection<Class<T>> features,
BootstrapBag bootstrapBag) {
final List<AutoDiscoverable> autoDiscoverables = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@

import javax.ws.rs.RuntimeType;
import javax.ws.rs.container.DynamicFeature;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* Registers JAX-RS {@link DynamicFeature} which are listed as SPIs for registration.
Expand Down Expand Up @@ -51,7 +53,8 @@ public DynamicFeatureConfigurator() {
public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) {
final Map<String, Object> properties = bootstrapBag.getConfiguration().getProperties();
if (PropertiesHelper.isJaxRsServiceLoadingEnabled(properties)) {
final List<Class<DynamicFeature>> dynamicFeatures = loadImplementations(properties);
final Set<Class<DynamicFeature>> dynamicFeatures = new HashSet<>();
dynamicFeatures.addAll(loadImplementations(properties));
dynamicFeatures.addAll(loadImplementations(properties, DynamicFeature.class.getClassLoader()));

registerFeatures(dynamicFeatures, bootstrapBag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

import javax.ws.rs.RuntimeType;
import javax.ws.rs.core.Feature;
import java.util.List;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
* Registers JAX-RS {@link Feature} which are listed as SPIs for registration.
Expand All @@ -44,7 +45,8 @@ public FeatureConfigurator(RuntimeType runtimeType) {
public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) {
final Map<String, Object> properties = bootstrapBag.getConfiguration().getProperties();
if (PropertiesHelper.isJaxRsServiceLoadingEnabled(properties)) {
final List<Class<Feature>> features = loadImplementations(properties);
final Set<Class<Feature>> features = new HashSet<>();
features.addAll(loadImplementations(properties));
features.addAll(loadImplementations(properties, Feature.class.getClassLoader()));

registerFeatures(features, bootstrapBag);
Expand Down

0 comments on commit 21115d4

Please sign in to comment.