From f0e0106dc24663294fdc9d787981c118c2236d99 Mon Sep 17 00:00:00 2001 From: Maxim Nesen Date: Fri, 26 Feb 2021 13:50:07 +0100 Subject: [PATCH 1/9] processing order for Jackson/Jaxb annotations Signed-off-by: Maxim Nesen --- .../DefaultJacksonJaxbJsonProvider.java | 25 ++++++++++++------- .../jackson/internal/model/ServiceTest.java | 4 ++- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java index 8b4ce1ce9f..8219cb1111 100644 --- a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java +++ b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -17,10 +17,11 @@ package org.glassfish.jersey.jackson.internal; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.Module; import org.glassfish.jersey.jackson.internal.jackson.jaxrs.cfg.Annotations; import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider; -import java.util.Objects; +import java.util.List; import javax.inject.Singleton; /** @@ -29,7 +30,11 @@ @Singleton public class DefaultJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider { + //do not register JaxbAnnotationModule because it brakes default annotations processing + private static final String EXCLUDE_MODULE_NAME = "JaxbAnnotationModule"; + public DefaultJacksonJaxbJsonProvider() { + super(); findAndRegisterModules(); } @@ -39,14 +44,16 @@ public DefaultJacksonJaxbJsonProvider(final Annotations... annotationsToUse) { } private void findAndRegisterModules() { - final ObjectMapper defaultMapper = _mapperConfig.getDefaultMapper(); - if (Objects.nonNull(defaultMapper)) { - defaultMapper.findAndRegisterModules(); - } + final ObjectMapper defaultMapper = _mapperConfig.getDefaultMapper(); final ObjectMapper mapper = _mapperConfig.getConfiguredMapper(); - if (Objects.nonNull(mapper)) { - mapper.findAndRegisterModules(); + + final List modules = ObjectMapper.findModules(); + modules.removeIf(mod -> mod.getModuleName().contains(EXCLUDE_MODULE_NAME)); + + defaultMapper.registerModules(modules); + if (mapper != null) { + mapper.registerModules(modules); } } -} +} \ No newline at end of file diff --git a/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java b/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java index 027064b27b..f3a664cc06 100644 --- a/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java +++ b/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/model/ServiceTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -23,6 +23,7 @@ import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; +import javax.xml.bind.annotation.XmlElement; @Path("/entity/") public final class ServiceTest { @@ -45,6 +46,7 @@ private static final class EntityTest { this.value = value; } + @XmlElement(name = "jaxb") @JsonGetter("name") public final String getName() { return name; From 6b87643f8b974af6bd600e4d58a026c3a0f5e33d Mon Sep 17 00:00:00 2001 From: Denis Kurochkin Date: Wed, 31 Mar 2021 15:36:06 +0300 Subject: [PATCH 2/9] Proper handling of chunked input streams in LoggingInterceptor (#4753) Signed-off-by: Denis Kurochkin --- core-common/pom.xml | 7 +- .../jersey/logging/LoggingInterceptor.java | 13 +++- .../logging/LoggingInterceptorTest.java | 78 ++++++++++++++++++- .../src/test/resources/surefire.policy | 5 +- 4 files changed, 98 insertions(+), 5 deletions(-) diff --git a/core-common/pom.xml b/core-common/pom.xml index 3288c5f45b..e36288f6c0 100644 --- a/core-common/pom.xml +++ b/core-common/pom.xml @@ -1,7 +1,7 @@ - 9.0 + 9.1 2.3.6 1.1 3.3.2 From d2b7b65b8f9baa8ed3069f083890badb63911dd9 Mon Sep 17 00:00:00 2001 From: jansupol Date: Tue, 6 Apr 2021 18:13:10 +0200 Subject: [PATCH 5/9] Lazy synchronized SSL Context initialization in the HttpUrlConnector Signed-off-by: jansupol --- .../glassfish/jersey/client/internal/HttpUrlConnector.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java index 72bceec3ad..21456b9c2e 100644 --- a/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java +++ b/core-client/src/main/java/org/glassfish/jersey/client/internal/HttpUrlConnector.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -73,7 +73,8 @@ public class HttpUrlConnector implements Connector { private static final String ALLOW_RESTRICTED_HEADERS_SYSTEM_PROPERTY = "sun.net.http.allowRestrictedHeaders"; // Avoid multi-thread uses of HttpsURLConnection.getDefaultSSLSocketFactory() because it does not implement a // proper lazy-initialization. See https://github.com/jersey/jersey/issues/3293 - private static final SSLSocketFactory DEFAULT_SSL_SOCKET_FACTORY = HttpsURLConnection.getDefaultSSLSocketFactory(); + private static final LazyValue DEFAULT_SSL_SOCKET_FACTORY = + Values.lazy((Value) () -> HttpsURLConnection.getDefaultSSLSocketFactory()); // The list of restricted headers is extracted from sun.net.www.protocol.http.HttpURLConnection private static final String[] restrictedHeaders = { "Access-Control-Request-Headers", @@ -305,7 +306,7 @@ protected void secureConnection(final JerseyClient client, final HttpURLConnecti suc.setHostnameVerifier(verifier); } - if (DEFAULT_SSL_SOCKET_FACTORY == suc.getSSLSocketFactory()) { + if (DEFAULT_SSL_SOCKET_FACTORY.get() == suc.getSSLSocketFactory()) { // indicates that the custom socket factory was not set suc.setSSLSocketFactory(sslSocketFactory.get()); } From 66aeadd992e5649f511f2c6cbe7eddf8e923d0de Mon Sep 17 00:00:00 2001 From: jansupol Date: Tue, 6 Apr 2021 15:44:27 +0200 Subject: [PATCH 6/9] Replace null Configuration in ContainerRequest with an empty instance to prevent possible NPE Signed-off-by: jansupol --- .../glassfish/jersey/server/ContainerRequest.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/core-server/src/main/java/org/glassfish/jersey/server/ContainerRequest.java b/core-server/src/main/java/org/glassfish/jersey/server/ContainerRequest.java index d67e8e7419..7823668fbf 100644 --- a/core-server/src/main/java/org/glassfish/jersey/server/ContainerRequest.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/ContainerRequest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -31,6 +31,7 @@ import java.util.function.Function; import java.util.stream.Collectors; +import javax.ws.rs.RuntimeType; import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.container.ContainerRequestFilter; import javax.ws.rs.container.ContainerResponseFilter; @@ -63,6 +64,8 @@ import org.glassfish.jersey.message.internal.OutboundJaxrsResponse; import org.glassfish.jersey.message.internal.TracingAwarePropertiesDelegate; import org.glassfish.jersey.message.internal.VariantSelector; +import org.glassfish.jersey.model.internal.CommonConfig; +import org.glassfish.jersey.model.internal.ComponentBag; import org.glassfish.jersey.model.internal.RankedProvider; import org.glassfish.jersey.process.Inflector; import org.glassfish.jersey.server.internal.LocalizationMessages; @@ -119,7 +122,7 @@ public class ContainerRequest extends InboundMessageContext // True if the request is used in the response processing phase (for example in ContainerResponseFilter) private boolean inResponseProcessingPhase; // lazy PropertiesResolver - private LazyValue propertiesResolver = Values.lazy( + private final LazyValue propertiesResolver = Values.lazy( (Value) () -> PropertiesResolver.create(getConfiguration(), getPropertiesDelegate()) ); @@ -188,7 +191,12 @@ public ContainerRequest( final String httpMethod, final SecurityContext securityContext, final PropertiesDelegate propertiesDelegate) { - this(baseUri, requestUri, httpMethod, securityContext, propertiesDelegate, (Configuration) null); + this(baseUri, requestUri, httpMethod, securityContext, propertiesDelegate, + new CommonConfig(RuntimeType.SERVER, ComponentBag.EXCLUDE_EMPTY) { + { + this.property(ContainerRequest.class.getName(), Deprecated.class.getSimpleName()); + } + }); } /** From 339e30a88127a76bb56a80d7008f353200b32050 Mon Sep 17 00:00:00 2001 From: jansupol Date: Tue, 30 Mar 2021 14:20:07 +0200 Subject: [PATCH 7/9] Adopted Jackson 2.12.2. No change in repackaged Jackson. Signed-off-by: jansupol --- pom.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index bc916373b6..0087da9392 100644 --- a/pom.xml +++ b/pom.xml @@ -61,7 +61,7 @@ - Roman Grigoriadi + Jorge Bescos Gascon Oracle Corporation http://www.oracle.com/ @@ -74,6 +74,12 @@ Dmitry Kornilov Oracle Corporation http://www.oracle.com/ + https://dmitrykornilov.net + + + David Kral + Oracle Corporation + http://www.oracle.com/ Tomas Kraus @@ -2099,7 +2105,7 @@ org.jvnet.hk2.*;version="[2.5,4)" 5.1.0 4.5.13 - 2.11.3 + 2.12.2 1.9.13 3.25.0-GA 3.3.0.Final From 9647ce541718cd0b583ceba1c735a886ec400b78 Mon Sep 17 00:00:00 2001 From: jansupol Date: Thu, 8 Apr 2021 16:21:33 +0200 Subject: [PATCH 8/9] Uptake Helidon 2.2.1 Signed-off-by: jansupol --- connectors/helidon-connector/pom.xml | 15 ++------------- .../helidon/connector/sse/EventOutputTest.java | 4 +--- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/connectors/helidon-connector/pom.xml b/connectors/helidon-connector/pom.xml index 5d2b443f52..fc138f2a47 100644 --- a/connectors/helidon-connector/pom.xml +++ b/connectors/helidon-connector/pom.xml @@ -1,7 +1,7 @@ - 2.0.2 + 2.2.1 provided @@ -81,16 +80,6 @@ false - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*Test.java - - - diff --git a/connectors/helidon-connector/src/test/java/org/glassfish/jersey/helidon/connector/sse/EventOutputTest.java b/connectors/helidon-connector/src/test/java/org/glassfish/jersey/helidon/connector/sse/EventOutputTest.java index 31ceb61e8d..5eb76e8e50 100644 --- a/connectors/helidon-connector/src/test/java/org/glassfish/jersey/helidon/connector/sse/EventOutputTest.java +++ b/connectors/helidon-connector/src/test/java/org/glassfish/jersey/helidon/connector/sse/EventOutputTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -139,7 +139,6 @@ public EventOutput getCommentsOnlyStream() throws IOException { } @Test - @Ignore //2.0.0-M3 public void testReadSseEventAsPlainString() throws Exception { final Response r = target().path("test/single").request().get(Response.class); assertThat(r.readEntity(String.class), containsString("single")); @@ -189,7 +188,6 @@ public void onEvent(InboundEvent inboundEvent) { } @Test - @Ignore // 2.0.0-M3 public void testReadFromClosedOutput() throws Exception { /** * Need to disable HTTP Keep-Alive to prevent this test from hanging in HttpURLConnection From 5f9510978b1c8077f3ed54cf8cbce0776e64cbba Mon Sep 17 00:00:00 2001 From: Jorge Bescos Gascon Date: Tue, 2 Mar 2021 15:11:23 +0100 Subject: [PATCH 9/9] ParameterConverter throwing IllegalArgumentException MUST result in 404 Signed-off-by: Jorge Bescos Gascon --- .../internal/inject/SingleValueExtractor.java | 8 +- .../server/IllegalArgumentExceptionTest.java | 124 ++++++++++++++++++ 2 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/IllegalArgumentExceptionTest.java diff --git a/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/SingleValueExtractor.java b/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/SingleValueExtractor.java index 69431fb157..8eb21d5660 100644 --- a/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/SingleValueExtractor.java +++ b/core-server/src/main/java/org/glassfish/jersey/server/internal/inject/SingleValueExtractor.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -62,7 +62,11 @@ public T extract(final MultivaluedMap parameters) { } catch (final WebApplicationException | ProcessingException ex) { throw ex; } catch (final IllegalArgumentException ex) { - return defaultValue(); + if (value == null) { + return defaultValue(); + } else { + throw new ExtractorException(ex); + } } catch (final Exception ex) { throw new ExtractorException(ex); } diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/IllegalArgumentExceptionTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/IllegalArgumentExceptionTest.java new file mode 100644 index 0000000000..3e27023f0c --- /dev/null +++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/IllegalArgumentExceptionTest.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v. 2.0, which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.e2e.server; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +import javax.validation.constraints.NotNull; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class IllegalArgumentExceptionTest extends JerseyTest { + + private static final String PARAM_NAME = "paramName"; + + @Override + protected Application configure() { + return new ResourceConfig(TestResource.class, TestParamProvider.class); + } + + @Path("test") + public static class TestResource { + @GET + @Path("1") + public String get1(@QueryParam(PARAM_NAME) CustomObj value) { + return "ok"; + } + @GET + @Path("2") + public String get2(@NotNull @QueryParam(PARAM_NAME) String value) { + return "ok"; + } + @GET + @Path("3") + public String get3(@NotNull @DefaultValue("get3") @QueryParam(PARAM_NAME) CustomObj value) { + return value.value; + } + @GET + @Path("4") + public String get4(@HeaderParam(PARAM_NAME) CustomObj header) { + return "ok"; + } + } + + @Test + public void illegalArgumentExceptionWith404() { + Response response = target().path("test/1").queryParam(PARAM_NAME, 1).request().get(); + assertEquals(404, response.getStatus()); + } + + @Test + public void validationExceptionWith400() { + Response response = target().path("test/2").request().get(); + assertEquals(400, response.getStatus()); + } + + @Test + public void with200() { + Response response = target().path("test/3").request().get(); + assertEquals(200, response.getStatus()); + assertEquals("get3", response.readEntity(String.class)); + } + + @Test + public void validationExceptionHeaderWith400() { + Response response = target().path("test/4").request().header(PARAM_NAME, "1").get(); + assertEquals(400, response.getStatus()); + } + + private static class CustomObj { + private String value; + } + + public static class TestParamProvider implements ParamConverterProvider { + @Override + public ParamConverter getConverter(Class rawType, Type genericType, Annotation[] annotations) { + return (ParamConverter) new ParamConverter() { + @Override + public CustomObj fromString(String value) { + if ("1".equals(value)) { + throw new IllegalArgumentException("test exception"); + } else if (value != null) { + CustomObj obj = new CustomObj(); + obj.value = value; + return obj; + } else { + return null; + } + } + @Override + public String toString(CustomObj value) { + return null; + } + }; + } + } +}