简体   繁体   English

作为API运行Neo4j遍历JAR

[英]Run a Neo4j traversal JAR as an API

I've coded a traversal in Java (using Eclipse IDE). 我已经用Java(使用Eclipse IDE)对遍历进行了编码。 The main() program accepts input arguments (classic args[]), it calls the traversal using one of them as the start node, the other args are used to perform some data filtering on traversal results. main()程序接受输入参数(经典的args []),它使用其中一个作为起始节点来调用遍历,其他args用于对遍历结果执行一些数据过滤。 Thus, I can run this JAR on a command line with corresponding arguments. 因此,我可以在带有相应参数的命令行上运行此JAR。

Question: how can quickly test this JAR as a RESTful API? 问题: 如何快速将此JAR作为RESTful API测试? eg sending HTTP GET with its parameters as input arguments ? 例如发送HTTP GET及其参数作为输入参数? what is best practice ? 什么是最佳做法?

Thank you 谢谢

The best way is to create an unmanaged extension which will accept query parameters that will call your traversal 最好的方法是创建一个非托管扩展 ,该扩展将接受将调用遍历的查询参数

Example from the doc : doc中的示例:

@Path( "/helloworld" )
public class HelloWorldResource
{
    private final GraphDatabaseService database;

    public HelloWorldResource( @Context GraphDatabaseService database )
    {
        this.database = database;
    }

    @GET
    @Produces( MediaType.TEXT_PLAIN )
    @Path( "/{nodeId}" )
    public Response hello( @PathParam( "nodeId" ) long nodeId )
    {
        // Do stuff with the database
        return Response.status( Status.OK ).entity(
                ("Hello World, nodeId=" + nodeId).getBytes( Charset.forName("UTF-8") ) ).build();
    }
}

You can find a test example here : https://github.com/neo4j/neo4j/blob/2.2.1/community/server-examples/src/test/java/org/neo4j/examples/server/unmanaged/UnmanagedExtensionsDocIT.java 您可以在这里找到测试示例: https : //github.com/neo4j/neo4j/blob/2.2.1/community/server-examples/src/test/java/org/neo4j/examples/server/unmanaged/UnmanagedExtensionsDocIT。 java的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM