I was trying to handle/receive all the responses with the 2xx status codes with the 'regex' http response code '2\d+' but it was not handling it as expected.When I enter the http status code directly (for example '202') then it was handling the response. But I want 'regex' to handle it.
#source(type='http-response', sink.id='Response',http.status.code='2\\d+', #map(type='json',#attributes(success = 'status')))
#sink(type='log')
define stream ResponseStream(success string);
Here is the response am getting when i use regex code.
[2019-11-26 07:16:42,705] ERROR
{org.wso2.extension.siddhi.io.http.source.HttpResponseMessageListener}
- No source of type 'http-response' that matches with the status code '202' has been defined. Hence dropping the response message.
Kindly help me to handle this using regex codes.
In your Siddhi query you have given status code as '2\\d+'. Please change it to '2\d+'
Related
I'm learning Postman, and I tried authentication with valid and invalid data. (I'm using basic auth).
If I give valid data, the login redirects me to the index page as is should, giving 200 OK status code. However if I pass wrong parameters, the status code remains 200 OK aswell, only the page tells me, that me username and password is incorrect. I tried using the following method I found somewhere:
pm.test("Request is successful with a status code of 200", function () {
pm.response.to.have.status(200);
});
I think postman gives me 200 OK since the post-request is done, and the failed-login option is handled properly. (I have to mention that this API I'm testing is pre-defined, I didn't make it.)
So basically how can I test this?
You could check the response body to not contain a certain string:
pm.test("Body does not contain invalid login message",() => {
pm.expect(pm.response.text()).to.not.include("invalid login");
});
Replace invalid login by te string you want to check for.
You can just test for a different status code (i.e., 400 BadRequest)
tests["Status code is 400"] = responseCode.code === 400;
I would like to return a response code of 400 to the client after throwing an error in my Lambda function. (via REST API - GET)
Here is the response from the Lambda function:
{
"errorMessage": "{\"status\": 400, \"result\": \"Invalid Input\", \"errorDescription\": \"Incorrect data format, should be YYYY-MM-DD. Refer to our documentation for further instructions.\", \"documentation\": \"link\"}",
"errorType": "ValueError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 69, in lambda_handler\n raise ValueError(date_error_json)\n"
]
}
In the settings of the Integration Response of the API I set up the Lambda Error Regex as .*"status":400.*
For the mapping template I have:
#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage')))
{
"status" : "$errorMessageObj.status"
}
When calling the API I mostly receive this result:
{"errorMessage": "{\"status\": 400, \"result\": \"Invalid Input\", \"errorDescription\": \"Incorrect data format, should be YYYY-MM-DD. Refer to our documentation for further instructions.\", \"documentation\": \"link\"}", "errorType": "ValueError", "stackTrace": [" File \"/var/task/lambda_function.py\", line 69, in lambda_handler\n raise ValueError(date_error_json)\n"]}
And the status of the HTTP request tracked in Chromes Developer Tools shows as 200.
My assumption is that the Regex is incorrect since it should at least return a 400 HTTP response, even if my mapping template was incorrect.
However, surprisingly a few times I was able to get the desired result of a 400 HTTP response, as well as the desired format displayed as:
{
"status" : "400"
}
The way I got to this result was the following: When I changed the Regex around to .*400.* (which did not help) and then back to .*"status":400.*. However, as soon as I send another request to the API it was back to the situation before. (No other changes were made, only a second API request)
And this is actually repeatable, every time I switch back and forth between those Regex values I get my desired result. For 1 API request and then it switches back.
I know it sounds weird. Here is a quick screenshare of it: https://www.loom.com/share/365a7c48119944658e157c5e0a5178e8
I would like to know if there is an issue with my code or if this might be a bug on Amazon's end.
For anyone coming across the same problem in the future. I have found out the following 2 things:
After trying again to set .*400.* a little later it worked fine. Of course, this may not be a good idea, because if you return any results, that contain 400 anywhere in their response, they could incorrectly trigger a 400 HTTP response.
The workaround I found was to use .*Invalid Input.*. Since it is not expected that regular results returned from the API would contain this phrase, this should work reliably.
I would like to obtain in a response of http-connector, only the “number” element, but I cannot obtain it.
I’m trying to have an inline Javascript with the following statement:
S(response).prop(“status”).prop(“number”).numberValue();
but it shows an error: SPIN/JACKSON-JSON-01004 Unable to find ‘status’
What it’s wrong in the statement?
Rest response to parse:
{
“status”: {
“number”: 200,
“type”: “OK”,
“description”: “Status OK”
}
}
There is no obvious issue with your expression. I would debug further to see if response indeed contanis the Json string you posted. The error shows that response exists, but the content differs.
This working example I just created may help you:
https://github.com/rob2universe/camunda-http-connector-example
If this does not help, you could share more info, e.g. the process model, server log, service you are calling...
Using the json-rpc-cpp library, I am creating an EOS Wallet using wallet RPC.
HttpClient *temp = new HttpClient("http://127.0.0.1:30031/v1/wallet/create");
string res;
string str = "testwallet1";
temp->SendRPCMessage(str, res);
cout<<"res : "<<res<<endl;
It is creating the wallet successfully, but after that I am getting the following exception.
unknown file: Failure
C++ exception with description "Exception -32603 : INTERNAL_ERROR: : "PW5JcEu7jTXd7XUYLWkPuCUbr1pqBhusqRFfhSVToqUNcDuZ3oeYK"" thrown in the test body.
I found that HttpClient receives a 201 response code. I have no idea how to avoid that exception. Does anyone have any idea?
The issue is caused by a bug in the HttpClient::SendRPCMessage() implementation.
Internally, HttpClient uses libcurl for its HTTP handling, and at the very end of the SendRPCMessage() implementation is the following check if curl_easy_perform() is successful:
long http_code = 0;
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
if (http_code != 200) {
throw JsonRpcException(Errors::ERROR_RPC_INTERNAL_ERROR, result);
}
As you can see, SendRPCMessage() throws an exception for ANY HTTP response code other than 200. But per the HTTP standard, ALL 2xx response codes indicate success, not just 200. In this case, response code 201 means:
10.2.2 201 Created
The request has been fulfilled and resulted in a new resource being created. The newly created resource can be referenced by the URI(s) returned in the entity of the response, with the most specific URI for the resource given by a Location header field. The response SHOULD include an entity containing a list of resource characteristics and location(s) from which the user or user agent can choose the one most appropriate. The entity format is specified by the media type given in the Content-Type header field. The origin server MUST create the resource before returning the 201 status code. If the action cannot be carried out immediately, the server SHOULD respond with 202 (Accepted) response instead.
A 201 response MAY contain an ETag response header field indicating the current value of the entity tag for the requested variant just created, see section 14.19.
This is clearly a logic error in the implementation of SendRPCMessage(). The check of the http_code should be more like this instead:
if ((http_code / 100) != 2)
This will treat all 2xx response codes as success.
I have filed a bug report with json-rpc-cpp's author:
#278 HttpClient::SendRPCMessage() throws ERROR_RPC_INTERNAL for successful HTTP responses
201 basically means that your request was processed successfully. As this source explains:
201 CREATED The request has been fulfilled and has resulted in one or more new resources being created.
The primary resource created by the request is identified by either a
Location header field in the response or, if no Location field is
received, by the effective request URI.
The 201 response payload typically describes and links to the
resource(s) created. See Section 7.2 of RFC7231 for a discussion of
the meaning and purpose of validator header fields, such as ETag and
Last-Modified, in a 201 response.
The exception must be thrown when any further processing is applied to the response data.
I can't tell what exactly causes this without more information.
I am trying to invoke a POST web service via Postman and I am getting the following error.
Error while sending request: Failed to execute setRequestHeader on
XMLHttpRequest: Value is not a valid ByteString.
Request Headers
X-PW-AccessToken:{{api_token}}
X-PW-Application:developer_api
X-PW-UserEmail:{{api_email}}
Content-Type:application/json
Request Body
{
"page_size": 25
}
Can anyone tell me why I am getting this error, and how can I get rid of this?
I think Http protocol's header can only post ByteString (what is ByteString? I think it is ASCII).
So if you have other char, for example, 汉字. if you put '汉字' add to Http Header the error 'Value is not a valid ByteString' happen!
Solove: You can use the encodeURI function to encode the String in the client, and then, You can use URLdecode.decode()(java) to decode the header information in the server.