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

Commit 9f0e149

Browse files
japodGerrit Code Review
authored andcommitted
Merge "JERSEY-2930: fixed CDI integration so that all locators get propagated to the CDI injection targets. If injection happens at bootstrap (to inject app scoped beans), then the last locator seen is used effectively as that locator belongs to the actually initialised application. Uncommented cdi-test-webapp related tests (that used to fail in AS environment)."
2 parents fc683c2 + 5ae05a0 commit 9f0e149

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ private abstract class Hk2InjectedCdiTarget implements Hk2InjectedTarget {
885885
private final ClassLoader targetClassLoader;
886886

887887
private volatile ServiceLocator effectiveLocator;
888+
private volatile boolean multipleLocators = false;
888889

889890
public Hk2InjectedCdiTarget(final Class<?> componentClass,
890891
final InjectionTarget delegate) {
@@ -900,7 +901,8 @@ public Hk2InjectedCdiTarget(final Class<?> componentClass,
900901
public void inject(final Object t, final CreationalContext cc) {
901902
delegate.inject(t, cc);
902903

903-
final ServiceLocator injectingLocator = (effectiveLocator != null) ? effectiveLocator : getEffectiveLocator();
904+
final ServiceLocator il = multipleLocators ? getEffectiveLocator() : effectiveLocator;
905+
final ServiceLocator injectingLocator = (il != null) ? il : effectiveLocator;
904906

905907
if (injectingLocator != null) {
906908
injectingLocator.inject(t, CdiComponentProvider.CDI_CLASS_ANALYZER);
@@ -929,6 +931,9 @@ public void dispose(final Object t) {
929931

930932
@Override
931933
public void setLocator(final ServiceLocator effectiveLocator) {
934+
if (this.effectiveLocator != null) {
935+
this.multipleLocators = true;
936+
}
932937
this.effectiveLocator = effectiveLocator;
933938
}
934939
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ public void registerLocator(final ServiceLocator locator) {
7979
this.locator = null;
8080
multipleLocators = true;
8181
} // first and second case
82-
for (final Hk2InjectedTarget target : injectionTargets) {
83-
target.setLocator(this.locator);
84-
}
85-
} // ignore otherwise
82+
}
83+
84+
// pass the locator to registered injection targets anyway
85+
for (final Hk2InjectedTarget target : injectionTargets) {
86+
target.setLocator(locator);
87+
}
8688
}
8789

8890
@Override

tests/integration/cdi-test-webapp/src/main/java/org/glassfish/jersey/tests/cdi/resources/SecondaryApplication.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,12 @@
6060
*
6161
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
6262
*/
63-
// TODO: uncomment once JERSEY-2930 gets fixed
64-
//@ApplicationPath("secondary")
63+
@ApplicationPath("secondary")
6564
@ApplicationScoped
66-
public class SecondaryApplication { //extends Application {
65+
public class SecondaryApplication extends Application {
6766

6867

69-
private static final Logger LOGGER = Logger.getLogger(SecondaryApplication.class.getName());
70-
71-
// @Override
68+
@Override
7269
public Set<Class<?>> getClasses() {
7370
final Set<Class<?>> classes = new HashSet<Class<?>>();
7471
classes.add(SecondNonJaxRsBeanInjectedResource.class);

tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/NonJaxRsBeanJaxRsInjectionTest.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@
6262
import org.junit.After;
6363
import org.junit.Assume;
6464
import org.junit.Before;
65-
import org.junit.Ignore;
6665
import org.junit.Test;
6766

6867
/**
@@ -75,7 +74,6 @@
7574
*
7675
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
7776
*/
78-
@Ignore("waiting for https://java.net/jira/browse/JERSEY-2930")
7977
public class NonJaxRsBeanJaxRsInjectionTest {
8078

8179
public static final String MAIN_URI = "/main";
@@ -127,10 +125,7 @@ private void initializeWeld() {
127125

128126
private void startGrizzlyContainer() throws IOException {
129127
final ResourceConfig firstConfig = ResourceConfig.forApplicationClass(MainApplication.class);
130-
131-
// TODO: replace after https://java.net/jira/browse/JERSEY-2930 gets fixed
132-
final ResourceConfig secondConfig = ResourceConfig.forApplicationClass(MainApplication.class);
133-
// final ResourceConfig secondConfig = ResourceConfig.forApplicationClass(SecondaryApplication.class);
128+
final ResourceConfig secondConfig = ResourceConfig.forApplicationClass(SecondaryApplication.class);
134129

135130
httpServer = GrizzlyHttpServerFactory.createHttpServer(MAIN_APP_URI, firstConfig, false);
136131
final HttpHandler secondHandler = createGrizzlyContainer(secondConfig);

tests/integration/cdi-test-webapp/src/test/java/org/glassfish/jersey/tests/cdi/resources/SecondJaxRsInjectedCdiBeanTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
*
6161
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
6262
*/
63-
@Ignore("waiting for https://java.net/jira/browse/JERSEY-2930")
6463
public class SecondJaxRsInjectedCdiBeanTest extends JerseyTest {
6564
Weld weld;
6665

@@ -77,11 +76,10 @@ public void tearDown() throws Exception {
7776
super.tearDown();
7877
}
7978

80-
// TODO: uncomment after https://java.net/jira/browse/JERSEY-2930 gets fixed
81-
// @Override
82-
// protected Application configure() {
83-
// return new SecondaryApplication();
84-
// }
79+
@Override
80+
protected Application configure() {
81+
return new SecondaryApplication();
82+
}
8583

8684
@Override
8785
protected URI getBaseUri() {

0 commit comments

Comments
 (0)