简体   繁体   English

非托管扩展neo4j上的密码查询

[英]cypher query on unmanaged extension neo4j

i have an unmanaged extension for my neo4j server. 我的neo4j服务器有一个不受管的扩展。

and the code like the following. 和如下代码。

@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) {
        String res = ""; 

        try ( Transaction ignored = database.beginTx();)
        {
            //@@problem
            Result result = database.execute( "MATCH (n:KISI) where id(n)=1 return n" );

        } catch (Exception e) {
            res = "Error = " + e.getMessage();
        }

        return Response
            .status(Status.OK)
            .entity(("nodeId =" + nodeId + " " + res).getBytes(Charset
                    .forName("UTF-8"))).build();
    }
}

When i deploy the code i got 500 internal error. 当我部署代码时,我得到了500个内部错误。 if i remove the code 如果我删除代码

Result result = database.execute( "MATCH (n:KISI) where id(n)=1 return n" ); 结果结果= database.execute(“ MATCH(n:KISI)其中id(n)= 1返回n”);

then everything is fine. 那一切都很好

i checked the log file and the error is the following 我检查了日志文件,错误如下

Aug 13, 2015 3:34:36 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container java.lang.NoSuchMethodError: org.neo4j.graphdb.GraphDatabaseService.execute(Ljava/lang/String;)Lorg/neo4j/graphdb/Result; 2015年8月13日,上午3:34:36 com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException严重:无法将MappableContainerException中包含的异常映射到响应,然后重新抛出到HTTP容器java.lang.NoSuchMethodError: org.neo4j.graphdb.GraphDatabaseService.execute(Ljava /郎/字符串;)Lorg / Neo4j的/ graphdb /结果; at org.neo4j.examples.server.unmanaged.HelloWorldResource.hello(HelloWorldResource.java:55) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) at com.sun.jersey.s 在org.neo4j.examples.server.unmanaged.HelloWorldResource.hello(HelloWorldResource.java:55)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) .reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at com.sun.jersey.spi.container.JavaMethodInvokerFactory $ 1.invoke(JavaMethodInvokerFactory.java:java.lang.reflect.Method.invoke(Method.java:606) 60)在com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher上的com.sun.jersey.server.impl.model.method.dispatch.Abs​​tractResourceMethodDispatchProvider $ ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)处。在org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)处com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule)调度(ResourceJavaMethodDispatcher.java:75)。 java:288)在com.sun.jersey.s erver.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.sun.jersey.spi.container.servle er.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)位于com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)位于com.sun.jersey。 com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)上的server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)在com.sun.jersey上。 com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)上的server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)。位于com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)上的application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)位于com.sun.jersey.spi.container.servlet.WebComponent处。 com.sun.jersey.spi.container.servle的service(WebComponent.java:416)com.sun.jersey.spi.container.servle的service(ServletContainer.java:537) t.ServletContainer.service(ServletContainer.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) at org.eclipse.jetty.server.Server.handle(Server.java:445) at org.eclipse. org上的org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)上的javax.servlet.http.HttpServlet.service(HttpServlet.java:848)上的t.ServletContainer.service(ServletContainer.java:699) org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211)上的.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:505)org.eclipse.jetty.server.handler.ContextHandler org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)的.doHandle(ContextHandler.java:1096)org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)的.doHandle(ContextHandler.java:1096) org.eclipse.jetty.server上的org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030)在org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)。 org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)处的handler.HandlerList.handle(HandlerList.java:52)org.eclipse.jetty.server.Server.handle(Server.java: 445),网址为org.eclipse。 jetty.server.HttpChannel.handle(HttpChannel.java:268) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532) at java.lang.Thread.run(Thread.java:745) org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)上的jetty.server.HttpChannel.handle(HttpChannel.java:268)org.eclipse.jetty.io.AbstractConnection $ ReadCallback.run(AbstractConnection。 java:358)在org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)在org.eclipse.jetty.util.thread.QueuedThreadPool $ 3.run(QueuedThreadPool.java:532)在java。 lang.Thread.run(Thread.java:745)

so whats wrong with my code? 那我的代码怎么了?

I guess that your Neo4j distribution version and maven dependency version in pom.xml are not same. 我猜您pom.xml中的Neo4j发行版本和maven依赖版本不相同。

But there are several things to check: 但是有几件事要检查:

1) You should always close Result object. 1)您应始终关闭Result对象。 Example: 例:

try(Result result = database.execute( "MATCH (n:KISI) where id(n)=1 return n" )) {
    // do stuff here
}

``` ```

2) Exception occurs not in try-catch but later. 2)异常不是在try-catch发生的,而是以后发生的。 You should change your code to this: 您应该将代码更改为此:

try ( Transaction tx = database.beginTx()) {
    String query = "MATCH (n:KISI) where id(n)=1 return n";
    // use result with try-with-resource to ensure that it will be closed
    try(Result result = database.execute(query)) {
        // do stuff you need with result here
        return Response.ok("nodeId =" + nodeId).build();
    }

    tx.success(); // mark transaction as successful 
} catch (Exception e) {
    // If exception occurs - send exception message with 500 status code
    // It's good idea to write Exception stacktrace to log there
    return Response.serverError().entity(e.getMessage()).build()      
}

3) You should check how unmanaged extension .jar file is build. 3)您应该检查非托管扩展.jar文件的构建方式。

  • All Neo4j dependencies should be provided in pom.xml (there are already there in Neo4j distribution). 所有Neo4j依赖项都应在pom.xml中provided (Neo4j发行版中已经存在)。
  • Check that your database version and your dependency version in pom.xml are same. 检查pom.xml中的数据库版本和依赖版本是否相同。 GraphDatabaseService::execute method is invented recently (2.2.3 if I remember correctly). GraphDatabaseService::execute方法是最近发明的(如果我没记错的话,请GraphDatabaseService::execute 2.2.3)。 Probably your database distribution is older than your maven dependencies. 可能您的数据库发行版比您的Maven依赖项还旧。

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

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