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

Commit a926b3f

Browse files
shamohGerrit Code Review
authored andcommitted
Merge "JAX-RS providers backed by dependent CDI beans can not be handled as request scoped components, cdi-test-webapp tests enabled by default (standalone grizzly)"
2 parents 653f7df + 879f6a0 commit a926b3f

File tree

6 files changed

+118
-20
lines changed

6 files changed

+118
-20
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,18 @@ public class CdiComponentProvider implements ComponentProvider, Extension {
160160
@Override
161161
public Boolean compute(final Class<?> clazz) {
162162
return Application.class.isAssignableFrom(clazz)
163-
|| Providers.isJaxRsProvider(clazz)
163+
|| jaxRsProvidersCache.compute(clazz)
164164
|| Resource.from(clazz) != null;
165165
}
166166
});
167167

168+
private final Cache<Class<?>, Boolean> jaxRsProvidersCache = new Cache<>(new Computable<Class<?>, Boolean>() {
169+
@Override
170+
public Boolean compute(final Class<?> clazz) {
171+
return Providers.isJaxRsProvider(clazz);
172+
}
173+
});
174+
168175
private final Hk2CustomBoundTypesProvider customHk2TypesProvider;
169176
private final Hk2LocatorManager locatorManager;
170177

@@ -313,12 +320,13 @@ public boolean bind(final Class<?> clazz, final Set<Class<?>> providerContracts)
313320
}
314321

315322
final boolean isJaxRsApp = isJaxRsComponent && Application.class.isAssignableFrom(clazz);
323+
final boolean isJaxRsProvider = jaxRsProvidersCache.compute(clazz);
316324

317325
final DynamicConfiguration dc = Injections.getConfiguration(locator);
318326

319327
final Class<? extends Annotation> beanScopeAnnotation = CdiUtil.getBeanScope(clazz, beanManager);
320328
final boolean isRequestScoped = beanScopeAnnotation == RequestScoped.class
321-
|| beanScopeAnnotation == Dependent.class && !isJaxRsApp;
329+
|| (beanScopeAnnotation == Dependent.class && !isJaxRsApp && !isJaxRsProvider);
322330

323331
Factory beanFactory = isRequestScoped
324332
? new RequestScopedCdiBeanHk2Factory(clazz, locator, beanManager, isCdiManaged)

tests/integration/cdi-test-webapp/pom.xml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,40 @@
7676
<type>pom</type>
7777
<scope>test</scope>
7878
</dependency>
79+
<dependency>
80+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
81+
<artifactId>jersey-weld2-se</artifactId>
82+
<scope>test</scope>
83+
</dependency>
7984
</dependencies>
85+
8086
<build>
8187
<finalName>${project.artifactId}</finalName>
82-
<plugins>
83-
<plugin>
84-
<artifactId>maven-surefire-plugin</artifactId>
85-
<configuration>
86-
<skipTests>${skipTests}</skipTests>
87-
<systemPropertyVariables>
88-
<jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
89-
<jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
90-
</systemPropertyVariables>
91-
</configuration>
92-
</plugin>
93-
</plugins>
9488
</build>
95-
<properties>
96-
<skipTests>true</skipTests>
97-
<testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
98-
<testContainerPort>8080</testContainerPort>
99-
</properties>
89+
90+
<profiles>
91+
<profile>
92+
<id>run-external-tests</id>
93+
<build>
94+
<plugins>
95+
<plugin>
96+
<groupId>org.apache.maven.plugins</groupId>
97+
<artifactId>maven-surefire-plugin</artifactId>
98+
<configuration>
99+
<systemPropertyVariables>
100+
<jersey.config.test.container.factory>${external.container.factory}</jersey.config.test.container.factory>
101+
<jersey.config.test.container.port>${external.container.port}</jersey.config.test.container.port>
102+
</systemPropertyVariables>
103+
</configuration>
104+
</plugin>
105+
</plugins>
106+
</build>
107+
<properties>
108+
<!-- External test container configuration is done via properties to allow overriding via command line. -->
109+
<external.container.factory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</external.container.factory>
110+
<external.container.port>8080</external.container.port>
111+
<maven.test.skip>false</maven.test.skip>
112+
</properties>
113+
</profile>
114+
</profiles>
100115
</project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5+
6+
Copyright (c) 2013-2015 Oracle and/or its affiliates. All rights reserved.
7+
8+
The contents of this file are subject to the terms of either the GNU
9+
General Public License Version 2 only ("GPL") or the Common Development
10+
and Distribution License("CDDL") (collectively, the "License"). You
11+
may not use this file except in compliance with the License. You can
12+
obtain a copy of the License at
13+
http://glassfish.java.net/public/CDDL+GPL_1_1.html
14+
or packager/legal/LICENSE.txt. See the License for the specific
15+
language governing permissions and limitations under the License.
16+
17+
When distributing the software, include this License Header Notice in each
18+
file and include the License file at packager/legal/LICENSE.txt.
19+
20+
GPL Classpath Exception:
21+
Oracle designates this particular file as subject to the "Classpath"
22+
exception as provided by Oracle in the GPL Version 2 section of the License
23+
file that accompanied this code.
24+
25+
Modifications:
26+
If applicable, add the following below the License Header, with the fields
27+
enclosed by brackets [] replaced by your own identifying information:
28+
"Portions Copyright [year] [name of copyright owner]"
29+
30+
Contributor(s):
31+
If you wish your version of this file to be governed by only the CDDL or
32+
only the GPL Version 2, indicate your decision by adding "[Contributor]
33+
elects to include this software in this distribution under the [CDDL or GPL
34+
Version 2] license." If you don't indicate a single choice of license, a
35+
recipient has the option to distribute your version of this file under
36+
either the CDDL, the GPL Version 2 or to extend the choice of license to
37+
its licensees as provided above. However, if you add GPL Version 2 code
38+
and therefore, elected the GPL Version 2 license, then the option applies
39+
only if the new code is made subject to such option by the copyright
40+
holder.
41+
42+
-->
43+
<beans/>

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

