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

Commit b280312

Browse files
author
Petr Bouda
committed
JERSEY-2988: CDI beans cannot use an injected locator from SingleHk2LocatorManager during Jersey injection of CDI Beans
Change-Id: I0535e7c2087b5aa8d168c18b57a8ba0a24e6dfcd
1 parent 24981b8 commit b280312

File tree

10 files changed

+648
-1
lines changed

10 files changed

+648
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ public void inject(final Object t, final CreationalContext cc) {
902902
delegate.inject(t, cc);
903903

904904
final ServiceLocator il = multipleLocators ? getEffectiveLocator() : effectiveLocator;
905-
final ServiceLocator injectingLocator = (il != null) ? il : effectiveLocator;
905+
final ServiceLocator injectingLocator = (il != null) ? il : getEffectiveLocator();
906906

907907
if (injectingLocator != null) {
908908
injectingLocator.inject(t, CdiComponentProvider.CDI_CLASS_ANALYZER);

tests/integration/JERSEY-2988/pom.xml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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) 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+
44+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
45+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
46+
<modelVersion>4.0.0</modelVersion>
47+
48+
<parent>
49+
<groupId>org.glassfish.jersey.tests.integration</groupId>
50+
<artifactId>project</artifactId>
51+
<version>3.0-SNAPSHOT</version>
52+
</parent>
53+
54+
<artifactId>jersey-2988</artifactId>
55+
<packaging>war</packaging>
56+
<name>jersey-tests-integration-jersey-2988</name>
57+
58+
<description>
59+
Reproducer of JERSEY-2988.
60+
61+
Jersey does not set locator properly for SingleHk2LocatorManager.
62+
</description>
63+
64+
<properties>
65+
<failOnMissingWebXml>false</failOnMissingWebXml>
66+
</properties>
67+
68+
<dependencies>
69+
<!-- Jersey -->
70+
<dependency>
71+
<groupId>org.glassfish.jersey.containers</groupId>
72+
<artifactId>jersey-container-servlet</artifactId>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
76+
<artifactId>jersey-cdi1x</artifactId>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
80+
<artifactId>jersey-test-framework-provider-external</artifactId>
81+
<scope>test</scope>
82+
</dependency>
83+
84+
<!-- Weld -->
85+
<dependency>
86+
<groupId>javax.enterprise</groupId>
87+
<artifactId>cdi-api</artifactId>
88+
<version>2.0-EDR1</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.jboss.weld.servlet</groupId>
92+
<artifactId>weld-servlet-core</artifactId>
93+
<version>3.0.0.Alpha13</version>
94+
</dependency>
95+
</dependencies>
96+
97+
<build>
98+
<plugins>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-compiler-plugin</artifactId>
102+
</plugin>
103+
<plugin>
104+
<groupId>org.apache.maven.plugins</groupId>
105+
<artifactId>maven-failsafe-plugin</artifactId>
106+
</plugin>
107+
<plugin>
108+
<groupId>org.mortbay.jetty</groupId>
109+
<artifactId>jetty-maven-plugin</artifactId>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.integration.jersey2988;
42+
43+
import javax.ws.rs.core.Configuration;
44+
import javax.ws.rs.core.Context;
45+
import javax.ws.rs.core.Response;
46+
47+
import javax.enterprise.context.ApplicationScoped;
48+
49+
@ApplicationScoped
50+
public class ContextAwareBean {
51+
52+
@Context
53+
private Configuration field;
54+
55+
private Configuration setter;
56+
57+
public Response fieldConfig() {
58+
return field == null
59+
? Response.serverError().build()
60+
: Response.ok().build();
61+
}
62+
63+
public Response setterConfig() {
64+
return setter == null
65+
? Response.serverError().build()
66+
: Response.ok().build();
67+
}
68+
69+
@Context
70+
public void setConfig(Configuration setter) {
71+
this.setter = setter;
72+
}
73+
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.integration.jersey2988;
42+
43+
import javax.ws.rs.core.Context;
44+
import javax.ws.rs.core.HttpHeaders;
45+
import javax.ws.rs.core.Response;
46+
import javax.ws.rs.ext.ExceptionMapper;
47+
import javax.ws.rs.ext.Provider;
48+
49+
@Provider
50+
public class FieldContextExceptionMapper implements ExceptionMapper<IllegalStateException> {
51+
52+
@Context
53+
private HttpHeaders field;
54+
55+
@Override
56+
public Response toResponse(IllegalStateException ex) {
57+
return Response.status(520)
58+
.header("x-test-header", field.getHeaderString("x-test-header"))
59+
.build();
60+
}
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.integration.jersey2988;
42+
43+
import javax.ws.rs.core.Context;
44+
import javax.ws.rs.core.HttpHeaders;
45+
import javax.ws.rs.core.Response;
46+
import javax.ws.rs.ext.ExceptionMapper;
47+
import javax.ws.rs.ext.Provider;
48+
49+
@Provider
50+
public class SetterContextExceptionMapper implements ExceptionMapper<NullPointerException> {
51+
52+
private HttpHeaders setter;
53+
54+
@Context
55+
public void setSetter(HttpHeaders setter) {
56+
this.setter = setter;
57+
}
58+
59+
@Override
60+
public Response toResponse(NullPointerException ex) {
61+
return Response.status(520)
62+
.header("x-test-header", setter.getHeaderString("x-test-header"))
63+
.build();
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
package org.glassfish.jersey.tests.integration.jersey2988;
42+
43+
import javax.ws.rs.ApplicationPath;
44+
import javax.ws.rs.core.Application;
45+
46+
@ApplicationPath("/")
47+
public class TestApplication extends javax.ws.rs.core.Application {
48+
49+
}

0 commit comments

Comments
 (0)