Unable to create http post request with multipart file which size greater than 10MB - karate

Method POST fails:
java.net.SocketException: An established connection has been dropped by software on your host computer, http call failed after 180865 milliseconds for url: http://localhost:8080/api/v2/files?filename=more.wav&contractId=51846706-c05f-4089-882d-7229f9b96d42
16:44:41.580 classpath:karate/features/files/files_post_exceptions.feature:106
I tried this scenario:
Scenario: As admin create file with size greater than 10MB
* def Path = 'classpath:karate/data/more-than-10MB.wav'
Given url HOST_V2
And path '/files'
And header Authorization = 'Bearer ' + TOKEN
And header content-type = 'multipart/form-data'
And params { contractId :'#(contractId)',filename : 'more-than-10MB.wav'}
And multipart file file = {read: '#(Path)', contentType: 'application/octet-stream',filename: 'more-than-10MB.wav'}
When method post
Then status 500
I expect a status 500.

Sounds like your network has throttled something. That said, Karate may have issues with large binary uploads. So you can use this workaround - which is to call curl via the command-line. Doing this for one or two "non-happy" path tests is perfectly fine (in my opinion).
Here are details: Using cURL for API automation in Karate

Related

Jmeter showing response code as 300 in response

I am working in a desktop application which contains API as well.
So when I try to hit the API using Jmeter with the local server name as localhost. I am getting the response as below
Response code:300
Response message:MULTIPLE CHOICES
Response data:
{"succeed": false, "error_message": "No data JSON received!"}
Even I tried with the Content-Type as application/json and multipart/form-data, but not worked.
Note: When I try to hit the same API using Postman, I got the 200 status.
If you're able to successfully execute the request using Postman you should be able to do this using JMeter as well. We cannot state what's wrong without seeing your Postman and JMeter configurations, just make sure that everything is the same:
request URL
request bosy
request headers
etc.
If you will send the same request - you will get the same response.
Be aware that you can just record the request from Postman using JMeter
Start JMeter's HTTP(S) Test Script Recorder
If you're using HTTPS protocol - import JMeter's certificate into Postman
Configure Postman to use JMeter as the proxy
Run your request in Postman
JMeter will capture the request and generate relevant HTTP Request sampler and HTTP Header Manager
More information: How to Convert Your Postman API Tests to JMeter for Scaling

When i POST a URL with Headers with Body data it is working fine in J METER -HTTP API request i get the following Error

In POSTMAN when i POST a URL with Headers with Body data it is working fine and getting Response as 200,but when i POST the same in J meter HTTP API request i am receiving the following Error.
Headers size in bytes: 124
Body size in bytes: 54
Sample Count: 1
Error Count: 1
Data type ("text"|"bin"|""): text
Response code: 404
Response message: Resource Not Found
If you're sending the same requests you should be getting the same responses. HTTP Status Code 404 means that URL path is not correct so you need to check the path of your URL as most probably there is a difference there. Even non-printable characters which you cannot see in JMeter GUI are encoded into their equivalents so whitespace becomes %20 so pay attention to literally everything.
In any case given you can successfully execute the request in Postman it means that you can record it using JMeter's HTTP(S) Test Script Recorder
Prepare JMeter for recording, the easiest way is using JMeter Templates Feature
once JMeter creates a Test Plan for your - expand and start the HTTP(S) Test Script Recorder
Prepare Postman for recording, configure it to use JMeter as the proxy:
Run your request in Postman
That's it, JMeter should capture the request and save it under the Recording Controller along with the HTTP Header Manager containing corresponding request headers

Not able to retrieve response for a GET request via Karate [duplicate]

