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

Commit 921ad77

Browse files
committed
JERSEY-2017: Container agnostic CDI support
- added ext/cdi/jersey-cdi1x module - added ext/cdi/jersey-cdi1x-ban-custom-hk2-binding module - added ext/cdi/jersey-cdi1x-transaction module - added ext/cdi/jersey-weld2-se module - added helloworld-weld example - fixed jersey-2137 integration test - enabled cdi-webapp tests to run on Grizzly - enabled cdi-webapp to run on Grizzly and Tomcat - fixed some FindBugs warnings - incorporated Michal's comments Change-Id: Ied4f4ce89f89470ea3ac461b2c5dcc0723e18179 Signed-off-by: Jakub Podlesak <[email protected]>
1 parent 16704c8 commit 921ad77

File tree

76 files changed

+3087
-393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3087
-393
lines changed

bom/pom.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,28 @@
147147
<version>${project.version}</version>
148148
</dependency>
149149
<dependency>
150-
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
151-
<artifactId>jersey-gf-cdi</artifactId>
150+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
151+
<artifactId>jersey-weld2-se</artifactId>
152152
<version>${project.version}</version>
153153
</dependency>
154154
<dependency>
155-
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
156-
<artifactId>jersey-gf-ejb</artifactId>
155+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
156+
<artifactId>jersey-cdi1x</artifactId>
157+
<version>${project.version}</version>
158+
</dependency>
159+
<dependency>
160+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
161+
<artifactId>jersey-cdi1x-transaction</artifactId>
162+
<version>${project.version}</version>
163+
</dependency>
164+
<dependency>
165+
<groupId>org.glassfish.jersey.ext.cdi</groupId>
166+
<artifactId>jersey-ext-cdi1x-ban-custom-hk2-binding</artifactId>
157167
<version>${project.version}</version>
158168
</dependency>
159169
<dependency>
160170
<groupId>org.glassfish.jersey.containers.glassfish</groupId>
161-
<artifactId>jersey-gf-cdi-ban-custom-hk2-binding</artifactId>
171+
<artifactId>jersey-gf-ejb</artifactId>
162172
<version>${project.version}</version>
163173
</dependency>
164174
<dependency>

containers/glassfish/jersey-gf-cdi-ban-custom-hk2-binding/src/main/resources/META-INF/services/org.glassfish.jersey.gf.cdi.spi.Hk2CustomBoundTypesProvider

Lines changed: 0 additions & 1 deletion
This file was deleted.

containers/glassfish/jersey-gf-cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension

Lines changed: 0 additions & 1 deletion
This file was deleted.

containers/glassfish/jersey-gf-cdi/src/main/resources/META-INF/services/org.glassfish.jersey.server.spi.ComponentProvider

Lines changed: 0 additions & 1 deletion
This file was deleted.

containers/glassfish/pom.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@
5858

5959
<modules>
6060
<module>jersey-gf-ejb</module>
61-
<module>jersey-gf-cdi</module>
62-
<module>jersey-gf-cdi-ban-custom-hk2-binding</module>
6361
</modules>
6462

6563
</project>

core-common/src/main/java/org/glassfish/jersey/internal/inject/Providers.java

Lines changed: 12 additions & 2 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) 2012-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-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
@@ -41,6 +41,7 @@
4141
package org.glassfish.jersey.internal.inject;
4242

