【问题标题】:Jersey client examples in Neo4j ManualNeo4j 手册中的 Jersey 客户端示例
【发布时间】:2016-04-16 08:07:59
【问题描述】:

我想使用 Jersey 客户端通过 REST 连接 Neo4j 数据库。在 Neo4j 手册中,他们在 Tutorials->Languages->How to use the REST API from Java 中有这方面的示例。我想创建一个新节点,然后使用 Cypher 向它添加关系。在 Neo4j 示例 (https://github.com/neo4j/neo4j/blob/2.2.9/community/server-examples/src/main/java/org/neo4j/examples/server/CreateSimpleGraph.java) 中,他们使用“createNode”,但文档表明这只能使用嵌入式 Neo4j 服务器。

在 RESTful 上下文中调用 createNode() 是否有效?

【问题讨论】:

  • 如果这个问题太无知或太愚蠢,我很抱歉。但我真的不知道答案。至少有人会指出我可能会找到答案的手册部分吗?谢谢

标签: java neo4j jersey-client


【解决方案1】:

在您引用的示例中,定义为 herecreateNode 函数只是向 http://localhost:7474/db/data/node 发出 HTTP POST 请求,这将创建一个新节点:

private static URI createNode()
{
    final String nodeEntryPointUri = SERVER_ROOT_URI + "node";
    // http://localhost:7474/db/data/node

    WebResource resource = Client.create()
            .resource( nodeEntryPointUri );
    // POST {} to the node entry point URI
    ClientResponse response = resource.accept( MediaType.APPLICATION_JSON )
            .type( MediaType.APPLICATION_JSON )
            .entity( "{}" )
            .post( ClientResponse.class );

    final URI location = response.getLocation();
    System.out.println( String.format(
            "POST to [%s], status code [%d], location header [%s]",
            nodeEntryPointUri, response.getStatus(), location.toString() ) );
    response.close();

    return location;
}

该函数在示例代码中定义,与createNode function that is part of the embedded Java API完全不同。

如果您有兴趣使用新的 Neo4j 3.0 版本(当前为 RC),有一个支持 Cypher here 的新 Java 驱动程序。

【讨论】:

  • 谢谢威廉。感谢您的澄清。
猜你喜欢
  • 2014-12-24
  • 1970-01-01
  • 2011-08-20
  • 1970-01-01
  • 2016-10-26
  • 2017-07-17
  • 1970-01-01
  • 1970-01-01
  • 2011-01-09
相关资源
最近更新 更多