Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Jersey 2.33 and related changes #2776

Merged
merged 5 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<version.lib.jaxrs-api>2.1</version.lib.jaxrs-api>
<version.lib.jboss-transaction-spi>7.6.0.Final</version.lib.jboss-transaction-spi>
<version.lib.jedis>3.1.0</version.lib.jedis>
<version.lib.jersey>2.29.1</version.lib.jersey>
<version.lib.jersey>2.33</version.lib.jersey>
<version.lib.jsonb-api>1.0.1</version.lib.jsonb-api>
<version.lib.jsonp-api>1.1.2</version.lib.jsonp-api>
<version.lib.jsonp-impl>1.1.2</version.lib.jsonp-impl>
Expand Down
43 changes: 42 additions & 1 deletion microprofile/server/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2018, 2021 Oracle and/or its affiliates. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -31,6 +31,47 @@
<name>Helidon Microprofile Server</name>
<description>Server of the microprofile implementation</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<!--
- Execute all tests except JerseyPropertiesTest in the same VM.
-->
<execution>
<id>default-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<excludes>
<exclude>**/JerseyPropertiesTest.java</exclude>
</excludes>
</configuration>
</execution>
<!--
- Run JerseyPropertiesTest in its own VM to avoid conflicts.
-->
<execution>
<id>jersey-properties-test</id>
<goals>
<goal>test</goal>
</goals>
<phase>test</phase>
<configuration>
<includes>
<include>**/JerseyPropertiesTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>javax.ws.rs</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -115,6 +117,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.
*
Expand All @@ -140,6 +147,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<String> ignore = builder.config.get(IGNORE_EXCEPTION_RESPONSE).asString();
System.setProperty(IGNORE_EXCEPTION_RESPONSE, ignore.orElse("true"));
}
}

@Override
Expand Down