Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 7393550

Browse files
author
petrbouda
committed
Fix CDI integration in multi Jersey application case
Change-Id: Id8c2f0c4ba1c796d46de687dc3bf174a5edd11f0
1 parent 51e6391 commit 7393550

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -82,16 +82,8 @@
8282
import javax.enterprise.inject.spi.InjectionTarget;
8383
import javax.enterprise.inject.spi.ProcessAnnotatedType;
8484
import javax.enterprise.inject.spi.ProcessInjectionTarget;
85-
import javax.enterprise.inject.spi.WithAnnotations;
8685
import javax.enterprise.util.AnnotationLiteral;
8786
import javax.inject.Qualifier;
88-
import javax.ws.rs.ApplicationPath;
89-
import javax.ws.rs.BeanParam;
90-
import javax.ws.rs.FormParam;
91-
import javax.ws.rs.HeaderParam;
92-
import javax.ws.rs.MatrixParam;
93-
import javax.ws.rs.PathParam;
94-
import javax.ws.rs.QueryParam;
9587
import javax.ws.rs.core.Application;
9688
import javax.ws.rs.core.Context;
9789

@@ -656,7 +648,7 @@ private void processInjectionTarget(@Observes final ProcessInjectionTarget event
656648

657649
Hk2InjectedCdiTarget target = null;
658650
if (isJerseyOrDependencyType(componentClass)) {
659-
target = new Hk2InjectedCdiTarget(componentClass, it) {
651+
target = new Hk2InjectedCdiTarget(it) {
660652

661653
@Override
662654
public Set<InjectionPoint> getInjectionPoints() {
@@ -667,7 +659,7 @@ public Set<InjectionPoint> getInjectionPoints() {
667659
};
668660
} else if (isJaxRsComponentType(componentClass)
669661
|| jaxrsInjectableTypes.contains(event.getAnnotatedType().getBaseType())) {
670-
target = new Hk2InjectedCdiTarget(componentClass, it) {
662+
target = new Hk2InjectedCdiTarget(it) {
671663

672664
@Override
673665
public Set<InjectionPoint> getInjectionPoints() {
@@ -880,18 +872,11 @@ private StringBuilder listElements(final StringBuilder logMsgBuilder, final Coll
880872
@SuppressWarnings("unchecked")
881873
private abstract class Hk2InjectedCdiTarget implements Hk2InjectedTarget {
882874

883-
private final Class<?> componentClass;
884875
private final InjectionTarget delegate;
885-
private final ClassLoader targetClassLoader;
886-
887876
private volatile ServiceLocator effectiveLocator;
888-
private volatile boolean multipleLocators = false;
889877

890-
public Hk2InjectedCdiTarget(final Class<?> componentClass,
891-
final InjectionTarget delegate) {
892-
this.componentClass = componentClass;
878+
public Hk2InjectedCdiTarget(InjectionTarget delegate) {
893879
this.delegate = delegate;
894-
this.targetClassLoader = componentClass.getClassLoader();
895880
}
896881

897882
@Override
@@ -901,8 +886,10 @@ public Hk2InjectedCdiTarget(final Class<?> componentClass,
901886
public void inject(final Object t, final CreationalContext cc) {
902887
delegate.inject(t, cc);
903888

904-
final ServiceLocator il = multipleLocators ? getEffectiveLocator() : effectiveLocator;
905-
final ServiceLocator injectingLocator = (il != null) ? il : getEffectiveLocator();
889+
ServiceLocator injectingLocator = getEffectiveLocator();
890+
if (injectingLocator == null) {
891+
injectingLocator = effectiveLocator;
892+
}
906893

907894
if (injectingLocator != null) {
908895
injectingLocator.inject(t, CdiComponentProvider.CDI_CLASS_ANALYZER);
@@ -931,9 +918,6 @@ public void dispose(final Object t) {
931918

932919
@Override
933920
public void setLocator(final ServiceLocator effectiveLocator) {
934-
if (this.effectiveLocator != null) {
935-
this.multipleLocators = true;
936-
}
937921
this.effectiveLocator = effectiveLocator;
938922
}
939923
}

0 commit comments

Comments
 (0)