[英]open REST cypher transaction
Trying to write a script to open a transaction in groovy. 尝试编写脚本以常规方式打开事务。 Currently have:
目前拥有:
def static transaction(statement, params,success, error)
{
def http = new HTTPBuilder( 'http://localhost:7474' )
http.request( POST, JSON ) {
uri.path = '/db/data/transaction'
headers.'X-Stream' = 'true'
requestContentType = JSON
body = [ statements : statement , params : params ?: [:] ]
// uri.query = [ param : 'value' ]
response.success = { resp, json ->
if (success) success(json)
else {
println "Status ${resp.statusLine} Columns ${json.columns}\nData: ${json.data}"
}
}
response.failure = { resp, message ->
def result=[status:resp.statusLine.statusCode,statusText:resp.statusLine.reasonPhrase]
result.headers = resp.headers.collect { h -> [ (h.name) : h.value ] }
result.message = message
if (error) {
error(result)
} else {
println "Status: ${result.status} : ${result.statusText} "
println 'Headers: ${result.headers}'
println 'Message: ${result.message}'
}
}
}
}
transaction("start n=node(*) return n",[id:56981],{ println "Success: ${it}" },{ println "Error: ${it}" })
However I am getting the following error in the response: 但是我在响应中收到以下错误:
Success: [commit:http://localhost:7474/db/data/transaction/4/commit, results:[], errors:[[code:40001, status:INVALID_REQUEST_FORMAT, message:Unable to deserialize request. Expected [START_OBJECT, FIELD_NAME, START_ARRAY], found [START_OBJECT, FIELD_NAME, VALUE_STRING].]]]
Thoughts? 思考? Thanks!
谢谢!
Please check out https://gist.github.com/7053223 . 请查看https://gist.github.com/7053223 。 Basically you did not build the json structure correctly.
基本上,您没有正确构建json结构。 According to http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html a json map containing
statements
key is sent. 根据http://docs.neo4j.org/chunked/milestone/rest-api-transactional.html发送包含
statements
键的json映射。 Inside there's an array of maps containing a statement
and parameters
key. 里面有一组包含
statement
和parameters
键的映射。 Compare l.15 vs l.16-18 to see the difference. 比较l.15与l.16-18可以看到不同之处。
Faced same problem with php, statements
must contain array of statement
: 面对php同样的问题,
statements
必须包含statement
数组:
[
statements => [
statemant
],
resultDataContents => [
'row',
'graph',
],
'includeStats' => true,
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.