From 05d29cdd5a117a90087bf8f2f4844e57b672510e Mon Sep 17 00:00:00 2001 From: Santiago Pericasgeertsen Date: Thu, 18 Feb 2021 10:31:49 -0500 Subject: [PATCH 1/5] Upgraded to Jersey 2.33. Fixed problem with SSE test and adapted 2.0 patch in https://github.com/eclipse-ee4j/jersey/pull/4641. --- dependencies/pom.xml | 2 +- .../server/JerseyPropertiesTest.java | 46 +++++++++++++++++++ .../microprofile/server/ServerSseTest.java | 19 ++++---- .../webserver/jersey/JerseySupport.java | 18 ++++++++ 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 microprofile/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 8be82a8069e..9e932dda8da 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -67,7 +67,7 @@ 2.1 7.6.0.Final 3.1.0 - 2.29.1 + 2.33 1.0.1 1.1.2 1.1.2 diff --git a/microprofile/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java b/microprofile/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java new file mode 100644 index 00000000000..ef2f2d7702c --- /dev/null +++ b/microprofile/server/src/test/java/io/helidon/microprofile/server/JerseyPropertiesTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.helidon.microprofile.server; + +import java.util.Properties; + +import io.helidon.config.Config; +import io.helidon.config.ConfigSources; +import io.helidon.webserver.jersey.JerseySupport; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.glassfish.jersey.client.ClientProperties.IGNORE_EXCEPTION_RESPONSE; + +/** + * Test that it is possible to override {@code IGNORE_EXCEPTION_RESPONSE} in + * Jersey using config. See {@link JerseySupport} + * for more information. + */ +class JerseyPropertiesTest { + + @Test + void testIgnoreExceptionResponseOverride() { + Properties properties = new Properties(); + properties.setProperty("jersey.config.client.ignoreExceptionResponse", "false"); + Config config = Config.builder(() -> ConfigSources.create(properties).build()).build(); + JerseySupport jerseySupport = JerseySupport.builder().config(config).build(); + assertNotNull(jerseySupport); + assertThat(System.getProperty(IGNORE_EXCEPTION_RESPONSE), is("false")); + } +} diff --git a/microprofile/server/src/test/java/io/helidon/microprofile/server/ServerSseTest.java b/microprofile/server/src/test/java/io/helidon/microprofile/server/ServerSseTest.java index 64c473638e4..9413c764a06 100644 --- a/microprofile/server/src/test/java/io/helidon/microprofile/server/ServerSseTest.java +++ b/microprofile/server/src/test/java/io/helidon/microprofile/server/ServerSseTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, 2020 Oracle and/or its affiliates. + * Copyright (c) 2019, 2021 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -103,16 +103,19 @@ public final class TestResource1 { @Produces(MediaType.SERVER_SENT_EVENTS) public void listenToEvents(@Context SseEventSink eventSink, @Context Sse sse) { while (true) { - eventSink.send(sse.newEvent("hello")).thenAccept(t -> { - if (t != null) { - System.out.println(t); - connClosedFuture.complete(null); - } - }); try { - Thread.sleep(50); + eventSink.send(sse.newEvent("hello")).thenAccept(t -> { + if (t != null) { + System.out.println(t); + connClosedFuture.complete(null); + } + }); + TimeUnit.MILLISECONDS.sleep(5); } catch (InterruptedException e) { // falls through + } catch (IllegalStateException e) { + //https://github.com/oracle/helidon/issues/1290 + connClosedFuture.complete(null); } } } diff --git a/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java b/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java index 1febc11d398..6a4b3950d09 100644 --- a/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java +++ b/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java @@ -44,6 +44,7 @@ import io.helidon.common.http.Http; import io.helidon.common.http.HttpRequest; import io.helidon.config.Config; +import io.helidon.config.ConfigValue; import io.helidon.webserver.Handler; import io.helidon.webserver.HttpException; import io.helidon.webserver.Routing; @@ -53,6 +54,7 @@ import io.opentracing.Span; import io.opentracing.SpanContext; +import org.glassfish.jersey.CommonProperties; import org.glassfish.jersey.internal.PropertiesDelegate; import org.glassfish.jersey.internal.util.collection.Ref; import org.glassfish.jersey.server.ApplicationHandler; @@ -61,6 +63,7 @@ import org.glassfish.jersey.server.model.Resource; import static java.util.Objects.requireNonNull; +import static org.glassfish.jersey.CommonProperties.PROVIDER_DEFAULT_DISABLE; /** * The Jersey Support integrates Jersey (JAX-RS RI) into the Web Server. @@ -115,6 +118,11 @@ public class JerseySupport implements Service { private final ExecutorService service; private final JerseyHandler handler = new JerseyHandler(); + /** + * If set to {@code "true"}, Jersey will ignore responses in exceptions. + */ + static final String IGNORE_EXCEPTION_RESPONSE = "jersey.config.client.ignoreExceptionResponse"; + /** * Creates a Jersey Support based on the provided JAX-RS application. * @@ -140,6 +148,16 @@ private JerseySupport(Builder builder) { } this.appHandler = new ApplicationHandler(builder.resourceConfig, new ServerBinder(executorService)); + + // This configuration via system properties is for the Jersey Client API. Any + // response in an exception will be mapped to an empty one to prevent data leaks + // unless property in config is set to false. + // See https://github.com/eclipse-ee4j/jersey/pull/4641. + if (!System.getProperties().contains(IGNORE_EXCEPTION_RESPONSE)) { + System.setProperty(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER, "true"); + ConfigValue ignore = builder.config.get(IGNORE_EXCEPTION_RESPONSE).asString(); + System.setProperty(IGNORE_EXCEPTION_RESPONSE, ignore.orElse("true")); + } } @Override From 718fb1caaaf6254770b1e5d7d8818341b5519dd3 Mon Sep 17 00:00:00 2001 From: Santiago Pericasgeertsen Date: Thu, 18 Feb 2021 10:47:08 -0500 Subject: [PATCH 2/5] Removed unused import. Signed-off-by: Santiago Pericasgeertsen --- .../src/main/java/io/helidon/webserver/jersey/JerseySupport.java | 1 - 1 file changed, 1 deletion(-) diff --git a/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java b/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java index 6a4b3950d09..aa20187eede 100644 --- a/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java +++ b/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java @@ -63,7 +63,6 @@ import org.glassfish.jersey.server.model.Resource; import static java.util.Objects.requireNonNull; -import static org.glassfish.jersey.CommonProperties.PROVIDER_DEFAULT_DISABLE; /** * The Jersey Support integrates Jersey (JAX-RS RI) into the Web Server. From 5b38ead2effdc3bef4af44b8cb942f441a907981 Mon Sep 17 00:00:00 2001 From: Santiago Pericasgeertsen Date: Thu, 18 Feb 2021 11:02:35 -0500 Subject: [PATCH 3/5] Fixed copyright. Signed-off-by: Santiago Pericasgeertsen --- .../main/java/io/helidon/webserver/jersey/JerseySupport.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java b/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java index aa20187eede..610a96e997c 100644 --- a/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java +++ b/webserver/jersey/src/main/java/io/helidon/webserver/jersey/JerseySupport.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020 Oracle and/or its affiliates. + * Copyright (c) 2017, 2021 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 913aeb25cff9642cc667cb95cd9870f7018b4f69 Mon Sep 17 00:00:00 2001 From: Santiago Pericasgeertsen Date: Thu, 18 Feb 2021 12:22:38 -0500 Subject: [PATCH 4/5] Run JerseyPropetiesTest in separate VM. Signed-off-by: Santiago Pericasgeertsen --- microprofile/server/pom.xml | 41 +++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/microprofile/server/pom.xml b/microprofile/server/pom.xml index c4783a3c108..547dc3567b3 100644 --- a/microprofile/server/pom.xml +++ b/microprofile/server/pom.xml @@ -31,6 +31,47 @@ Helidon Microprofile Server Server of the microprofile implementation + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + default-test + + test + + test + + + **/JerseyPropertiesTest.java + + + + + + jersey-properties-test + + test + + test + + + **/JerseyPropertiesTest.java + + + + + + + + javax.ws.rs From b3f318eb8e01b6b4434a5e401e6938596f1543e3 Mon Sep 17 00:00:00 2001 From: Santiago Pericasgeertsen Date: Thu, 18 Feb 2021 12:29:58 -0500 Subject: [PATCH 5/5] Fixed copyright. Signed-off-by: Santiago Pericasgeertsen --- microprofile/server/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microprofile/server/pom.xml b/microprofile/server/pom.xml index 547dc3567b3..a804f99cfb1 100644 --- a/microprofile/server/pom.xml +++ b/microprofile/server/pom.xml @@ -1,7 +1,7 @@