This question already has an answer here:
Passing JSON request starting with the character [ gives the error: invalid request format with GET operation [duplicate]
(1 answer)
Closed 2 years ago.
I am getting an error as below when I execute my scenario
Feature: sample karate test script for ws+
Background:
url 'https://pluss-nav2.ekstern.acos/api/api/register/'
configure headers = { Accept: 'application/json' }
configure ssl = true
header Authorization = 'Bearer token'
Scenario: get all users and then get the first user by id
Given path 'sakmaler'
When method get
Then status 200
When method gets executed, I get the below exception.
com.intuit.karate.exception.KarateException:
com.intuit.karate.exception.KarateException: wsplussnav.feature:14 -
java.net.UnknownHostException: This is usually a temporary error during hostname resolution and means that the local server did not receive a response from an authoritative server (pluss-nav2.ekstern.acos)
Note: I get this exception only when I execute test on this url. This url does not have any proper domain like .net or .com
I tested in postman, and it works.
I tested in powershell command, and it works.
Any idea how to re-solve this error in Karate?
Most likely you are behind a corporate proxy, which is why it works in P*stman.
Refer the docs: https://github.com/intuit/karate#configure
karate.configure('proxy','http://myhost:80');
EDIT: for others landing here, besides the fact that an HTTP proxy may be in the picture - another place where Karate behaves a bit differently than Postman is that Karate does not auto-send an Accept header by default.

Jmeter - POST API not working

I am new to Jmeter and have been struggling to get it working to test my POST API. It works fine for a GET API call where I pass the parameters through the Parameters tab.
Details here:
server name: localhost
port: 8080
path /registerMobileUsingCode
In the request body, I am sending the following:
{
"clientName": "DemoOrg",
"code": "9880007615",
"languageId": "1"
}
My Jmeter setup looks like this:
And my HTTP Request Header looks like this:
The API is in production and works fine with postman.
I am just unable to get it working through JMeter. It is obvious that I am doing something wrong but can't figure out what despite having spent a considerable amount of time Googling for solutions.
Any help would be much appreciated.
UPDATE - 1 - Updated with jmeter log as suggested
Thread Name: Thread Group 1-1 Sample Start: 2017-08-09 17:03:41 IST Load time: 1604 Connect Time: 1525 Latency: 1604 Size in bytes: 399
Sent bytes:251 Headers size in bytes: 213 Body size in bytes: 186
Sample Count: 1 Error Count: 1 Data type ("text"|"bin"|""): text
Response code: 500 Response message: Server Level Exception
encountered
Response headers: HTTP/1.1 500 Server Level Exception encountered
Date: Wed, 09 Aug 2017 11:33:43 GMT Access-Control-Allow-Origin: *
Content-Type: application/json Transfer-Encoding: chunked Server:
Jetty(9.2.16.v20160414)
HTTPSampleResult fields: ContentType: application/json DataEncoding:
null
UPDATE-2 - Using Postman and JMeter Recorder
As suggested by #Dimitri T, I downloaded the Linux version of Postman and started it with --proxy-server=localhost:8888.
I was now able to make a Postman request and capture the request in JMeter. Here is what the request looked like:
Jmeter capture of a Postman Request
As you can see, nothing radically different from what I did. However, this DOES work! So hurray!
If your application works fine with Postman the fastest and the easiest way of building JMeter test plan will be just recording it using JMeter's HTTP(S) Test Script Recorder.
Prepare JMeter for recording (you can do it in a few clicks via JMeter Templates Feature)
from JMeter's main menu choose File -> Templates -> Recording and click "Create"
Expand Workbench - HTTP(S) Test Script Recorder and click "Start"
Prepare Postman for recording
In order to "tell" Postman to use JMeter as a proxy you need to provide --proxy-server parameter to it like:
C:\Users\YOUR_USER_NAME\AppData\Local\Postman\app-x.x.x\Postman.exe --proxy-server=localhost:8888
Execute your requests in Postman
JMeter will capture requests, convert them into HTTP Request samplers and store them under Test Plan -> Thread Group -> Recording Controller
References:
JMeter Proxy Step by Step
How to configure Postman Native Client App to use an external proxy
By seeing the image you have attached you are missing / in the path.
the path should be /registerMobileUsingCode
if it is working fine from POSTMAN, then your port 8080 is fine.
Can you please confirm what is the data type of your request? looks like languageId is integer so you should be using languageId: 1, instead of languageId: "1". The integer should not be double quotes.

Moqui REST API call fail with error code 403

From my Angular 2 application I am trying to get data from Moqui but the request always fails with the error code 403.
Here is the REST API call implementation
getExample() {
let url = 'http://localhost:8080/rest/s1/example/examples'
let headers = new Headers({ 'Authorization': 'Basic
am9obi5kb2U6bW9xdWk='});
headers.append('Accept', 'application/json, text/plain, */*');
headers.append('Content-Type', 'application/json; charset=UTF-8');
let options = new RequestOptions({ headers: headers });
let response = this.http.get(url, options).map(res => res.json());
return response;
}
The Moqui logs :-
REST Access Forbidden (no authz): User null is not authorized for View on REST Path /example/examples
There is also a similar question Moqui Rest Nginx but from the answer I do not know that where I have to change the settings in Moqui.
On the client console the error is :-
XMLHttpRequest cannot load http://localhost:8080/rest/s1/example/examples. Response for preflight has invalid HTTP status code 403
But with a rest client like YARC it works :-
You must authenticate for REST API calls except for Service REST API paths that are configured to not require authentication (like the /mantle/my end points in the mantle.rest.xml file in the mantle-usl component).
You have authentication but then there is one other step: authorization. In general if authc is required then authorization is also required. This is done with database records usually either in seed data and can also be added using the System app that is included in the default Moqui runtime (ie the moqui/moqui-runtime repository).
There is an example of authorization setup for Service REST API calls in the MantleSetupData.xml file. The main difference from screen authorization is that the artifact type to use is 'AT_REST_PATH'. Here is that file on GitHub (right near the top of the file):
https://github.com/moqui/mantle-usl/blob/master/data/MantleSetupData.xml
The best documentation for most things to do with REST requests in Moqui, is currently in the comments in the 'rest.xml' file that actually processes the incoming requests (ie handles the /rest path). You can see this on GitHub here:
https://github.com/moqui/moqui-runtime/blob/master/base-component/webroot/screen/webroot/rest.xml