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

Allow override of Jersey property via config #2737

Merged
merged 2 commits into from
Feb 5, 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
7 changes: 6 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.
Copyright (c) 2018, 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 @@ -137,5 +137,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.helidon.microprofile.tests</groupId>
<artifactId>helidon-microprofile-tests-junit5</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 javax.inject.Inject;

import io.helidon.config.Config;
import io.helidon.microprofile.tests.junit5.AddConfig;
import io.helidon.microprofile.tests.junit5.HelidonTest;
import io.helidon.webserver.jersey.JerseySupport;
import org.junit.jupiter.api.Test;

import static org.glassfish.jersey.client.ClientProperties.IGNORE_EXCEPTION_RESPONSE;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* Test that it is possible to override {@code IGNORE_EXCEPTION_RESPONSE} in
* Jersey using config. See {@link io.helidon.webserver.jersey.JerseySupport}
* for more information.
*/
@HelidonTest
@AddConfig(key = IGNORE_EXCEPTION_RESPONSE, value = "false")
class JerseyPropertiesTest {

@Inject
Config config;

@Test
void testIgnoreExceptionResponseOverride() {
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
Expand Up @@ -42,6 +42,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 Down Expand Up @@ -108,17 +109,10 @@ public class JerseySupport implements Service {
private final Thread serviceShutdownHook;

/**
* 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.
* See https://github.com/eclipse-ee4j/jersey/pull/4641.
* If set to {@code "true"}, Jersey will ignore responses in exceptions.
*/
static final String IGNORE_EXCEPTION_RESPONSE = "jersey.config.client.ignoreExceptionResponse";

static {
System.setProperty(CommonProperties.ALLOW_SYSTEM_PROPERTIES_PROVIDER, "true");
System.setProperty(IGNORE_EXCEPTION_RESPONSE, "true");
}

/**
* Creates a Jersey Support based on the provided JAX-RS application.
*
Expand Down Expand Up @@ -148,6 +142,16 @@ private JerseySupport(Builder builder) {

this.appHandler = new ApplicationHandler(builder.resourceConfig, new ServerBinder(executorService));
this.container = new HelidonJerseyContainer(appHandler, builder.resourceConfig);

// 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