New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] There is no demo of how creating a graph through GraphAPI in test module and I had try client.post() failed. #2530
Comments
嗨,@BreakMeEveryday!看来我们又在这里相遇了,希望这次我能帮到你。我正在查看你的问题,很快会给你一个完整的答复。 |
我跑get的方法是对的,所以client这边应该没有问题,是因为我没有配置请求头吗,还是说这里不要用RestClient去请求,而是用普通的http工具?比如hutool下的一些Http工具类去发送请求? @dosu-bot , 请问动态创建图的 API 在 java-client 或者 HTTP 请求中应该如何构造, 另外请给出动态创建图的 API 代码引用以及相关的测试代码例子 |
To address the issue with the
This method checks the API version for compatibility and uses the By following these steps and utilizing the provided API method, you should be able to dynamically create graphs in HugeGraph without encountering the
|
@dosu Sorry, your answer is not working and there is no 4 parameters overload method with client.post(). This is my solution and it works. /**
* 该Test方法成功,url可以替换成你自己的路径,我只是用了常量定义,HttpUtil使用的是hutool 5.8.27包,这个也可以自定义替换
* */
@Test
public void createGraphUsingHttpUtil(){
String url = ConstTransferPath.BASE_URL.getPath()
+ConstTransferPath.GRAPHS.getPath()
+"hugegraph2";
String configInfo = "gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy\n" +
"backend=rocksdb\n" +
"serializer=binary\n" +
"store=hugegraph2\n" +
"rocksdb.data_path=./rks-data-2\n" +
"rocksdb.wal_path=./rks-data-2";
try{
String response = HttpUtil.createPost(url)
.header("Content-Type", "text/plain") //Attention Please! The content-type is text/plain.
.body(configInfo)
.execute()
.body();
System.out.println(JSONUtil.toJsonPrettyStr(response));
}catch (Exception e){
log.error(e.getMessage());
}
} |
Thank you for sharing your solution. It's great to see you've found a way to dynamically create a graph using HttpUtil from the hutool library. Your approach, which involves setting the For others who might be following this discussion, the key takeaway from @BreakMeEveryday's solution is the importance of correctly setting the If there are any further questions or if anyone needs additional clarification on working with the HugeGraph API, feel free to ask.
|
@BreakMeEveryday indeed there are actually 2 problems:
BTW, u could try to use docker version to avoid some environmental impacts and run tests quickly @dosu u need tell users to move/check the toolchain repo for client related issues (they may miss the context if u don't remind them) |
@imbajin @dosu A bad news, I'm failed and here is my result. I had run the test method @Test
public void testCreateAndDropGraph() {
int initialGraphNumber = graphsAPI.list().size();
// Create new graph dynamically
String config;
try {
config = FileUtils.readFileToString(new File(CONFIG2_PATH),
StandardCharsets.UTF_8);
} catch (IOException e) {
throw new ClientException("Failed to read config file: %s",
CONFIG2_PATH);
}
Map<String, String> result = graphsAPI.create(GRAPH2, null, config);
...
} But a same exception as before occured. And here is the stack of exceptions of server java.lang.IllegalStateException: Missing authentication context when verifying resource permission
at com.google.common.base.Preconditions.checkState(Preconditions.java:532) ~[guava-30.0-jre.jar:?]
at org.apache.hugegraph.util.E.checkState(E.java:64) ~[hugegraph-common-1.3.0.jar:1.3.0]
at org.apache.hugegraph.auth.HugeGraphAuthProxy.verifyResPermission(HugeGraphAuthProxy.java:964) ~[classes/:?]
at org.apache.hugegraph.auth.HugeGraphAuthProxy.verifyResPermission(HugeGraphAuthProxy.java:955) ~[classes/:?]
at org.apache.hugegraph.auth.HugeGraphAuthProxy.verifyPermission(HugeGraphAuthProxy.java:828) ~[classes/:?]
at org.apache.hugegraph.auth.HugeGraphAuthProxy.create(HugeGraphAuthProxy.java:781) ~[classes/:?]
at org.apache.hugegraph.core.GraphManager.createGraph(GraphManager.java:591) ~[classes/:?]
at org.apache.hugegraph.core.GraphManager.createGraph(GraphManager.java:188) ~[classes/:?]
at org.apache.hugegraph.api.profile.GraphsAPI.create(GraphsAPI.java:136) ~[classes/:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:566) ~[?:?]
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:124) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:167) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ObjectOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:192) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:79) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:475) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:397) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:255) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248) ~[jersey-common-3.0.3.jar:?]
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244) ~[jersey-common-3.0.3.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:292) ~[jersey-common-3.0.3.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:274) ~[jersey-common-3.0.3.jar:?]
at org.glassfish.jersey.internal.Errors.process(Errors.java:244) ~[jersey-common-3.0.3.jar:?]
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265) ~[jersey-common-3.0.3.jar:?]
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:234) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684) ~[jersey-server-3.0.3.jar:?]
at org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpContainer.service(GrizzlyHttpContainer.java:356) ~[jersey-container-grizzly2-http-3.0.3.jar:?]
at org.glassfish.grizzly.http.server.HttpHandler$1.run(HttpHandler.java:190) ~[grizzly-http-server-3.0.1.jar:3.0.1]
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:535) ~[grizzly-framework-3.0.1.jar:3.0.1]
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:515) ~[grizzly-framework-3.0.1.jar:3.0.1]
at java.lang.Thread.run(Thread.java:829) [?:?] U know, I did nothing to the public class BaseClientTest {
protected static final String BASE_URL = "http://192.168.10.70:8080";
protected static final String GRAPH = "hugegraph";
protected static final String USERNAME = "admin";
protected static final String PASSWORD = "pa";
...
} |
The issue you're encountering, indicated by the To address this, ensure your client is authenticated before making any API requests, especially if your HugeGraph server requires authentication. Here's a concise way to authenticate using token-based authentication, which is recommended for security:
Here's a simplified example: import org.apache.hugegraph.client.RestClient;
import org.apache.hugegraph.structure.auth.Login;
import org.apache.hugegraph.structure.auth.LoginResult;
import org.apache.hugegraph.api.auth.LoginAPI;
import org.apache.hugegraph.api.auth.TokenAPI;
public class YourTestClass {
private static String BASE_URL = "http://your_hugegraph_server.com";
private static String GRAPH = "your_graph_name";
private static RestClient client;
public static void init() {
client = RestClient.builder(BASE_URL).build();
LoginAPI loginAPI = new LoginAPI(client, GRAPH);
Login login = new Login().name("admin").password("pa");
LoginResult result = loginAPI.login(login);
client.setAuthContext("Bearer " + result.token());
}
public static void main(String[] args) {
init();
// Your client is now authenticated and ready for API calls
}
} Make sure to replace This setup should resolve the authentication issue. If the problem persists, it might be beneficial to check your HugeGraph server's authentication configuration, particularly the
|
@BreakMeEveryday some suggestions:
|
Given the error message "Missing authentication context when verifying resource permission," it seems the issue is related to authentication. Here are steps to potentially resolve this:
Remember, changing server configurations, especially those related to security like authentication, should be done cautiously and ideally in a testing environment before applying changes to production.
|
Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label |
Problem Type (问题类型)
rest-api (结果不合预期)
Before submit
Environment (环境信息)
Your Question (问题描述)
I had tried the client.post() method failed.
Vertex/Edge example (问题点 / 边数据举例)
No response
Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)
No response
The text was updated successfully, but these errors were encountered: