From ab5ac1fc441b23a8a9fbf1bdd4db0b5f6fcface5 Mon Sep 17 00:00:00 2001 From: Jiangnan Jia Date: Tue, 14 Feb 2023 17:33:06 +0800 Subject: [PATCH] check endpoint of OpenSergoClient Signed-off-by: Jiangnan Jia --- src/main/java/io/opensergo/OpenSergoClient.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/opensergo/OpenSergoClient.java b/src/main/java/io/opensergo/OpenSergoClient.java index 1bf3b29..a977927 100644 --- a/src/main/java/io/opensergo/OpenSergoClient.java +++ b/src/main/java/io/opensergo/OpenSergoClient.java @@ -52,8 +52,8 @@ public class OpenSergoClient implements AutoCloseable { public static class Builder { - private String host; - private int port; + private String host = "localhost"; + private int port = 10246; private OpenSergoClientConfig openSergoConfig; public OpenSergoClient.Builder endpoint(String host, int port) { @@ -83,6 +83,7 @@ public OpenSergoClient(String host, int port) { } public OpenSergoClient(String host, int port, OpenSergoClientConfig clientConfig) { + checkEndpoint(host, port); checkClientConfig(clientConfig); // TODO: support TLS this.clientConfig = clientConfig; @@ -95,6 +96,11 @@ public OpenSergoClient(String host, int port, OpenSergoClientConfig clientConfig this.reqId = new AtomicInteger(0); } + private void checkEndpoint(String host, int port) { + AssertUtils.notEmpty(host, "host cannot be empty, need to give a valid host"); + AssertUtils.isTrue(port > 0, "port < 1 is invalid, need to give a valid port"); + } + private void checkClientConfig(OpenSergoClientConfig clientConfig) { AssertUtils.assertNotNull(clientConfig, "clientConfig cannot be null"); }