我正在使用Scala(2.9.2)中的一些代码来通过Jersey(1.19)和Cypher使用REST API查询neo4j(2.2.0)服务器。我的第一个事务成功(HTTP 200)返回一些不错的XHTML。包含有效Cypher查询的第二个更复杂的事务返回405,没有数据或消息。它会导致服务器日志中的堆栈转储。同一查询通过控制台成功到同一服务器。我不知道如何进行诊断问题。详情如下:
以下是Cypher控制台的交易和结果:
neo4j-sh (?)$ match (p)-[r]->(n) where n.number = '15' return p,r,n;
+------------------------------------------------------------------------------------------------------------+
| p | r | n |
+------------------------------------------------------------------------------------------------------------+
| Node[1451]{name:"Elizabeth Maher Muoio"} | :REPRESENTS[1725]{inHouse:"Assembly"} | Node[1381]{number:"15"} |
| Node[1450]{name:"Reed Gusciora"} | :REPRESENTS[1724]{inHouse:"Assembly"} | Node[1381]{number:"15"} |
| Node[1449]{name:"Shirley K. Turner"} | :REPRESENTS[1723]{inHouse:"Senate"} | Node[1381]{number:"15"} |
+------------------------------------------------------------------------------------------------------------+
3 rows
24 ms
以下是Scala代码段:
val n4url = "http://dev.cosi.com:7474/db/data/"
// Make a client...
val c = Client.create // Uses jersey 1.19
//val cl = c.getClass.getName; println("cl: "+cl);
c.addFilter(new HTTPBasicAuthFilter("neo4j","connected"))
// Dumb test of comms w server...
val resource = c.resource(n4url)
val response = resource.get(classOf[ClientResponse])
printf("\nGET on [%s], status code [%d]\n%s\n",n4url,response.getStatus(),
response.getEntity(classOf[String]))
response.close
println("\n=== MOVING ALONG TO REAL INQUIRY ===")
val inq = n4url+"transaction/commit"
val res2 = c.resource(inq)
val query = "match (p)-[r]->(n) where n.number = '15' return p,r,n"
val payload = "{\"statements\" : [ {\"statement\" : \"" + query + "\"} ]}";
val resp2 = resource.
accept(MediaType.APPLICATION_JSON).
`type`(MediaType.APPLICATION_JSON).
entity(payload).
post(classOf[ClientResponse])
printf("POST [%s] to [%s], status code [%d], returned data: " +
System.getProperty("line.separator") + "%s\n",
payload,inq,resp2.getStatus,resp2.getEntity(classOf[String]))
resp2.close
这是Scala程序的输出:
GET on [http://dev.cosi.com:7474/db/data/], status code [200]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>Root</title><meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<link href='http://resthtml.neo4j.org/style/rest.css' rel='stylesheet' type='text/css'>
<script type='text/javascript' src='/webadmin/htmlbrowse.js'></script>
</head>
<body onload='javascript:neo4jHtmlBrowse.start();' id='root'>
<div id='content'><div id='header'><h1><a title='Neo4j REST interface' href='/'><span>Neo4j REST interface</span></a></h1></div>
<div id='page-body'>
<table class="root"><caption>Root</caption>
<tr class='odd'><th>relationship_index</th><td><a href="http://dev.cosi.com:7474/db/data/index/relationship">http://dev.cosi.com:7474/db/data/index/relationship</a></td></tr>
<tr><th>node_index</th><td><a href="http://dev.cosi.com:7474/db/data/index/node">http://dev.cosi.com:7474/db/data/index/node</a></td></tr>
</table>
<div class='break'> </div></div></div></body></html>
=== MOVING ALONG TO REAL INQUIRY ===
POST [{"statements" : [ {"statement" : "match (p)-[r]->(n) where n.number = '15' return p,r,n"} ]}] to [http://dev.cosi.com:7474/db/data/transaction/commit], status code [405], returned data:
这是服务器日志片段:
FINE: Mapped exception to response: 405
javax.ws.rs.WebApplicationException
at com.sun.jersey.server.impl.uri.rules.TerminatingRule.accept(TerminatingRule.java:66)
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:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
at org.neo4j.server.rest.dbms.AuthorizationFilter.doFilter(AuthorizationFilter.java:120)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
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:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
at java.lang.Thread.run(Thread.java:745)
答案 0 :(得分:1)
我在第二次查询中引用了错误的ClientResponse对象。通过更改修复:
val resp2 = resource.
到
val resp2 = res2.