diff --git a/hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java b/hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java index 25462c704..f17a9ae82 100644 --- a/hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java +++ b/hugegraph-client/src/main/java/org/apache/hugegraph/client/RestClient.java @@ -17,10 +17,13 @@ package org.apache.hugegraph.client; +import java.util.Map; + import org.apache.hugegraph.exception.ServerException; import org.apache.hugegraph.rest.AbstractRestClient; import org.apache.hugegraph.rest.ClientException; import org.apache.hugegraph.rest.RestClientConfig; +import org.apache.hugegraph.rest.RestHeaders; import org.apache.hugegraph.rest.RestResult; import org.apache.hugegraph.serializer.PathDeserializer; import org.apache.hugegraph.structure.graph.Path; @@ -34,7 +37,7 @@ public class RestClient extends AbstractRestClient { private static final int SECOND = 1000; - private Version apiVersion = null; + private static boolean filter = false; static { SimpleModule module = new SimpleModule(); @@ -42,6 +45,8 @@ public class RestClient extends AbstractRestClient { RestResult.registerModule(module); } + private Version apiVersion = null; + public RestClient(String url, String username, String password, int timeout) { super(url, username, password, timeout * SECOND); } @@ -58,6 +63,11 @@ public RestClient(String url, RestClientConfig config) { super(url, config); } + private static String removeDefaultGsPrefix(String path) { + final String DEFAULT_GS_PATH_PREFIX = "graphspaces/DEFAULT/"; + return path.replaceFirst(DEFAULT_GS_PATH_PREFIX, ""); + } + public void apiVersion(Version version) { E.checkNotNull(version, "api version"); this.apiVersion = version; @@ -80,9 +90,64 @@ public boolean apiVersionLt(String minVersion) { return apiVersion != null && !VersionUtil.gte(apiVersion, minVersion); } + @Override + public RestResult post(String path, Object object) { + return super.post(filter ? path : removeDefaultGsPrefix(path), object); + } + + @Override + public RestResult get(String path, String id) { + return super.get(filter ? path : removeDefaultGsPrefix(path), id); + } + + @Override + public RestResult delete(String path, Map params) { + return super.delete(filter ? path : removeDefaultGsPrefix(path), params); + } + + @Override + public RestResult delete(String path, String id) { + return super.delete(filter ? path : removeDefaultGsPrefix(path), id); + } + + @Override + public RestResult post(String path, Object object, RestHeaders headers) { + return super.post(filter ? path : removeDefaultGsPrefix(path), object, headers, null); + } + + @Override + public RestResult post(String path, Object object, Map params) { + return super.post(filter ? path : removeDefaultGsPrefix(path), object, null, params); + } + + @Override + public RestResult put(String path, String id, Object object) { + return super.put(filter ? path : removeDefaultGsPrefix(path), id, object, null, null); + } + + @Override + public RestResult put(String path, String id, Object object, RestHeaders headers) { + return super.put(filter ? path : removeDefaultGsPrefix(path), id, object, headers, null); + } + + @Override + public RestResult put(String path, String id, Object object, Map params) { + return super.put(filter ? path : removeDefaultGsPrefix(path), id, object, null, params); + } + + @Override + public RestResult get(String path) { + return super.get(filter ? path : removeDefaultGsPrefix(path)); + } + + @Override + public RestResult get(String path, Map params) { + return super.get(filter ? path : removeDefaultGsPrefix(path), params); + } + @Override protected void checkStatus(okhttp3.Response response, int... statuses) { - boolean match = false; + boolean match = filter; for (int status : statuses) { if (status == response.code()) { match = true;