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

Commit b72a0f8

Browse files
author
Michal Gajdos
committed
JERSEY-2518: Disable MBW, MBR, ExceptionMapper automatic registration via META-INF/services
JERSEY-2519: Update Jackson JSON module to use Jackson 2.x (Jackson 1.x -> Jackson 2.x) - disabled automatic registration for MBRs, MBWs, ExceptiomMappers via META-INF/services - switched to Jackson 2.x (Jackson 1.x -> Jackson 2.x) - introduced metainf-services module - updated tests and migration guide Change-Id: I5e6e395d3839741d45c8de282b630998dfed6008 Signed-off-by: Michal Gajdos <[email protected]>
1 parent 036b3bb commit b72a0f8

File tree

59 files changed

+934
-144
lines changed

Some content is hidden

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

59 files changed

+934
-144
lines changed

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@
170170
<artifactId>jersey-entity-filtering</artifactId>
171171
<version>${project.version}</version>
172172
</dependency>
173+
<dependency>
174+
<groupId>org.glassfish.jersey.ext</groupId>
175+
<artifactId>jersey-metainf-services</artifactId>
176+
<version>${project.version}</version>
177+
</dependency>
173178
<dependency>
174179
<groupId>org.glassfish.jersey.ext</groupId>
175180
<artifactId>jersey-mvc</artifactId>
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.internal;
42+
43+
import org.glassfish.jersey.internal.util.PropertiesClass;
44+
45+
/**
46+
* Internal common (server/client) Jersey configuration properties.
47+
*
48+
* @author Michal Gajdos (michal.gajdos at oracle.com)
49+
*/
50+
@PropertiesClass
51+
public class InternalProperties {
52+
53+
/**
54+
* This property should be set by configured JSON feature to indicate that other (registered but not configured) JSON features
55+
* should not be configured.
56+
* <p/>
57+
* The name of the configuration property is <tt>{@value}</tt>.
58+
*
59+
* @since 2.9
60+
*/
61+
public static final String JSON_FEATURE = "jersey.config.jsonFeature";
62+
63+
/**
64+
* Client-specific version of {@link InternalProperties#JSON_FEATURE}.
65+
* <p/>
66+
* If present, it overrides the generic one for the client environment.
67+
*
68+
* @since 2.9
69+
*/
70+
public static final String JSON_FEATURE_CLIENT = "jersey.config.client.jsonFeature";
71+
72+
/**
73+
* Server-specific version of {@link InternalProperties#JSON_FEATURE}.
74+
* <p/>
75+
* If present, it overrides the generic one for the server environment.
76+
*
77+
* @since 2.9
78+
*/
79+
public static final String JSON_FEATURE_SERVER = "jersey.config.server.jsonFeature";
80+
81+
/**
82+
* Prevent instantiation.
83+
*/
84+
private InternalProperties() {
85+
}
86+
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,9 @@ protected void configure() {
131131
* TODO: com.sun.jersey.core.impl.provider.entity.EntityHolderReader
132132
*/
133133

134-
install(new ServiceFinderBinder<MessageBodyReader>(MessageBodyReader.class, applicationProperties, runtimeType));
135134
// Message body writers
136135
bind(StreamingOutputProvider.class).to(MessageBodyWriter.class).in(Singleton.class);
137136
bind(SourceProvider.SourceWriter.class).to(MessageBodyWriter.class).in(Singleton.class);
138-
install(new ServiceFinderBinder<MessageBodyWriter>(MessageBodyWriter.class, applicationProperties, runtimeType));
139137
install(new ServiceFinderBinder<HeaderDelegateProvider>(HeaderDelegateProvider.class, applicationProperties, runtimeType));
140138

141139
// XML factory injection points

docs/pom.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@
8282
<replace file="${src.dir}/jersey.ent" token="$jax-rs-version" value="${jaxrs.version}" />
8383
<replace file="${src.dir}/jersey.ent" token="$jax-rs-api-jar-version" value="${jaxrs.version}" />
8484
<replace file="${src.dir}/jersey.ent" token="$jaxb-api-jar-version" value="${jaxb.api.version}" />
85-
<!--<replace file="${src.dir}/jersey.ent" token="$jackson-version" value="${jackson.version}" />-->
86-
<replace file="${src.dir}/jersey.ent" token="$jackson-version" value="1.9.4" />
85+
<replace file="${src.dir}/jersey.ent" token="$jackson-version" value="${jackson.version}" />
8786
</tasks>
8887
</configuration>
8988
<id>process-entities</id>

docs/src/main/docbook/deployment.xml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,8 @@
222222
it means if you disable service loading the AutoDiscoverable feature is automatically disabled too</para>
223223
</listitem>
224224
<listitem>
225-
<para><literal>MessageBodyReader</literal> (server, client)</para>
226-
</listitem>
227-
<listitem>
228-
<para><literal>MessageBodyWriter</literal> (server, client)</para>
225+
<para><literal>ForcedAutoDiscoverable</literal> (server, client) -
226+
Jersey always looks for these auto discoverable features even if the service loading is disabled</para>
229227
</listitem>
230228
<listitem>
231229
<para><literal>HeaderDelegateProvider</literal> (server, client)</para>
@@ -241,6 +239,19 @@
241239
</listitem>
242240
</itemizedlist>
243241

242+
<itemizedlist>
243+
<title>List of additional SPIs recognized by Jersey in case the <literal>metainf-services</literal> module is on the classpath</title>
244+
<listitem>
245+
<para><literal>MessageBodyReader</literal> (server, client)</para>
246+
</listitem>
247+
<listitem>
248+
<para><literal>MessageBodyWriter</literal> (server, client)</para>
249+
</listitem>
250+
<listitem>
251+
<para><literal>ExceptionMapper</literal> (server, client)</para>
252+
</listitem>
253+
</itemizedlist>
254+
244255
Since it is possible to configure all SPI implementation classes or instances manually in your
245256
&lit.jaxrs.core.Application; subclass, disabling services lookup in Jersey does not affect any
246257
functionality of Jersey core modules and extensions and can save dozens of ms during application

docs/src/main/docbook/migration.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,27 @@
6969
<literal>ServerProperties.WADL_FEATURE_DISABLE</literal>).
7070
</para>
7171
</listitem>
72+
<listitem>
73+
<para>
74+
Automatic registration of <literal>MessageBodyWriter</literal>, <literal>MessageBodyReaders</literal>
75+
and <literal>ExceptionMappers</literal> via <literal>META-INF/services</literal> mechanism has been
76+
removed. Disabling the automatic registration of providers via <literal>META-INF/services</literal>
77+
may affect 3rd party libraries (i.e. Jackson 2.x) that are using this mechanism to register it's
78+
providers. In order to restore this functionality the <literal>org.glassfish.jersey.ext:jersey-metainf-services</literal>
79+
has to be added on the classpath. Otherwise such providers has to be registered manually.
80+
</para>
81+
</listitem>
82+
<listitem>
83+
<para>
84+
The Jackson JSON Jersey module has been updated to use Jackson 2.x instead of Jackson 1.x. This means
85+
that all the code that has been using Jackson 1.x for JSON (de)serialization has to be migrated to
86+
Jackson 2.x.
87+
</para>
88+
</listitem>
7289
</itemizedlist>
7390
</para>
7491
</section>
7592
</section>
76-
7793
<section xml:id="mig-2.8">
7894
<title>Migrating from Jersey 2.7 to 2.8</title>
7995

examples/json-jackson/src/main/java/org/glassfish/jersey/examples/jackson/CombinedAnnotationBean.java

Lines changed: 3 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) 2010-2012 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2014 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,7 +40,8 @@
4040
package org.glassfish.jersey.examples.jackson;
4141

