diff --git a/jersey-servlet/pom.xml b/jersey-servlet/pom.xml index 6f8446251..95eee1026 100644 --- a/jersey-servlet/pom.xml +++ b/jersey-servlet/pom.xml @@ -184,7 +184,6 @@ - com.sun.jersey.server.impl.cdi, com.sun.jersey.server.impl.ejb, com.sun.jersey.server.impl.managedbeans @@ -192,6 +191,7 @@ com.sun.jersey.api.container.servlet, com.sun.jersey.api.core.servlet, com.sun.jersey.spi.container.servlet, + com.sun.jersey.server.impl.cdi, com.sun.jersey.spi.scanning.servlet, com.sun.jersey.server.impl.container.servlet diff --git a/jersey-servlet/src/main/java/com/sun/jersey/server/impl/cdi/Utils.java b/jersey-servlet/src/main/java/com/sun/jersey/server/impl/cdi/Utils.java index fb5ef3632..c7bb343b6 100644 --- a/jersey-servlet/src/main/java/com/sun/jersey/server/impl/cdi/Utils.java +++ b/jersey-servlet/src/main/java/com/sun/jersey/server/impl/cdi/Utils.java @@ -44,6 +44,7 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import javax.enterprise.context.ApplicationScoped; import javax.enterprise.context.spi.CreationalContext; import javax.enterprise.inject.AmbiguousResolutionException; import javax.enterprise.inject.spi.Bean; @@ -119,32 +120,12 @@ public static T getInstance(BeanManager beanManager, Class c) { } public static CDIExtension getCdiExtensionInstance(BeanManager beanManager) { - - final Set> beans = beanManager.getBeans(CDIExtension.class); - - if (beans.isEmpty()) { + Bean bean = getBean(beanManager, CDIExtension.class); + if (bean == null) { return null; } - try { - return getCdiExtensionReference(beanManager.resolve(beans), beanManager); - } catch(AmbiguousResolutionException ex) { - // try to resolve the instance directly by looking at which one has already been initialized - for (Bean b : beans) { - final CDIExtension cdiExtension = getCdiExtensionReference(b, beanManager); - if (cdiExtension.toBeInitializedLater != null) { - return cdiExtension; - } - } - } - - return null; - } - - private static CDIExtension getCdiExtensionReference(final Bean extensionBean, final BeanManager beanManager) { - final CreationalContext creationalContext = beanManager.createCreationalContext(extensionBean); - final Object result = beanManager.getReference(extensionBean, CDIExtension.class, creationalContext); - return (CDIExtension)result; + return ( CDIExtension ) beanManager.getContext( ApplicationScoped.class ).get( bean ); } private static boolean isSharedBaseClass(final Class clazz, final Set> beans) {