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

Commit 1c56cb9

Browse files
japodGerrit Code Review
authored andcommitted
Merge "GF-21033: Make sure MultiPart feature works fine with CDI PS3: fixed jersey-2137 test as well"
2 parents c481b53 + e9ef633 commit 1c56cb9

File tree

11 files changed

+551
-8
lines changed

11 files changed

+551
-8
lines changed

containers/glassfish/jersey-gf-cdi/src/main/java/org/glassfish/jersey/gf/cdi/internal/CdiComponentProvider.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.lang.annotation.Target;
4444
import java.lang.annotation.Retention;
4545

46+
import java.lang.reflect.Constructor;
4647
import java.lang.reflect.Field;
4748
import java.lang.reflect.Member;
4849
import java.lang.reflect.Method;
@@ -88,8 +89,7 @@
8889
import javax.enterprise.inject.spi.InjectionTarget;
8990
import javax.enterprise.inject.spi.ProcessAnnotatedType;
9091
import javax.enterprise.inject.spi.ProcessInjectionTarget;
91-
import javax.enterprise.inject.spi.ProcessProducerField;
92-
import javax.enterprise.inject.spi.ProcessProducerMethod;
92+
import javax.enterprise.inject.spi.InjectionTargetFactory;
9393
import javax.enterprise.util.AnnotationLiteral;
9494
import javax.inject.Inject;
9595
import javax.inject.Qualifier;
@@ -129,7 +129,6 @@
129129
import static java.lang.annotation.ElementType.PARAMETER;
130130
import static java.lang.annotation.ElementType.TYPE;
131131
import static java.lang.annotation.RetentionPolicy.RUNTIME;
132-
import java.lang.reflect.Constructor;
133132

134133
/**
135134
* Jersey CDI integration implementation.
@@ -238,7 +237,9 @@ public void preDestroy(final T instance) {
238237
} : new InstanceManager<T>() {
239238

240239
final AnnotatedType<T> annotatedType = beanManager.createAnnotatedType(clazz);
241-
final InjectionTarget<T> injectionTarget = beanManager.createInjectionTarget(annotatedType);
240+
final InjectionTargetFactory<T> injectionTargetFactory = beanManager.getInjectionTargetFactory(annotatedType);
241+
final InjectionTarget<T> injectionTarget = injectionTargetFactory.createInjectionTarget(null);
242+
242243
final CreationalContext<T> creationalContext = beanManager.createCreationalContext(null);
243244

244245
@Override
@@ -380,6 +381,10 @@ public boolean bind(final Class<?> clazz, final Set<Class<?>> providerContracts)
380381
return false;
381382
}
382383

384+
if (isJerseyOrDependencyType(clazz)) {
385+
return false;
386+
}
387+
383388
final boolean isCdiManaged = isCdiComponent(clazz);
384389
final boolean isManagedBean = isManagedBean(clazz);
385390
final boolean isJaxRsComponent = isJaxRsComponentType(clazz);
@@ -859,7 +864,7 @@ static boolean isJaxRsComponentType(final Class<?> clazz) {
859864
Resource.from(clazz) != null;
860865
}
861866

862-
private boolean isJerseyOrDependencyType(final Class<?> clazz) {
867+
private static boolean isJerseyOrDependencyType(final Class<?> clazz) {
863868

864869
if (clazz.isPrimitive() || clazz.isSynthetic()) {
865870
return false;
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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-2014 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+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44+
<modelVersion>4.0.0</modelVersion>
45+
<parent>
46+
<groupId>org.glassfish.jersey.tests.integration</groupId>
47+
<artifactId>project</artifactId>
48+
<version>2.10-SNAPSHOT</version>
49+
</parent>
50+
51+
<artifactId>cdi-multipart-webapp</artifactId>
52+
<packaging>war</packaging>
53+
<name>jersey-tests-cdi-multipart-webapp</name>
54+
55+
<description>Jersey CDI test web application that uses multipart feature</description>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>javax.ws.rs</groupId>
60+
<artifactId>javax.ws.rs-api</artifactId>
61+
<scope>provided</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>javax.annotation</groupId>
65+
<artifactId>javax.annotation-api</artifactId>
66+
<scope>provided</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>javax.enterprise</groupId>
70+
<artifactId>cdi-api</artifactId>
71+
<scope>provided</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>org.glassfish.jersey.media</groupId>
75+
<artifactId>jersey-media-multipart</artifactId>
76+
<scope>provided</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
80+
<artifactId>jersey-test-framework-provider-bundle</artifactId>
81+
<type>pom</type>
82+
<scope>test</scope>
83+
</dependency>
84+
</dependencies>
85+
<build>
86+
<finalName>${project.artifactId}</finalName>
87+
<plugins>
88+
<plugin>
89+
<artifactId>maven-surefire-plugin</artifactId>
90+
<configuration>
91+
<skipTests>${skipTests}</skipTests>
92+
<systemPropertyVariables>
93+
<jersey.config.test.container.factory>${testContainerFactory}</jersey.config.test.container.factory>
94+
<jersey.config.test.container.port>${testContainerPort}</jersey.config.test.container.port>
95+
</systemPropertyVariables>
96+
</configuration>
97+
</plugin>
98+
</plugins>
99+
</build>
100+
<properties>
101+
<skipTests>true</skipTests>
102+
<testContainerFactory>org.glassfish.jersey.test.external.ExternalTestContainerFactory</testContainerFactory>
103+
<testContainerPort>8080</testContainerPort>
104+
</properties>
105+
</project>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2014 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.cdi.resources;
42+
43+
import javax.enterprise.context.RequestScoped;
44+
import javax.ws.rs.POST;
45+
import javax.ws.rs.Path;
46+
import javax.ws.rs.core.Response;
47+
import org.glassfish.jersey.media.multipart.FormDataParam;
48+
49+
50+
/**
51+
* GF-21033 reproducer. Just a resource using multi-part support.
52+
*
53+
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
54+
*/
55+
@Path("/echo")
56+
@RequestScoped
57+
public class EchoResource {
58+
59+
/**
60+
* We want to consume form data using multi-part provider.
61+
*
62+
* @param input form data
63+
* @return input data
64+
*/
65+
@POST
66+
public Response echoMultipart(@FormDataParam ("input") String input) {
67+
return Response.ok(input).build();
68+
}
69+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2014 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+
package org.glassfish.jersey.tests.cdi.resources;
41+
42+
import java.util.HashSet;
43+
import java.util.Set;
44+
45+
import javax.ws.rs.ApplicationPath;
46+
import javax.ws.rs.core.Application;
47+
48+
import org.glassfish.jersey.media.multipart.MultiPartFeature;
49+
50+
/**
51+
* GF-21033 reproducer. This is to make sure Jersey's multipart
52+
* feature could work in GF with CDI.
53+
*
54+
* @author Jakub Podlesak (jakub.podlesak at oracle.com)
55+
*/
56+
@ApplicationPath("/*")
57+
public class MyApplication extends Application {
58+
59+
final static Set<Class<?>> classes = new HashSet<Class<?>>();
60+
61+
static {
62+
classes.add(EchoResource.class);
63+
classes.add(MultiPartFeature.class);
64+
}
65+
@Override
66+
public Set<Class<?>> getClasses() {
67+
return classes;
68+
}
69+
}
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) 2014 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/>

0 commit comments

Comments
 (0)