404 error in using REST API in neo4j - json

Here I am trying to execute shortestPath algorithm in neo4j.
{
method: 'POST',
json:true,
url: 'http://neo4j:admin#localhost:7474/db/data/81/path',
body:{
"to" : '/db/data/84',
"max_depth" : 2,
"relationships" : {
"type" : "Meet",
"direction" : "out"
},
"algorithm" : "shortestPath"
}
},
Obtained response:
error: null
body:
{
"statusCode":404,
"headers":
{
"date":"Wed, 24 May 2017 05:10:51 GMT",
"access-control-allow-origin":"*",
"connection":"close",
"server":"Jetty(9.2.9.v20150224)"
},
"request":
{
"uri":
{
"protocol":"http:",
"slashes":true,
"auth":"neo4j:admin",
"host":"localhost:7474",
"port":"7474",
"hostname":"localhost",
"hash":null,
"search":null,
"query":null,
"pathname":"/db/data/81/path",
"path":"/db/data/81/path",
"href":"http://neo4j:admin#localhost:7474/db/data/81/path"
},
"method":"POST",
"headers":
{
"authorization":"Basic bmVvNGo6YWRtaW4=",
"accept":"application/json",
"content-type":"application/json",
"content-length":144
}
}
}
Please, can anyone help me out with this?

You are missing /node from your url and to paths.
Try this:
{
method: 'POST',
json:true,
url: 'http://neo4j:admin#localhost:7474/db/data/node/81/path',
body:{
"to" : '/node/84',
"max_depth" : 2,
"relationships" : {
"type" : "Meet",
"direction" : "out"
},
"algorithm" : "shortestPath"
}
}

Related

Wiremock response depending on request body parameter

I am sending Wiremock (Standalone, 2.21) a request with the body
{
"attribute1": "value1",
"attribute2": "value2",
...
"attributen": "valuen"
}
to the URL /test/test-url , no query parameters, with POST.
I would like it to do the following:
respond with "response1.json" when attribute1 equals "text1"
respond with "response2.json" when attribute1 equals "text2"
respond with "response_general.json" when attribute1 equals something else than "text1" or "text2"
The other attributes dont matter regarding the answer.
I would like to do this by only using .json files. Thank you!
The answer was to have check for body patterns and have 3 mappings for the 3 different cases:
One for the case when text1 is detected:
"request": {
"method": "POST",
"urlPattern":"/.*",
"bodyPatterns": [
{
"contains":"\"attribute1\": \"text1\""
}
]
},
"response": {
"status": 200,
"bodyFileName": "response_text1.json",
"headers": {
"Content-Type": "application/json"
}
}
One for the case when text2 is detected:
"request": {
"method": "POST",
"urlPattern":"/.*",
"bodyPatterns": [
{
"contains":"\"attribute1\": \"text2\""
}
]
},
"response": {
"status": 200,
"bodyFileName": "response_text2.json",
"headers": {
"Content-Type": "application/json"
}
}
One for the case when neither is detected. In this case a general answer is given back.
"request": {
"method": "POST",
"urlPattern": "/.*"
},
"response": {
"status": 200,
"bodyFileName": "response_general.json",
"headers": {
"Content-Type": "application/json"
}
}
In the more recent versions of WireMock (2.19+) there is support for HandleBars processing in the BodyFileName attribute. This then allows you to do put a (partial) name in the JSON request body and then reuse it's value for the filename reference.
{
"request" : {
"urlPathPattern" : "/jpathFile",
"method" : "GET",
"headers": {
"Content-Type": {
"equalTo": "application/json"
}
}
},
"response" : {
"status" : 200,
"headers": {
"Content-Type": "application/json"
},
"bodyFileName" : "/{{jsonPath request.body '$.attribute2'}}",
"transformers": ["response-template"]
}
}
Input message:
{
"attribute1": "value1",
"attribute2": "response.json",
"attributen": "valuen"
}
the response.json in the /__files/response.json location:
{
"hello": "World!"
}
Instead of using "contains" or "equalTo" i would suggest to use "matchesJsonPath"
"bodyPatterns": [
{
"matchesJsonPath": "$[?(#.attribute1 == 'value1')]"
}
]

