Skip to content

Commit

Permalink
Adds support to control 100-Continue requests in the Helidon connecto…
Browse files Browse the repository at this point in the history
…r. This is implemented by mapping a Jersey to a WebClient property. Updates docs and tests. (helidon-io#9332)
  • Loading branch information
spericas authored and barchetta committed Oct 11, 2024
1 parent c9e54f3 commit 0b4e832
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/src/main/asciidoc/mp/jaxrs/helidon-connector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ properties supported by the connector, their types, scopes and default values.
|client, invocation
|true
|jersey.config.client.request.expect.100.continue.processing
|`Boolean`
|client
|true
|jersey.connector.helidon.config
|`io.helidon.config.Config`
|client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import static io.helidon.jersey.connector.HelidonProperties.SHARE_CONNECTION_CACHE;
import static io.helidon.jersey.connector.HelidonProperties.TLS;
import static org.glassfish.jersey.client.ClientProperties.CONNECT_TIMEOUT;
import static org.glassfish.jersey.client.ClientProperties.EXPECT_100_CONTINUE;
import static org.glassfish.jersey.client.ClientProperties.FOLLOW_REDIRECTS;
import static org.glassfish.jersey.client.ClientProperties.READ_TIMEOUT;
import static org.glassfish.jersey.client.ClientProperties.getValue;
Expand All @@ -76,10 +77,11 @@ class HelidonConnector implements Connector {
private final WebClient webClient;
private final Proxy proxy;

@SuppressWarnings("unchecked")
HelidonConnector(Client client, Configuration config) {
// create underlying HTTP client
Map<String, Object> properties = config.getProperties();
var builder = WebClientConfig.builder();
WebClientConfig.Builder builder = WebClientConfig.builder();

// use config for client
Config helidonConfig = helidonConfig(config).orElse(Config.empty());
Expand All @@ -98,14 +100,17 @@ class HelidonConnector implements Connector {
if (properties.containsKey(FOLLOW_REDIRECTS)) {
builder.followRedirects(getValue(properties, FOLLOW_REDIRECTS, true));
}
if (properties.containsKey(EXPECT_100_CONTINUE)) {
builder.sendExpectContinue(getValue(properties, EXPECT_100_CONTINUE, true));
}

//Whether WebClient TLS has been already set via config
// whether WebClient TLS has been already set via config
boolean helidonConfigTlsSet = helidonConfig.map(hc -> hc.get("tls").exists()).orElse(false);
boolean isJerseyClient = client instanceof JerseyClient;
//Whether Jersey client has non-default SslContext set. If so, we should honor these settings
// whether Jersey client has non-default SslContext set. If so, we should honor these settings
boolean jerseyHasDefaultSsl = isJerseyClient && ((JerseyClient) client).isDefaultSslContext();

if (!helidonConfigTlsSet || !isJerseyClient || !jerseyHasDefaultSsl) {// prefer Tls over SSLContext
if (!helidonConfigTlsSet || !isJerseyClient || !jerseyHasDefaultSsl) { // prefer Tls over SSLContext
if (properties.containsKey(TLS)) {
builder.tls(getValue(properties, TLS, Tls.class));
} else if (client.getSslContext() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 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 @@ -71,7 +71,7 @@ void testConfigPropertyOverride() {
}

@Test
void testConfigDefaut() {
void testConfigDefault() {
Client client = ClientBuilder.newClient();
HelidonConnector connector = new HelidonConnector(client, client.getConfiguration());
assertThat(connector.proxy(), is(Proxy.create()));
Expand All @@ -91,4 +91,20 @@ void testConfigProxy() {
assertThat(connector.proxy().username(), is(Optional.of("user")));
assertThat(connector.proxy().password(), notNullValue());
}

@Test
void testConfig100ContinueDefault() {
Client client = ClientBuilder.newBuilder().build();
HelidonConnector connector = new HelidonConnector(client, client.getConfiguration());
assertThat(connector.client().prototype().sendExpectContinue(), is(true));
}

@Test
void testConfig100ContinueOverride() {
Client client = ClientBuilder.newBuilder()
.property(ClientProperties.EXPECT_100_CONTINUE, "false")
.build();
HelidonConnector connector = new HelidonConnector(client, client.getConfiguration());
assertThat(connector.client().prototype().sendExpectContinue(), is(false));
}
}

0 comments on commit 0b4e832

Please sign in to comment.