Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

CDI Extension Fix on Master for Weld 1.1.32.Final #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jersey-servlet/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,14 @@
<configuration>
<instructions>
<Private-Package>
com.sun.jersey.server.impl.cdi,
com.sun.jersey.server.impl.ejb,
com.sun.jersey.server.impl.managedbeans
</Private-Package>
<Export-Package>
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,
<!-- the following is being used internally in GF REST API code! :-( -->
com.sun.jersey.server.impl.container.servlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,32 +120,12 @@ public static <T> T getInstance(BeanManager beanManager, Class<T> c) {
}

public static CDIExtension getCdiExtensionInstance(BeanManager beanManager) {

final Set<Bean<?>> 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<Bean<?>> beans) {
Expand Down