zhenyuT commented on code in PR #133:
URL: 
https://github.com/apache/incubator-hugegraph-commons/pull/133#discussion_r1375439213


##########
hugegraph-common/src/main/java/org/apache/hugegraph/rest/AbstractRestClient.java:
##########
@@ -207,31 +263,62 @@ public RestResult post(String path, Object object) {
     }
 
     @Override
-    public RestResult post(String path, Object object,
-                           MultivaluedMap<String, Object> headers) {
+    public RestResult post(String path, Object object, RestHeaders headers) {
         return this.post(path, object, headers, null);
     }
 
     @Override
-    public RestResult post(String path, Object object,
-                           Map<String, Object> params) {
+    public RestResult post(String path, Object object, Map<String, Object> 
params) {
         return this.post(path, object, null, params);
     }
 
+    private Request.Builder getRequestBuilder(String path, String id, 
RestHeaders headers,
+                                              Map<String, Object> params) {
+        HttpUrl.Builder urlBuilder = HttpUrl.parse(this.baseUrl).newBuilder()
+                                            .addPathSegments(path);
+        if (id != null) {
+            urlBuilder.addPathSegment(id);
+        }
+
+        if (params != null) {
+            params.forEach((name, value) -> {
+                if (value == null) {
+                    return;
+                }
+
+                if (value instanceof Collection) {
+                    for (Object i : (Collection<?>) value) {
+                        urlBuilder.addQueryParameter(name, String.valueOf(i));
+                    }
+                } else {
+                    urlBuilder.addQueryParameter(name, String.valueOf(value));
+                }
+            });
+        }
+
+        Request.Builder builder = requestBuilder.url(urlBuilder.build());
+
+        if (headers != null) {
+            builder.headers(headers.toOkhttpHeader());
+        }
+
+        this.attachAuthToRequest(builder);
+
+        return builder;
+    }
+
+    @SneakyThrows
     @Override
-    public RestResult post(String path, Object object,
-                           MultivaluedMap<String, Object> headers,
+    public RestResult post(String path, Object object, RestHeaders headers,
                            Map<String, Object> params) {
-        Pair<Builder, Entity<?>> pair = this.buildRequest(path, null, object,
-                                                          headers, params);
-        Response response = this.request(() -> {
-            // pair.getLeft() is builder, pair.getRight() is entity (http body)
-            return pair.getLeft().post(pair.getRight());
-        });
-        // If check status failed, throw client exception.
-        checkStatus(response, Response.Status.CREATED,
-                    Response.Status.OK, Response.Status.ACCEPTED);
-        return new RestResult(response);
+        Request.Builder requestBuilder = getRequestBuilder(path, null, 
headers, params);
+        requestBuilder.post(buildRequestBody(object, headers));
+
+        try (Response response = this.request(
+                () -> client.newCall(requestBuilder.build()).execute())) {

Review Comment:
   seems this is for the RestClientTest to mock the request action



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to