org.jboss.spec.javax.ws.rs
jboss-jaxrs-api_2.1_spec
diff --git a/services/src/main/java/org/keycloak/common/util/Resteasy.java b/services/src/main/java/org/keycloak/common/util/Resteasy.java
index 206247dc73..754b25dbb3 100644
--- a/services/src/main/java/org/keycloak/common/util/Resteasy.java
+++ b/services/src/main/java/org/keycloak/common/util/Resteasy.java
@@ -17,9 +17,7 @@
package org.keycloak.common.util;
-import org.jboss.resteasy.core.Dispatcher;
-import org.jboss.resteasy.core.ResteasyContext;
-import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import java.util.ServiceLoader;
/**
* Provides a layer of indirection to abstract invocations to Resteasy internal APIs. Making also possible to use different
@@ -34,65 +32,14 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory;
*/
public final class Resteasy {
- private static final BiConsumer PUSH_CONTEXT;
- private static final BiConsumer PUSH_DEFAULT_OBJECT;
- private static final Function PULL_CONTEXT;
- private static final Runnable CLEAR_CONTEXT;
+ private static ResteasyProvider provider;
static {
- if (isRestEasy4()) {
- PUSH_CONTEXT = new BiConsumer() {
- @Override
- public void accept(Class p1, Object p2) {
- ResteasyContext.pushContext(p1, p2);
- }
- };
- PUSH_DEFAULT_OBJECT = new BiConsumer() {
- @Override
- public void accept(Class p1, Object p2) {
- ResteasyContext.getContextData(org.jboss.resteasy.spi.Dispatcher.class).getDefaultContextObjects()
- .put(p1, p2);
- }
- };
- PULL_CONTEXT = new Function() {
- @Override
- public Object apply(Class p1) {
- return ResteasyContext.getContextData(p1);
- }
- };
- CLEAR_CONTEXT = new Runnable() {
- @Override
- public void run() {
- ResteasyContext.clearContextData();
- }
- };
- } else {
- PUSH_CONTEXT = new BiConsumer() {
- @Override
- public void accept(Class p1, Object p2) {
- ResteasyProviderFactory.getInstance().pushContext(p1, p2);
- }
- };
- PUSH_DEFAULT_OBJECT = new BiConsumer() {
- @Override
- public void accept(Class p1, Object p2) {
- ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects()
- .put(p1, p2);
- }
- };
- PULL_CONTEXT = new Function() {
- @Override
- public Object apply(Class p1) {
- return ResteasyProviderFactory.getInstance().getContextData(p1);
- }
- };
- CLEAR_CONTEXT = new Runnable() {
- @Override
- public void run() {
- ResteasyProviderFactory.getInstance().clearContextData();
- }
- };
- }
+ provider = ServiceLoader.load(ResteasyProvider.class, Resteasy.class.getClassLoader()).iterator().next();
+ }
+
+ public static ResteasyProvider getProvider() {
+ return provider;
}
/**
@@ -102,7 +49,7 @@ public final class Resteasy {
* @param instance the instance
*/
public static void pushContext(Class type, Object instance) {
- PUSH_CONTEXT.accept(type, instance);
+ provider.pushContext(type, instance);
}
/**
@@ -112,14 +59,14 @@ public final class Resteasy {
* @return the instance associated with the given {@code type} or null if non-existent.
*/
public static R getContextData(Class type) {
- return (R) PULL_CONTEXT.apply(type);
+ return provider.getContextData(type);
}
/**
* Clear the Resteasy context associated with the current thread.
*/
public static void clearContextData() {
- CLEAR_CONTEXT.run();
+ provider.clearContextData();
}
/**
@@ -129,28 +76,7 @@ public final class Resteasy {
* @param instance the instance
*/
public static void pushDefaultContextObject(Class type, Object instance) {
- PUSH_DEFAULT_OBJECT.accept(type, instance);
+ provider.pushDefaultContextObject(type, instance);
}
- private static boolean isRestEasy4() {
- try {
- return Class.forName("org.jboss.resteasy.core.ResteasyContext") != null;
- } catch (ClassNotFoundException ignore) {
- return false;
- }
- }
-
- /**
- * Only necessary because keycloak-common is constrained to JDK 1.7.
- */
- private interface BiConsumer {
- void accept(T p1, S p2);
- }
-
- /**
- * Only necessary because keycloak-common is constrained to JDK 1.7.
- */
- private interface Function {
- R apply(T p1);
- }
}
diff --git a/services/src/main/java/org/keycloak/common/util/ResteasyProvider.java b/services/src/main/java/org/keycloak/common/util/ResteasyProvider.java
new file mode 100644
index 0000000000..5cca0ffceb
--- /dev/null
+++ b/services/src/main/java/org/keycloak/common/util/ResteasyProvider.java
@@ -0,0 +1,13 @@
+package org.keycloak.common.util;
+
+public interface ResteasyProvider {
+
+ R getContextData(Class type);
+
+ void pushDefaultContextObject(Class type, Object instance);
+
+ void pushContext(Class type, Object instance);
+
+ void clearContextData();
+
+}
diff --git a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
index e7154e39e7..8bd2965f32 100644
--- a/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
+++ b/services/src/main/java/org/keycloak/services/resources/KeycloakApplication.java
@@ -108,6 +108,8 @@ public class KeycloakApplication extends Application {
public KeycloakApplication() {
try {
+ logger.debugv("RestEasy provider: {0}", Resteasy.getProvider().getClass().getName());
+
ServletContext context = Resteasy.getContextData(ServletContext.class);
if ("true".equals(context.getInitParameter(KEYCLOAK_EMBEDDED))) {
diff --git a/testsuite/utils/src/main/java/org/keycloak/testsuite/Resteasy3Provider.java b/testsuite/utils/src/main/java/org/keycloak/testsuite/Resteasy3Provider.java
new file mode 100644
index 0000000000..e008396e0a
--- /dev/null
+++ b/testsuite/utils/src/main/java/org/keycloak/testsuite/Resteasy3Provider.java
@@ -0,0 +1,30 @@
+package org.keycloak.testsuite;
+
+import org.jboss.resteasy.core.Dispatcher;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.keycloak.common.util.ResteasyProvider;
+
+public class Resteasy3Provider implements ResteasyProvider {
+
+ @Override
+ public R getContextData(Class type) {
+ return ResteasyProviderFactory.getInstance().getContextData(type);
+ }
+
+ @Override
+ public void pushDefaultContextObject(Class type, Object instance) {
+ ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects()
+ .put(type, instance);
+ }
+
+ @Override
+ public void pushContext(Class type, Object instance) {
+ ResteasyProviderFactory.getInstance().pushContext(type, instance);
+ }
+
+ @Override
+ public void clearContextData() {
+ ResteasyProviderFactory.getInstance().clearContextData();
+ }
+
+}
diff --git a/testsuite/utils/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider b/testsuite/utils/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider
new file mode 100644
index 0000000000..81e6d35653
--- /dev/null
+++ b/testsuite/utils/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider
@@ -0,0 +1 @@
+org.keycloak.testsuite.Resteasy3Provider
\ No newline at end of file
diff --git a/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/Resteasy3Provider.java b/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/Resteasy3Provider.java
new file mode 100644
index 0000000000..590477fc97
--- /dev/null
+++ b/wildfly/extensions/src/main/java/org/keycloak/provider/wildfly/Resteasy3Provider.java
@@ -0,0 +1,30 @@
+package org.keycloak.provider.wildfly;
+
+import org.jboss.resteasy.core.Dispatcher;
+import org.jboss.resteasy.spi.ResteasyProviderFactory;
+import org.keycloak.common.util.ResteasyProvider;
+
+public class Resteasy3Provider implements ResteasyProvider {
+
+ @Override
+ public R getContextData(Class type) {
+ return ResteasyProviderFactory.getInstance().getContextData(type);
+ }
+
+ @Override
+ public void pushDefaultContextObject(Class type, Object instance) {
+ ResteasyProviderFactory.getInstance().getContextData(Dispatcher.class).getDefaultContextObjects()
+ .put(type, instance);
+ }
+
+ @Override
+ public void pushContext(Class type, Object instance) {
+ ResteasyProviderFactory.getInstance().pushContext(type, instance);
+ }
+
+ @Override
+ public void clearContextData() {
+ ResteasyProviderFactory.getInstance().clearContextData();
+ }
+
+}
diff --git a/wildfly/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider b/wildfly/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider
new file mode 100644
index 0000000000..260db8b309
--- /dev/null
+++ b/wildfly/extensions/src/main/resources/META-INF/services/org.keycloak.common.util.ResteasyProvider
@@ -0,0 +1 @@
+org.keycloak.provider.wildfly.Resteasy3Provider
\ No newline at end of file