RESTHeart Error When Trying To Load CSV Data - mongodb

I try to load csv data by using:
given().
contentType("text/csv").
body("num,name,val\n1,dror,x\n2,amir,y").
when().
log ().
all ().
post("csv?db=restheart&coll=poi&id=0").
then().log().ifError()
I get status 400:
"message": "Content-Type request header must be 'text/csv'"
although the header seems right:
Content-Type=text/csv; charset=ISO-8859-1
full log following:
Request path: http://localhost:8080/csv?db=restheart&coll=poi&id=0
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Multiparts: <none>
Headers: Accept=*/*
Content-Type=text/csv; charset=ISO-8859-1
Cookies: <none>
Body:
num,name,val
1,dror,x
2,amir,y
HTTP/1.1 400 Bad Request
Content-Encoding: gzip
X-Powered-By: restheart.org
Auth-Token-Location: /tokens/admin
Authentication-Info: nextnonce="moqjKcH05wkNMTU4NTk1NDY2OTEwNe2jU1Xuay1TK5O7rrmyiDA=",qop="auth",rspauth="d31b66e99f7dbb1c339b17741f9380c5",cnonce="f1843d31ec429268",nc=00000001
Access-Control-Expose-Headers: Location, ETag, X-Powered-By, Auth-Token, Auth-Token-Valid-Until, Auth-Token-Location
Date: Fri, 03 Apr 2020 22:57:49 GMT
Auth-Token: 16p0go30vzwa3ju0h839zn4wfnipcy914g56b5t0xkjh9yotxa
Connection: keep-alive
Access-Control-Allow-Origin: *
Auth-Token-Valid-Until: 2020-04-03T23:12:49.109466Z
Access-Control-Allow-Credentials: true
Content-Type: application/json
Content-Length: 142
{
"http status code": 400,
"http status description": "Bad Request",
"message": "Content-Type request header must be 'text/csv'",
"_links": {
"self": {
"href": "/csv"
}
}
}
Any idea what is going wrong?

I checked the code of the CsvLoader service (that handles the request) and it checks Content-Type to be exactly text/csv, so I think the problem is with the additional charset substring ; charset=ISO-8859-1
Force the Content-Type header to be exactly just text-cvs.
I also fixed this bug (see commit 47fa0821). Fix will be included in upcoming v5.0 release.

Related

bluemix app push hangs after upload

command bx app push hangs after message "Done uploading" is shown.
I activated CF_TRACE env var, and the following request is made several times before failing with:
Error processing app files: Error uploading application.
Server error, status code: 502, error code: 0, message:
REQUEST: [2018-08-01T11:47:21-03:00]
GET /v2/jobs/5dc92acb-8573-422b-8a60-2e6b558dc26e HTTP/1.1
Host: api.ng.bluemix.net
Accept: application/json
Authorization: [PRIVATE DATA HIDDEN]
Connection: close
Content-Type: application/json
User-Agent: go-cli 6.32.0+0191c33d9.2017-09-26 / linux
RESPONSE: [2018-08-01T11:47:21-03:00]
HTTP/1.1 200 OK
Connection: close
Content-Length: 270
Cache-Control: max-age=0, no-cache, no-store
Content-Type: application/json;charset=utf-8
Date: Wed, 01 Aug 2018 14:47:21 GMT
Expires: Wed, 01 Aug 2018 14:47:21 GMT
Pragma: no-cache
Server: nginx
X-Backside-Transport: OK OK
X-Content-Type-Options: nosniff
X-Global-Transaction-Id: 2574851421
{
"metadata": {
"guid": "5dc92acb-8573-422b-8a60-2e6b558dc26e",
"created_at": "2018-08-01T14:36:25Z",
"url": "/v2/jobs/5dc92acb-8573-422b-8a60-2e6b558dc26e"
},
"entity": {
"guid": "5dc92acb-8573-422b-8a60-2e6b558dc26e",
"status": "queued"
}
}
I noticed the status queued on the entity object. What that means ? What can I do?
EDIT:
There was a problem with the region my app was on. It was reported at: https://console.bluemix.net/status

Load performance testing with Gatling and Content-Type

I am using gatling for load performance testing on a brand new API. It seems fairly easy and well documented but I am facing an issue as simple as POST a request with Content-Type set to 'application/vnd.api+json' on the Header. All works well when doing the GET stuff but when launching a POST test I get a
HTTP response:
status=
415 Unsupported Media Type
headers=
cache-control: [no-cache]
Content-Type: [application/vnd.api+json; charset=utf-8]
Date: [Fri, 08 Sep 2017 12:57:10 GMT]
Server: [nginx]
Vary: [Origin]
x-content-type-options: [nosniff]
x-frame-options: [SAMEORIGIN]
X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9]
x-runtime: [0.040662]
x-xss-protection: [1; mode=block]
Content-Length: [218]
Connection: [keep-alive]
body=
{"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]}
Here is the scala code I am using for the http request:
object PostTokenGcm {
val token = exec {
http("TestAPI POST /tokens")
.post("/tokens")
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
.body(StringBody(gcmTokenRequestBody)).asJSON
.check(status.is(201))
.check(bodyString.exists)
}}
It seems that it is not setting the Content-Type?
Thank you for any lead!
In your POST definition you're using asJSON. According to notes in documentation about request headers:
http("foo").get("bar").asJSON is equivalent to:
http("foo").get("bar")
.header(HttpHeaderNames.ContentType, HttpHeaderValues.ApplicationJson)
.header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
... so, headers set in:
.headers(Map("Authorization" -> testApiToken,
"Content-Type" -> "application/vnd.api+json",
"Accept" -> "application/vnd.api+json" ))
... get overwritten by asJSON to "application/json" (which is the value of HttpHeaderValues.ApplicationJson).

Wolkenkit REST API for sending commands returns "Malformed command"

I am trying to use the REST API of Wolkenkit to send a command. I did not find any information in the docs, so i tried to find what is necessary by going through the source code and unit tests.
I am using HTTPie to do requests from the cli:
> http --verbose post https://local.wolkenkit.io:3500/v1/command id=12bf5b37-e0b8-42e0-8dcf-dc8c4aefc000 context:='{"name": "mycontext"}' aggregate:='{"name": "label", "id": "26c01e1f-abb8-42fa-82cf-60ca4a6bfbfa"}' name=create data:='{"label": "third"}' custom:='{}' metadata:='{"timestamp": "1504167240279", "correlationId": "12bf5b37-e0b8-42e0-8dcf-dc8c4aefc000", "causationId": "12bf5b37-e0b8-42e0-8dcf-dc8c4aefc000"}'
POST /v1/command HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 405
Content-Type: application/json
Host: local.wolkenkit.io:3500
User-Agent: HTTPie/0.9.9
{
"aggregate": {
"id": "26c01e1f-abb8-42fa-82cf-60ca4a6bfbfa",
"name": "label"
},
"context": {
"name": "mycontext"
},
"custom": {},
"data": {
"label": "third"
},
"id": "12bf5b37-e0b8-42e0-8dcf-dc8c4aefc000",
"metadata": {
"causationId": "12bf5b37-e0b8-42e0-8dcf-dc8c4aefc000",
"correlationId": "12bf5b37-e0b8-42e0-8dcf-dc8c4aefc000",
"timestamp": "1504167240279"
},
"name": "create"
}
HTTP/1.1 400 Bad Request
Access-Control-Allow-Origin: *
Cache-Control: no-store, no-cache, must-revalidate, proxy-revalidate
Connection: keep-alive
Content-Length: 18
Content-Type: text/html; charset=utf-8
Date: Wed, 30 Aug 2017 20:57:27 GMT
ETag: W/"12-2BIyYXjsDfNWq9+GqVAfSCeA8D4"
Expires: 0
Pragma: no-cache
Surrogate-Control: no-store
X-FRAME-OPTIONS: DENY
X-Powered-By: Express
X-XSS-Protection: 1; mode=block
Malformed command.
I used wolkenkit console to verify that the aggregate.id is correct. The command.id is just a random uuid().
What did i wrong to get Malformed command as response?
Disclaimer: I am one of the developers of wolkenkit.
Internally, the commands are built using the commands-events module, which also is being used for verifying incoming commands.
The actual error comes from tailwind which wolkenkit uses under the hood as base for an application that uses commands and events. Internally, this code calls the isWellformed function of commands-events, which in turn checks the schema of the command.
From what I see everything seems to be fine, except that metadata.timestamp should be a number, not a string. I think that if you change this, then wolkenkit will accept your command happily.

Unexpected character in payload

My Citrus test sends a (travel)request to some REST API. The response is handled as follows:
http()
.client("http://localhost:18082/cases")
.send()
.post()
.accept("application/json; charset=UTF-8")
.contentType("application/json")
//.payload(new ClassPathResource("templates/travelrequest.json"));
.payload(
"{ "+
"\"definition\": \"travelrequest.xml\", "+
"\"name\": \"travelrequest\" "+
"} "
);
Although response code 500 is received, this is what I expect. In Wireshark I captured the following package:
Host: localhost:18082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate
{ "definition": "travelrequest.xml", "name": "travelrequest" } HTTP/1.1 500 Internal Server Error
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:33:37 GMT
When I move the payload to a template, the receive part of my test now looks like this:
http()
.client("http://localhost:18082/cases")
.send()
.post()
.accept("application/json; charset=UTF-8")
.contentType("application/json")
.payload(new ClassPathResource("templates/travelrequest.json"));
//.payload(
// "{ "+
// "\"definition\": \"travelrequest.xml\", "+
// "\"name\": \"travelrequest\" "+
// "} "
//);
The template resource contains this text:
{
"definition": "travelrequest.xml",
"name": "travelrequest"
}
When I run this test, I receive a different response code: 400. In Wireshark I captured the following package:
Host: localhost:18082
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_121)
Accept-Encoding: gzip,deflate
?{
"definition": "travelrequest.xml",
"name": "travelrequest"
}HTTP/1.1 400 Bad Request
Server: spray-can/1.3.3
Date: Thu, 13 Apr 2017 15:36:15 GMT
Do notice that the request starts with an unexpected questionmark. This questionmark is not visible in the Citrus output:
17:36:13,629 DEBUG client.HttpClient| Sending HTTP message to: 'http://localhost:18082/cases'
17:36:13,629 DEBUG client.HttpClient| Message to send:
{
"definition": "travelrequest.xml",
"name": "travelrequest"
}
17:36:13,630 DEBUG ingClientInterceptor| Sending Http request message
Do notice the space directly before the opening bracket.
Is this some special character? Why is it added to the payload? Is there a logical explanation?
Cheers,
Ed
Seems to be an encoding issue. Citrus by default uses UTF-8 encoding when reading the file content. Maybe the file uses some other encoding and the first character is the result of this difference.
Please check the file encoding. You can tell Citrus to use some other encoding by setting the System property
citrus.file.encoding=UTF-8
You can also add this property to the citrus-application.properties file as described here: http://www.citrusframework.org/reference/html/configuration.html#citrus-application-properties

Failed to parse SDKResponse from http_response

I implemented a webhook to conform to the Actions on Google Conversation Protocol. However, when I simulate an interaction through the Web Simulator, I get the following error:
{
"response": “action name isn’t responding right now. Try again soon.\n",
"audioResponse": "...",
"debugInfo": {
"sharedDebugInfo": [
{
"name": "ExecutionResponse",
"debugInfo": "Failed to parse SDKResponse from http_response: 'HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nTransfer-Encoding: chunked\r\nConnection: keep-alive\r\nDate: Sun, 11 Dec 2016 22:54:50 GMT\r\nServer: Server-Software/1.0\r\nGoogle-Assistant-API-Version: v1\r\nVary: Accept-Encoding\r\nContent-Encoding: gzip\r\nX-Cache: Miss from CDN\r\nVia: 1.1 cdn.example.net (CDN)\r\n\r\n{\"conversation_token\":null,\"expect_user_response\":false,\"expected_inputs\":[],\"final_response\":{\"speech_response\":{\"ssml\":null,\"text_to_speech\":\"Hello!\"}}}'"
}
]
}
}
The block inside the debugInfo field is:
Failed to parse SDKResponse from http_response: 'HTTP/1.1 200 OK
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Date: Sun, 11 Dec 2016 22:54:50 GMT
Server: Server-Software/1.0
Google-Assistant-API-Version: v1
Vary: Accept-Encoding
Content-Encoding: gzip
X-Cache: Miss from CDN
Via: 1.1 cdn.example.net (CDN)
{\"conversation_token\":null,\"expect_user_response\":false,\"expected_inputs\":[],\"final_response\":{\"speech_response\":{\"ssml\":null,\"text_to_speech\":\"Hello!\"}}}'
Fields that have null values or empty arrays should be excluded. For example, since expect_user_response is false, the expected_inputs field should not be present in the output. Use the following instead:
{
"expect_user_response": false,
"final_response": {
"speech_response": {
"text_to_speech": "Hello!"
}
}
}