Unable to parse expectation on mockserver-netty when adding Content-Type header

I have an integration test where I am using mockserver-netty (v5.3.0) with a springboot 2.0 application..everything is working fine but if I try to add the Content-Type header, I get the following exception:
java.lang.IllegalArgumentException: Exception while parsing [{
"httpRequest" : {
"method" : "POST",
"body" : {
"type" : "XML",
"xml" : "......"
},
"times" : {
"remainingTimes" : 0,
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
}
}] for Expectation
at org.mockserver.client.AbstractClient.sendRequest(AbstractClient.java:95)
at org.mockserver.client.AbstractClient.sendExpectation(AbstractClient.java:441)
at org.mockserver.client.ForwardChainExpectation.respond(ForwardChainExpectation.java:25)
The expectation is the following:
{
"method" : "POST",
"body" : {
"type" : "XML",
"xml" : "......"
}
},
"httpResponse" : {
"statusCode" : 200,
"headers" : {
"Content-Type" : [ "text/xml" ]
},
"body" : "......."
},
"times" : {
"remainingTimes" : 0,
"unlimited" : true
},
"timeToLive" : {
"unlimited" : true
}
}
I create it with the following code:
private static HttpResponse responseWithBody(String responseBody, int statusCode, String contentType) {
return HttpResponse.response()
.withStatusCode(statusCode)
.withHeader("Content-Type",contentType)
.withBody(responseBody);
}
If I just comment the line with the .withHeader("Content-Type",contentType) statement, everything runs fine. Any clue about that?
Thanks a lot
I got the same problem. Looks like it was caused by a bug in xml parser used underneath, see https://github.com/jamesdbloom/mockserver/issues/451
Upgrade to mockserver 5.4.1 and you'll be fine :)

DataTables warning: table id=data-table - Ajax error

I am getting table id=data-table error. I have even converted my text file to json file with parse command. Any ideas what is causing this. I have tried to search every where for this issue.
Please help.
My Text File
{
"Orders": [
{
"Address": "124, KAPADIA INDUSTRIAL",
"Dabba Type": "LUNCH AND DINNER",
"Email": "jamesbond#gmail.com",
"End date": "29/4/2017",
"Phone number": "9619582277",
"Session": "VEG",
"Start date": "15/3/2017",
"User id": "CaXXchcC3XhAifuk7P4YprzSGqB3",
"Username": "james bond"
},
...Still more data is there below
]
}
Script file
$(document).ready(function(){
$('#data-table').DataTable({
"ajax" : {
"dataType" : 'json',
"contentType" : "application/json; charset=utf-8",
"type" : "POST",
"url" : "data/mumbaidabbawala.txt",
"dataSrc" : function (json) {
return $.parseJSON(Orders);
}
},
"columns" : [
{ "Orders" : "Address"},
{ "Orders" : "Dabba Type"},
{ "Orders" : "Email"},
{ "Orders" : "End Date"},
{ "Orders" : "Phone number"},
{ "Orders" : "Session"},
{ "Orders" : "Start date"},
{ "Orders" : "User id"},
{ "Orders" : "Username"}
]
});
});

Cannot Transform Correctly with Elasticsearch Watcher {{ctx.payload.hits.hits}}