Lines changed: 18 additions & 1 deletion
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 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2013-2015 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
@@ -46,6 +46,8 @@
4646

4747
import org.glassfish.jersey.test.JerseyTest;
4848

49+
import org.jboss.weld.environment.se.Weld;
50+
4951
/**
5052
* Test for CDI web application resources.
5153
* Run with:
@@ -58,6 +60,21 @@
5860
*/
5961
public class CdiTest extends JerseyTest {
6062

63+
Weld weld;
64+
65+
@Override
66+
public void setUp() throws Exception {
67+
weld = new Weld();
68+
weld.initialize();
69+
super.setUp();
70+
}
71+
72+
@Override
73+
public void tearDown() throws Exception {
74+
weld.shutdown();
75+
super.tearDown();
76+
}
77+
6178
@Override
6279
protected Application configure() {
6380
return new MyApplication();

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import javax.ws.rs.client.Entity;
4646
import javax.ws.rs.client.WebTarget;
4747

48+
import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
49+
4850
import org.junit.Test;
4951
import org.junit.runner.RunWith;
5052
import org.junit.runners.Parameterized;
@@ -91,8 +93,14 @@ public void testGet() {
9193

9294
@Test
9395
public void testCounter() {
96+
9497
final WebTarget counter = target().path("jcdibean/singleton").path(p).queryParam("x", x).path("counter");
9598

99+
if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
100+
// TODO: remove this workaround once JERSEY-2744 is resolved
101+
counter.request().put(Entity.text("10"));
102+
}
103+
96104
String c10 = counter.request().get(String.class);
97105
assertThat(c10, containsString("10"));
98106

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545
import javax.ws.rs.client.Entity;
4646
import javax.ws.rs.client.WebTarget;
4747

48+
import org.glassfish.jersey.test.external.ExternalTestContainerFactory;
49+
4850
import org.junit.Test;
4951
import org.junit.runner.RunWith;
5052
import org.junit.runners.Parameterized;
@@ -94,6 +96,11 @@ public void testCounter() {
9496

9597
final WebTarget counter = target().path("jcdibean/dependent/singleton").path(p).queryParam("x", x).path("counter");
9698

99+
if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) {
100+
// TODO: remove this workaround once JERSEY-2744 is resolved
101+
counter.request().put(Entity.text("10"));
102+
}
103+
97104
String c10 = counter.request().get(String.class);
98105
assertThat(c10, containsString("10"));
99106

0 commit comments

Comments
 (0)