Skip to content

Commit

Permalink
[grid][java] fix code as suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
  • Loading branch information
VietND96 committed Apr 22, 2024
1 parent 1238be2 commit 5a042ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 10 additions & 4 deletions java/src/org/openqa/selenium/grid/node/relay/RelayOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ void protocolVersionThrowsConfigException() {
.isThrownBy(
() -> {
relayOptions.getServiceProtocolVersion();
});
})
.withMessageContaining("Invalid protocol version provided: HTTP/0.9");
}

@Test
Expand Down

0 comments on commit 5a042ae

Please sign in to comment.