4343
import java.lang.annotation.Annotation;
44+
import java.lang.reflect.Type;
4445
import java.util.ArrayList;
4546
import java.util.Collection;
4647
import java.util.Collections;
@@ -232,7 +233,16 @@ public static <T> Iterable<RankedProvider<T>> getAllRankedProviders(final Servic
232233
for (final ServiceHandle<T> provider : providers) {
233234
final ActiveDescriptor<T> key = provider.getActiveDescriptor();
234235
if (!providerMap.containsKey(key)) {
235-
providerMap.put(key, new RankedProvider<T>(provider.getService(), key.getRanking()));
236+
final Set<Type> contractTypes = key.getContractTypes();
237+
final Class<?> implementationClass = key.getImplementationClass();
238+
boolean proxyGenerated = true;
239+
for (Type ct : contractTypes) {
240+
if (((Class<?>)ct).isAssignableFrom(implementationClass)) {
241+
proxyGenerated = false;
242+
break;
243+
}
244+
}
245+
providerMap.put(key, new RankedProvider<T>(provider.getService(), key.getRanking(), proxyGenerated ? contractTypes : null));
236246
}
237247
}
238248

core-common/src/main/java/org/glassfish/jersey/internal/util/ReflectionHelper.java

Lines changed: 24 additions & 3 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) 2010-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-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
@@ -310,7 +310,7 @@ public Field[] run() {
310310
}
311311
};
312312
}
313-
313+
314314
/**
315315
* Get privileged action to obtain fields on given class, recursively through inheritance hierarchy.
316316
* If run using security manager, the returned privileged action
@@ -329,7 +329,7 @@ public Field[] run() {
329329
recurse(clazz, fields);
330330
return fields.toArray(new Field[0]);
331331
}
332-
332+
333333
private void recurse(final Class<?> clazz, final List<Field> fields) {
334334
fields.addAll(Arrays.asList(clazz.getDeclaredFields()));
335335
if(clazz.getSuperclass() != null) {
@@ -942,6 +942,27 @@ public static String getPropertyName(final Method method) {
942942
return new String(chars, offset, chars.length - offset);
943943
}
944944

945+
/**
946+
* Determine the most specific type from given set.
947+
*
948+
* @param contractTypes to be taken into account.
949+
* @return the most specific type.
950+
*/
951+
public static Class<?> theMostSpecificTypeOf(Set<Type> contractTypes) {
952+
Class<?> result = null;
953+
for (Type t : contractTypes) {
954+
final Class<?> next = (Class<?>) t;
955+
if (result == null) {
956+
result = next;
957+
} else {
958+
if (result.isAssignableFrom(next)) {
959+
result = next;
960+
}
961+
}
962+
}
963+
return result;
964+
}
965+
945966
/**
946967
* A tuple consisting of a concrete class and a declaring class that declares a
947968
* generic interface type.

core-common/src/main/java/org/glassfish/jersey/message/internal/WriterInterceptorExecutor.java

Lines changed: 2 additions & 2 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) 2012-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-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
@@ -108,7 +108,7 @@ public final class WriterInterceptorExecutor extends InterceptorExecutor<WriterI
108108
* @param entityStream {@link java.io.InputStream} from which an entity will be read. The stream is not
109109
* closed after reading the entity.
110110
* @param workers {@link org.glassfish.jersey.message.MessageBodyWorkers Message body workers}.
111-
* @param writerInterceptors Writer interceptor that are to be used to intercept the writing of an entity. The interceptors
111+
* @param writerInterceptors Writer interceptors that are to be used to intercept writing of an entity.
112112
* @param serviceLocator Service locator.
113113
*/
114114
public WriterInterceptorExecutor(final Object entity, final Class<?> rawType,

core-common/src/main/java/org/glassfish/jersey/model/internal/RankedProvider.java

Lines changed: 28 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) 2012-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2012-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
@@ -40,6 +40,9 @@
4040

4141
package org.glassfish.jersey.model.internal;
4242

43+
import java.lang.reflect.Type;
44+
import java.util.Collections;
45+
import java.util.Set;
4346
import javax.ws.rs.Priorities;
4447

4548
import javax.annotation.Priority;
@@ -56,6 +59,7 @@ public class RankedProvider<T> {
5659

5760
private final T provider;
5861
private final int rank;
62+
private final Set<Type> contractTypes;
5963

6064
/**
6165
* Creates a new {@code RankedProvider} instance. The rank of the provider is obtained from the {@link javax.annotation.Priority}
@@ -66,6 +70,7 @@ public class RankedProvider<T> {
6670
public RankedProvider(final T provider) {
6771
this.provider = provider;
6872
this.rank = computeRank(provider, ContractProvider.NO_PRIORITY);
73+
this.contractTypes = null;
6974
}
7075

7176
/**
@@ -75,8 +80,20 @@ public RankedProvider(final T provider) {
7580
* @param rank rank of this provider.
7681
*/
7782
public RankedProvider(final T provider, final int rank) {
83+
this(provider, rank, null);
84+
}
85+
86+
/**
87+
* Creates a new {@code RankedProvider} instance for given {@code provider} with specific {@code rank} (> 0).
88+
*
89+
* @param provider service provider to create a {@code RankedProvider} instance from.
90+
* @param rank rank of this provider.
91+
* @param contracts contracts implemented by the service provider
92+
*/
93+
public RankedProvider(final T provider, final int rank, final Set<Type> contracts) {
7894
this.provider = provider;
7995
this.rank = computeRank(provider, rank);
96+
this.contractTypes = contracts;
8097
}
8198

8299
private int computeRank(final T provider, final int rank) {
@@ -99,6 +116,16 @@ public int getRank() {
99116
return rank;
100117
}
101118

119+
/**
120+
* Get me set of implemented contracts.
121+
* Returns null if no contracts are implemented.
122+
*
123+
* @return set of contracts or null if no contracts have been implemented.
124+
*/
125+
public Set<Type> getContractTypes() {
126+
return contractTypes;
127+
}
128+
102129
@Override
103130
public String toString() {
104131
return provider.getClass().getName();

core-common/src/main/resources/org/glassfish/jersey/internal/localization.properties

Lines changed: 1 addition & 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) 2012-2014 Oracle and/or its affiliates. All rights reserved.
4+
# Copyright (c) 2012-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

0 commit comments

Comments
 (0)