From 0b4e832da185c7c50a97538cd21ce969676b25c1 Mon Sep 17 00:00:00 2001 From: Santiago Pericas-Geertsen Date: Mon, 7 Oct 2024 14:04:12 -0400 Subject: [PATCH] Adds support to control 100-Continue requests in the Helidon connector. This is implemented by mapping a Jersey to a WebClient property. Updates docs and tests. (#9332) --- .../asciidoc/mp/jaxrs/helidon-connector.adoc | 5 +++++ .../jersey/connector/HelidonConnector.java | 13 ++++++++---- .../helidon/jersey/connector/ConfigTest.java | 20 +++++++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/docs/src/main/asciidoc/mp/jaxrs/helidon-connector.adoc b/docs/src/main/asciidoc/mp/jaxrs/helidon-connector.adoc index cab34bcd99f..ab5b695cfcb 100644 --- a/docs/src/main/asciidoc/mp/jaxrs/helidon-connector.adoc +++ b/docs/src/main/asciidoc/mp/jaxrs/helidon-connector.adoc @@ -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 diff --git a/jersey/connector/src/main/java/io/helidon/jersey/connector/HelidonConnector.java b/jersey/connector/src/main/java/io/helidon/jersey/connector/HelidonConnector.java index 59c83627782..0481b9031a1 100644 --- a/jersey/connector/src/main/java/io/helidon/jersey/connector/HelidonConnector.java +++ b/jersey/connector/src/main/java/io/helidon/jersey/connector/HelidonConnector.java @@ -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; @@ -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 properties = config.getProperties(); - var builder = WebClientConfig.builder(); + WebClientConfig.Builder builder = WebClientConfig.builder(); // use config for client Config helidonConfig = helidonConfig(config).orElse(Config.empty()); @@ -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) { diff --git a/jersey/connector/src/test/java/io/helidon/jersey/connector/ConfigTest.java b/jersey/connector/src/test/java/io/helidon/jersey/connector/ConfigTest.java index 56701f80136..20629316e1e 100644 --- a/jersey/connector/src/test/java/io/helidon/jersey/connector/ConfigTest.java +++ b/jersey/connector/src/test/java/io/helidon/jersey/connector/ConfigTest.java @@ -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. @@ -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())); @@ -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)); + } }