I have a watcher configuration as follows:
{
"trigger": {
"schedule": {
"interval": "5s"
}
},
"input" : {
"search" : {
"request" : {
"indices" : [ "my_index" ],
"types" : [ "my_type" ],
"body" : {
"query" : {
"match_all" : {}
}
}
}
}
},
"transform" : {
"script" : "return [ body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]"
},
"actions" : {
"hbase_webhook" : {
"webhook" : {
"method" : "POST",
"host" : "<some_ip>",
"port" : <some_port>,
"path": "/v0.1/_events",
"body" : "data: {{ctx.payload.body}}"
}
}
}
}
The data posted in the body is not a valid JSON: Something like:
{ 'data: ': { '{"_index":"my_index","_type":"my_type","_source":{"key":"val"}},"_id":"<some_id>","_score":1.0}': '' } }
I don't know how to parse this output as JSON.parse in Node.js won't correctly parse it anyway.
Never. Forget. Headers.
I was forgetting:
"headers" {
"Content-type": "application/json"
}
So it was impossible to parse with any tool.
Ran into this while creating an alert for an endpoint where we just wanted to send off the actual records that matched specific criteria. See sample below:
"actions": {
"my_webhook": {
"webhook": {
"scheme": "https",
"host": "webhook.site",
"port": 443,
"method": "post",
"path": "/webhooksiteguidwouldbehere",
"params": {},
"headers": {
"Content-type": "application/json"
},
"body": "{{#toJson}}ctx.payload.hits.hits{{/toJson}}"
}
}
}
Second Note:
If the body size is set to 0 your hits will be returned as null. :)

Matching data in JsonPath with wiremock

I'm trying to create mocks for my login procedure. I use POST method with a couple of fields and login object (with login, password, etc.)
For that I'm using JsonPath. Code below:
{
"request": {
"method": "POST",
"url": "/login",
"bodyPatterns" : [
{"matchesJsonPath" : "$.method"},
{"matchesJsonPath" : "$.params[?(#.clientVersion == "1")]"},
{"matchesJsonPath" : "$.params.login"},
{"matchesJsonPath" : "$.params.password"}
]
},
"response": {
"status": 200,
"bodyFileName": "login.json"
}
}
I'm checking the clientVersion because it's similar to the examples.
My problem is, that with te given POST JSON:
{
"method": "login",
"params": {
"clientVersion": "1",
"login": "test#test.com",
"password": "681819535da188b6ef2"
}
}
I receive 404.
However, when I change
{"matchesJsonPath" : "$.params[?(#.clientVersion == "1")]"},
to normal
{"matchesJsonPath" : "$.params.clientVersion"},
everything works just fine.
So - how to check inside wiremock, using matchesJsonPath if given field equals some value?
How to apply it to the root field like method in my case?
And while we're at it - I had similar problems with checking if the value is not null. I tried to apply regular expressions and such - no luck.
It's working in my case :
wiremock:
"request": {
"urlPathPattern": "/api/authins-portail-rs/authins/inscription/infosperso",
"bodyPatterns" : [
{"matchesJsonPath" : "$[?(#.nir == '123456789')]"},
{"matchesJsonPath" : "$[?(#.nomPatronyme == 'aubert')]"},
{"matchesJsonPath" : "$[?(#.prenoms == 'christian')]"},
{"matchesJsonPath" : "$[?(#.dateNaissance == '01/09/1952')]"}
],
"method": "POST"
}
Json:
{
"nir": "123456789",
"nomPatronyme": "aubert",
"prenoms": "christian",
"dateNaissance": "01/09/1952"
}
Following worked for me.
"matchesJsonPath" : "$.rootItem.itemA[0].item..[?(#.fieldName=='file')]"
Json :
{
"rootItem" : {
"itemA" : [
{
"item" : {
"fieldName" : "file",
"name" : "test"
}
}
]
}
}
Wiremock
{
"request" : {
"urlPattern" : "/testjsonpath",
"method" : "POST",
"bodyPatterns" : [ {
"matchesJsonPath" : "$.rootItem.itemA[0].item..[?(#.fieldName=='file')]"
} ]
},
"response" : {
"status" : 200,
"body" : "{\"result\": \"success\"}",
"headers" : {
"Content-Type" : "application/json"
}
}
}
Update Wiremock. It should work with newer versions >= 2.0.0-beta. Its JsonPath dependency was very outdated (GitHub #261).
Using the double dots operator is semantically not the same, as the filter will also match for elements with the same name deeper down the tree.
try with double dots operator (recursive)
$..params[?(#.clientVersion == "1")]