TOMEE-3729 Do not scan classpath for @Provider when there is a JAX-RS Application
diff --git a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
index 9fb42a9..bf96a16 100644
--- a/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
+++ b/server/openejb-rest/src/main/java/org/apache/openejb/server/rest/RESTService.java
@@ -177,10 +177,10 @@
application = "true".equalsIgnoreCase(
appInfo.properties.getProperty("openejb.cxf-rs.cache-application",
- SystemInstance.get().getOptions().get("openejb.cxf-rs.cache-application", "true")))
- ?
- new InternalApplication(application) /* caches singletons and classes */ :
- application;
+ SystemInstance.get().getOptions().get("openejb.cxf-rs.cache-application", "true")))
+ ?
+ new InternalApplication(application) /* caches singletons and classes */ :
+ application;
final Set<Class<?>> classes = new HashSet<>(application.getClasses());
final Set<Object> singletons = application.getSingletons();
@@ -314,7 +314,7 @@
}
private void addAppProvidersIfNeeded(final AppInfo appInfo, final WebAppInfo webApp, final ClassLoader classLoader, final Collection<Object> additionalProviders) {
- if (useDiscoveredProviders(appInfo)) {
+ if (useDiscoveredProviders(appInfo, webApp.restApplications.size() == 0)) {
final Set<String> jaxRsProviders = new HashSet<>(webApp.jaxRsProviders);
jaxRsProviders.addAll(appInfo.jaxRsProviders);
additionalProviders.addAll(appProviders(jaxRsProviders, classLoader));
@@ -587,11 +587,15 @@
}
private boolean useDiscoveredProviders(final AppInfo appInfo) {
+ return useDiscoveredProviders(appInfo, true);
+ }
+
+ private boolean useDiscoveredProviders(final AppInfo appInfo, final boolean defaultValue) {
final String value = appInfo.properties.getProperty(OPENEJB_JAXRS_PROVIDERS_AUTO_PROP);
if (value != null) {
return "true".equalsIgnoreCase(value.trim());
}
- return SystemInstance.get().getOptions().get(OPENEJB_JAXRS_PROVIDERS_AUTO_PROP, true);
+ return SystemInstance.get().getOptions().get(OPENEJB_JAXRS_PROVIDERS_AUTO_PROP, defaultValue);
}
private Collection<Object> appProviders(final Collection<String> jaxRsProviders, final ClassLoader classLoader) {