From 5a042aeeba26c179c8cfae463ba31fe5518c6fe4 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Duc Date: Mon, 22 Apr 2024 09:43:29 +0000 Subject: [PATCH] [grid][java] fix code as suggestions Signed-off-by: Viet Nguyen Duc --- .../selenium/grid/node/relay/RelayOptions.java | 14 ++++++++++---- .../selenium/grid/node/relay/RelayOptionsTest.java | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java b/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java index 28cbef2cd2c8d..dfa52189a2745 100644 --- a/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java +++ b/java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java @@ -105,20 +105,26 @@ public URI getServiceStatusUri() { } public String getServiceProtocolVersion() { - String protocolVersion = config.get(RELAY_SECTION, "protocol-version").orElse(""); + String rawProtocolVersion = config.get(RELAY_SECTION, "protocol-version").orElse(""); + String protocolVersion = rawProtocolVersion; if (protocolVersion.isEmpty()) { return protocolVersion; } else { - // Support input in the form of "http/1.1" or "HTTP/1.1" - protocolVersion = protocolVersion.toUpperCase().replaceAll("/", "_").replaceAll("\\.", "_"); + protocolVersion = normalizeProtocolVersion(protocolVersion); } try { return Version.valueOf(protocolVersion).toString(); } catch (IllegalArgumentException e) { - throw new ConfigException("Unable to determine the service protocol version", e); + LOG.info("Unsupported protocol version: " + protocolVersion); + throw new ConfigException("Invalid protocol version provided: " + rawProtocolVersion, e); } } + private String normalizeProtocolVersion(String protocolVersion) { + // Support input in the form of "http/1.1" or "HTTP/1.1" + return protocolVersion.toUpperCase().replaceAll("/", "_").replaceAll("\\.", "_"); + } + // Method being used in SessionSlot @SuppressWarnings("unused") private boolean isServiceUp(HttpClient client) { diff --git a/java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java b/java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java index c48f79f54d888..83a4b9c78c64f 100644 --- a/java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java +++ b/java/test/org/openqa/selenium/grid/node/relay/RelayOptionsTest.java @@ -140,7 +140,8 @@ void protocolVersionThrowsConfigException() { .isThrownBy( () -> { relayOptions.getServiceProtocolVersion(); - }); + }) + .withMessageContaining("Invalid protocol version provided: HTTP/0.9"); } @Test