4242
import javax.xml.bind.annotation.XmlRootElement;
43-
import org.codehaus.jackson.annotate.JsonProperty;
43+
44+
import com.fasterxml.jackson.annotation.JsonProperty;
4445

4546
/**
4647
* TODO javadoc.

examples/json-jackson/src/main/java/org/glassfish/jersey/examples/jackson/MyObjectMapperProvider.java

Lines changed: 19 additions & 26 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-2012 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2014 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
@@ -42,14 +42,13 @@
4242
import javax.ws.rs.ext.ContextResolver;
4343
import javax.ws.rs.ext.Provider;
4444

45-
import org.codehaus.jackson.map.AnnotationIntrospector;
46-
import org.codehaus.jackson.map.AnnotationIntrospector.Pair;
47-
import org.codehaus.jackson.map.DeserializationConfig;
48-
import org.codehaus.jackson.map.ObjectMapper;
49-
import org.codehaus.jackson.map.SerializationConfig;
50-
import org.codehaus.jackson.map.SerializationConfig.Feature;
51-
import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector;
52-
import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
45+
import com.fasterxml.jackson.databind.AnnotationIntrospector;
46+
import com.fasterxml.jackson.databind.DeserializationFeature;
47+
import com.fasterxml.jackson.databind.ObjectMapper;
48+
import com.fasterxml.jackson.databind.SerializationFeature;
49+
import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector;
50+
import com.fasterxml.jackson.databind.type.TypeFactory;
51+
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
5352

5453
/**
5554
* TODO javadoc.
@@ -68,7 +67,7 @@ public MyObjectMapperProvider() {
6867
}
6968

7069
@Override
71-
public ObjectMapper getContext(Class<?> type) {
70+
public ObjectMapper getContext(final Class<?> type) {
7271

7372
if (type == CombinedAnnotationBean.class) {
7473
return combinedObjectMapper;
@@ -78,30 +77,24 @@ public ObjectMapper getContext(Class<?> type) {
7877
}
7978

8079
private static ObjectMapper createCombinedObjectMapper() {
81-
82-
Pair combinedIntrospector = createJaxbJacksonAnnotationIntrospector();
83-
ObjectMapper result = new ObjectMapper();
84-
result.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);
85-
result.configure(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE, true);
86-
result.setDeserializationConfig(result.getDeserializationConfig().withAnnotationIntrospector(combinedIntrospector));
87-
result.setSerializationConfig(result.getSerializationConfig().withAnnotationIntrospector(combinedIntrospector));
88-
89-
return result;
80+
return new ObjectMapper()
81+
.configure(SerializationFeature.WRAP_ROOT_VALUE, true)
82+
.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true)
83+
.setAnnotationIntrospector(createJaxbJacksonAnnotationIntrospector());
9084
}
9185

9286
private static ObjectMapper createDefaultMapper() {
93-
94-
ObjectMapper result = new ObjectMapper();
95-
result.configure(Feature.INDENT_OUTPUT, true);
87+
final ObjectMapper result = new ObjectMapper();
88+
result.enable(SerializationFeature.INDENT_OUTPUT);
9689

9790
return result;
9891
}
9992

100-
private static Pair createJaxbJacksonAnnotationIntrospector() {
93+
private static AnnotationIntrospector createJaxbJacksonAnnotationIntrospector() {
10194

102-
AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector();
103-
AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
95+
final AnnotationIntrospector jaxbIntrospector = new JaxbAnnotationIntrospector(TypeFactory.defaultInstance());
96+
final AnnotationIntrospector jacksonIntrospector = new JacksonAnnotationIntrospector();
10497

105-
return new AnnotationIntrospector.Pair(jacksonIntrospector, jaxbIntrospector);
98+
return AnnotationIntrospector.pair(jacksonIntrospector, jaxbIntrospector);
10699
}
107100
}

examples/oauth-client-twitter/src/main/java/org/glassfish/jersey/examples/oauth/twitterclient/Status.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) 2010-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2014 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
@@ -43,7 +43,7 @@
4343
import javax.xml.bind.annotation.XmlElement;
4444
import javax.xml.bind.annotation.XmlRootElement;
4545

46-
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
46+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4747

4848
/**
4949
* Entity into which the Twitter status (tweet) is deserialized

examples/oauth-client-twitter/src/main/java/org/glassfish/jersey/examples/oauth/twitterclient/User.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) 2010-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2014 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
@@ -43,7 +43,7 @@
4343
import javax.xml.bind.annotation.XmlElement;
4444
import javax.xml.bind.annotation.XmlRootElement;
4545

46-
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
46+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4747

4848
/**
4949
* Entity into which the Twitter user is deserialized.

0 commit comments

Comments
 (0)