Skip to content

Commit

Permalink
Always register a jakarta.ws.rs.core.Application for CDI.
Browse files Browse the repository at this point in the history
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Aug 14, 2023
1 parent 5b7a255 commit bb51b62
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
* Sesion Bean JAX-RS components.
*
* @author Jozef Hartinger
*
*/
public class ResteasyCdiExtension implements Extension {
private static boolean active;
Expand All @@ -73,6 +72,7 @@ public static boolean isCDIActive() {
private final Map<Class<?>, Type> sessionBeanInterface = new HashMap<>();
private boolean generateClientBean = true;
private boolean addContextProducers = true;
private boolean noApplicationFound = true;

/**
* Obtain BeanManager reference for future use.
Expand Down Expand Up @@ -135,6 +135,11 @@ public void addContextProducer(@Observes final AfterTypeDiscovery event, final B
.createAnnotatedType(ContextProducers.class);
event.addAnnotatedType(producersAnnotatedType, ContextProducers.class.getCanonicalName());
}
if (noApplicationFound) {
// Add a generic Application if no application was defined
final AnnotatedType<Application> annotatedType = beanManager.createAnnotatedType(Application.class);
event.addAnnotatedType(annotatedType, Application.class.getCanonicalName());
}
}

/**
Expand Down Expand Up @@ -190,6 +195,7 @@ public <T> void observeProviders(@WithAnnotations({ Provider.class }) @Observes
*/
public <T extends Application> void observeApplications(@Observes ProcessAnnotatedType<T> event,
BeanManager beanManager) {
noApplicationFound = false;
if (!Utils.isScopeDefined(event.getAnnotatedType(), beanManager)) {
event.configureAnnotatedType().add(applicationScopedLiteral);
}
Expand Down Expand Up @@ -220,7 +226,6 @@ protected <T> InjectionTarget<T> wrapInjectionTarget(ProcessInjectionTarget<T> e
*
* @param <T> type
* @param event event
*
*/
public <T> void observeSessionBeans(@Observes ProcessSessionBean<T> event) {
Bean<Object> sessionBean = event.getBean();
Expand Down

0 comments on commit bb51b62

Please sign in to comment.