Java 将Neo4j与Jersey 2.x API一起使用

Java 将Neo4j与Jersey 2.x API一起使用,java,jersey,neo4j,jersey-2.0,Java,Jersey,Neo4j,Jersey 2.0,我试图将Neo4j服务器与jersey 2 API一起使用,但在将Neo4j中的示例从jersey 1.x重写为2.x时遇到了困难。例如,第一个例子是: WebResource resource = Client.create().resource( SERVER_ROOT_URI ); ClientResponse response = resource.get( ClientResponse.class ); System.out.println( String.format( "GET o

我试图将Neo4j服务器与jersey 2 API一起使用,但在将Neo4j中的示例从jersey 1.x重写为2.x时遇到了困难。例如,第一个例子是:

WebResource resource = Client.create().resource( SERVER_ROOT_URI );
ClientResponse response = resource.get( ClientResponse.class );
System.out.println( String.format( "GET on [%s], status code [%d]",SERVER_ROOT_URI, response.getStatus() ) );
response.close();
可重写为:

String baseURI = new String("http://localhost:7474/");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(baseURI);
Invocation.Builder invocationBuilder = target.request(MediaType.TEXT_PLAIN_TYPE);
Response response = invocationBuilder.get();
但当我试图重写第二个示例时,我陷入了困境:

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 );
这应该类似于:

String baseURI = new String("http://localhost:7474/");
Client client = ClientBuilder.newClient();
WebTarget target = client.target(baseURI).path(newnode);
Response response = target.request(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity("{}", MediaType.APPLICATION_JSON_TYPE));
System.out.println(postResponse.getStatus());
但这将返回HTTP404。应该如何构造请求>

我自己已经回答了这个问题:代码片段应该是:

String baseURI = new String("http://localhost:7474/"); 
Client client2 = ClientBuilder.newClient();
WebTarget target2 = client2.target(baseURI + "db/data/node");
System.out.println(target2.getUri());
Response postResponse = target2.request().accept(MediaType.APPLICATION_JSON_TYPE).post(Entity.entity(JSON , MediaType.APPLICATION_JSON_TYPE));
    System.out.println(postResponse.getStatus() + "     " + postResponse.getLocation());
    postResponse.close();

在1.x示例中,您将
/db/data/
路径包含在根uri中,但在2.x代码中,您没有(至少在第一个示例中没有)。你是不是无意中发到了
localhost:7474/node
?我两个都试过了,两个都没试过。我不确定哪一个是正确的,但我认为问题在于回复/发帖栏。请将您的答案作为答案发布。你也可以通过解释问题是什么以及你改变了什么来解决它来改进你的答案。