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

Commit 303742e

Browse files
author
Marek Potociar
committed
Fixed missing propagation of media type parameters into entity providers.
- See new test method in MessageBodyWriterTest in E2E tests for the reproducer test. - Some additional core media type and header parser refactoring & cleanup. - Consolidation and renaming in MediaTypes utility. - Quality source parameters reuse the same parsing as quality parameters; this means that values higher than "1.0" throw ParseException. - Header parser (and any dependent code) updated to work with CharSequence - MethodSelectingRouter updated to re-use common entity provider information Change-Id: If16fe49345b32edf9f6e121ac238f1ad7716e1a4 Signed-off-by: Marek Potociar <[email protected]>
1 parent cb0261b commit 303742e

File tree

70 files changed

+2238
-1241
lines changed

Some content is hidden

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

70 files changed

+2238
-1241
lines changed

core-client/src/main/java/org/glassfish/jersey/client/JerseyInvocation.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) 2011-2014 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2011-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
@@ -105,7 +105,7 @@ private enum EntityPresence {
105105
OPTIONAL
106106
}
107107

108-
private static Map<String, EntityPresence> METHODS = initializeMap();
108+
private static final Map<String, EntityPresence> METHODS = initializeMap();
109109

110110
private static Map<String, EntityPresence> initializeMap() {
111111
final Map<String, EntityPresence> map = new HashMap<String, EntityPresence>();

core-common/src/main/java/org/glassfish/jersey/filter/LoggingFilter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
* only if the new code is made subject to such option by the copyright
3838
* holder.
3939
*/
40-
4140
package org.glassfish.jersey.filter;
4241

4342
import java.io.BufferedInputStream;
@@ -72,7 +71,6 @@
7271

7372
import javax.annotation.Priority;
7473

75-
import org.glassfish.jersey.internal.util.collection.StringIgnoreCaseKeyComparator;
7674
import org.glassfish.jersey.message.MessageUtils;
7775

7876
/**
@@ -100,7 +98,7 @@ public class LoggingFilter implements ContainerRequestFilter, ClientRequestFilte
10098

10199
@Override
102100
public int compare(final Map.Entry<String, List<String>> o1, final Map.Entry<String, List<String>> o2) {
103-
return StringIgnoreCaseKeyComparator.SINGLETON.compare(o1.getKey(), o2.getKey());
101+
return o1.getKey().compareToIgnoreCase(o2.getKey());
104102
}
105103
};
106104

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

Lines changed: 5 additions & 6 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
@@ -37,7 +37,6 @@
3737
* only if the new code is made subject to such option by the copyright
3838
* holder.
3939
*/
40-
4140
package org.glassfish.jersey.internal;
4241

4342
import java.lang.reflect.Type;
@@ -126,7 +125,7 @@ public ContextResolverFactory(final ServiceLocator locator) {
126125

127126
for (final Map.Entry<Type, Map<MediaType, List<ContextResolver>>> e : rs.entrySet()) {
128127
final Map<MediaType, ContextResolver> mr = new KeyComparatorHashMap<MediaType, ContextResolver>(
129-
4, MessageBodyFactory.MEDIA_TYPE_COMPARATOR);
128+
4, MessageBodyFactory.MEDIA_TYPE_KEY_COMPARATOR);
130129
resolver.put(e.getKey(), mr);
131130

132131
cache.put(e.getKey(), new ConcurrentHashMap<MediaType, ContextResolver>(4));
@@ -219,22 +218,22 @@ public <T> ContextResolver<T> resolve(final Type t, MediaType m) {
219218
}
220219

221220
if (m == null) {
222-
m = MediaTypes.GENERAL_MEDIA_TYPE;
221+
m = MediaType.WILDCARD_TYPE;
223222
}
224223

225224
ContextResolver<T> cr = crMapCache.get(m);
226225
if (cr == null) {
227226
final Map<MediaType, ContextResolver> crMap = resolver.get(t);
228227

229228
if (m.isWildcardType()) {
230-
cr = crMap.get(MediaTypes.GENERAL_MEDIA_TYPE);
229+
cr = crMap.get(MediaType.WILDCARD_TYPE);
231230
if (cr == null) {
232231
cr = NULL_CONTEXT_RESOLVER;
233232
}
234233
} else if (m.isWildcardSubtype()) {
235234
// Include x, x/* and */*
236235
final ContextResolver<T> subTypeWildCard = crMap.get(m);
237-
final ContextResolver<T> wildCard = crMap.get(MediaTypes.GENERAL_MEDIA_TYPE);
236+
final ContextResolver<T> wildCard = crMap.get(MediaType.WILDCARD_TYPE);
238237

239238
cr = new ContextResolverAdapter(subTypeWildCard, wildCard).reduce();
240239
} else {

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

Lines changed: 2 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-2013 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
@@ -40,15 +40,14 @@
4040
package org.glassfish.jersey.internal.util.collection;
4141

4242
import java.io.Serializable;
43-
import java.util.Comparator;
4443

4544
/**
4645
* A key comparator.
4746
*
4847
* @param <K> Key's type
4948
* @author Paul Sandoz
5049
*/
51-
public interface KeyComparator<K> extends Comparator<K>, Serializable {
50+
public interface KeyComparator<K> extends Serializable {
5251

5352
/**
5453
* Compare two keys for equality.

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

Lines changed: 3 additions & 5 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-2013 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
@@ -51,16 +51,14 @@ public class StringIgnoreCaseKeyComparator implements KeyComparator<String> {
5151

5252
public static final StringIgnoreCaseKeyComparator SINGLETON = new StringIgnoreCaseKeyComparator();
5353

54+
@Override
5455
public int hash(String k) {
5556
return k.toLowerCase().hashCode();
5657
}
5758

59+
@Override
5860
public boolean equals(String x, String y) {
5961
return x.equalsIgnoreCase(y);
6062
}
6163

62-
public int compare(String o1, String o2) {
63-
return o1.compareToIgnoreCase(o2);
64-
}
65-
6664
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
package org.glassfish.jersey.message;
41+
42+
import java.util.List;
43+
44+
import javax.ws.rs.core.MediaType;
45+
46+
import org.glassfish.jersey.internal.util.ReflectionHelper;
47+
48+
/**
49+
* Abstract entity provider model.
50+
*
51+
* @author Marek Potociar (marek.potociar at oracle.com)
52+
* @since 2.16
53+
*/
54+
public abstract class AbstractEntityProviderModel<T> {
55+
56+
private final T provider;
57+
private final List<MediaType> declaredTypes;
58+
private final boolean custom;
59+
private final Class<?> providedType;
60+
61+
/**
62+
* Create new entity provider model.
63+
*
64+
* NOTE: The constructor is package private on purpose as we do not support extensions of this class from another package.
65+
*
66+
* @param provider entity provider instance.
67+
* @param declaredTypes declared supported media types.
68+
* @param custom custom flag; {@code true} is the provider is custom, {@code false} if the provider is one of the
69+
* default Jersey providers.
70+
* @param providerType parameterized entity provider type (used to retrieve the provided Java type).
71+
*/
72+
AbstractEntityProviderModel(final T provider,
73+
final List<MediaType> declaredTypes,
74+
final boolean custom,
75+
final Class<T> providerType) {
76+
this.provider = provider;
77+
this.declaredTypes = declaredTypes;
78+
this.custom = custom;
79+
this.providedType = getProviderClassParam(provider, providerType);
80+
}
81+
82+
/**
83+
* Get the modelled entity provider instance.
84+
*
85+
* @return entity provider instance.
86+
*/
87+
public T provider() {
88+
return provider;
89+
}
90+
91+
/**
92+
* Get types declared as supported (via {@code @Produces} or {@code @Consumes}) on the entity provider.
93+
*
94+
* @return declared supported types.
95+
*/
96+
public List<MediaType> declaredTypes() {
97+
return declaredTypes;
98+
}
99+
100+
/**
101+
* Get the {@code custom} flag value.
102+
*
103+
* @return {@code true} if the provider is a custom implementation, {@code false} if the provider is
104+
* one of the default providers supplied with Jersey.
105+
*/
106+
public boolean isCustom() {
107+
return custom;
108+
}
109+
110+
/**
111+
* Get the provided Java type.
112+
*
113+
* @return provided Java type.
114+
*/
115+
public Class<?> providedType() {
116+
return providedType;
117+
}
118+
119+
private static Class<?> getProviderClassParam(Object provider, Class<?> providerType) {
120+
final ReflectionHelper.DeclaringClassInterfacePair pair =
121+
ReflectionHelper.getClass(provider.getClass(), providerType);
122+
final Class[] classArgs = ReflectionHelper.getParameterizedClassArguments(pair);
123+
124+
return classArgs != null ? classArgs[0] : Object.class;
125+
}
126+
}

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

Lines changed: 23 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) 2010-2013 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
@@ -223,6 +223,17 @@ <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, A
223223
*/
224224
List<MessageBodyReader> getMessageBodyReadersForType(Class<?> type);
225225

226+
/**
227+
* Get a list of {@code MessageBodyReader} models that are suitable for the given {@code type}.
228+
*
229+
* The list is sorted based on the class hierarchy (most specific readers are first).
230+
*
231+
* @param type the class of object readers are requested for.
232+
* @return the list of supported {@code MessageBodyReader} models for given class.
233+
* @since 2.16
234+
*/
235+
List<ReaderModel> getReaderModelsForType(Class<?> type);
236+
226237
/**
227238
* Get the list of media types supported for a Java type.
228239
*
@@ -257,6 +268,17 @@ <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, A
257268
*/
258269
List<MessageBodyWriter> getMessageBodyWritersForType(Class<?> type);
259270

271+
/**
272+
* Get a list of {@code MessageBodyWriter} models that are suitable for the given {@code type}.
273+
*
274+
* The list is sorted based on the class hierarchy (most specific writers are first).
275+
*
276+
* @param type the class of object writers are requested for.
277+
* @return the list of supported {@code MessageBodyWriter} models for given class.
278+
* @since 2.16
279+
*/
280+
List<WriterModel> getWritersModelsForType(Class<?> type);
281+
260282
/**
261283
* Get the most acceptable media type supported for a Java type given a set of
262284
* acceptable media types.

0 commit comments

Comments
 (0)