Load testing on jmeter to compare request and response - java

I am trying to test my Springboot App using jMeter. I want to send multiple request with some JSON payload to receive the response concurrently (via threading).
While doing this, in order to check validity of response, I want to keep a log where it can show the request-response pair (side-by-side or even in separate files, they should just be identifiable which request gave which response).
This is to test if one request is not tampering other request's response (data validation).
I have already tried Simple Writer tool where we can log request and response (I think jmeter have used some different terminology in menu) on configure menu. But it doesn't seem to be working when I run the results.
So my main concern is how can we store the JSON request data and response data pair somewhere after test iteration have completed. I have never used jmeter before so a little bit of detailing will help.
Thanks!

You can use Flexible File Writer which gives you the full freedom with regards to what and where to store.
For example if you configure the Flexible File Writer as:
I'll provide textual form of the sample template:
---------REQUEST----------------------\r\n|requestData|\r\n---------RESPONSE--------------------\r\n|responseData|\r\n-------------------------------------
You will get results file looking like:
---------REQUEST----------------------
POST https://jsonplaceholder.typicode.com/posts
POST data:
{
"title": "foo",
"body": "bar",
"userId": 1
}
[no cookies]
---------RESPONSE--------------------
{
"id": 101
}
-------------------------------------
You can install Flexible File Writer plugin using JMeter Plugins Manager

Check out the JMeter docs on configuring the Results Tree. It will show you the results and you can configure how much to keep and where.
https://jmeter.apache.org/usermanual/component_reference.html#View_Results_Tree
In particular you might benefit from this:
https://jmeter.apache.org/usermanual/component_reference.html#Save_Responses_to_a_file

Related

Running Java Lambda through API Gateway in

I am trying to make a local Java program run in AWS Lambda and make it such that it can be called with a HTTP request. All I need is just to be able to duplicate the functionality of running java locally from the command line through HTTP in AWS so other people in the company can run the code by just sending a HTTP request in Postman(for now, next step is a web form that just makes the request) instead of downloading the jar and launching the Java command line.
I went through the hello world tutorial in the Amazon website and was able to adapt my code, and run it successfully using the test function in the AWS Lambda control panel. I am also able to see the logs in cloudwatch that it ran and also observe the results. So it all works from the Lambda control panel test function.
So instead of command line arguments, I'm giving the arguments in JSON format as follows:
{
"environment": "dev",
"username": "Test",
"password": "Test22",
"storeId": "TESTMA0001",
"data": "a,b,c,d"
}
And this works quite well when invoking the lambda from the test function.
However I want to be able to enter this in the body of a HTTP request and have my lambda run so I added an api gateway through the gui in the aws lambda panel, chose HTTP API kind and default options.
Then I send a HTTP GET request to the api endpoint with the body being the same input I used in the testing panel, but whenever I run it, I get internal server error. I turned on access logs for the gateway api, and I get the following, my lambda is not being launched by the api since there is no lambda log being written when I use the API, it gets written when I launch it from the AWS lambda web panel.
{
"requestId": "KByVuheeoAMEPLA=",
"ip": "",
"requestTime": "27/Mar/2020:02:25:40 +0000",
"httpMethod": "GET",
"routeKey": "$default",
"status": "500",
"protocol": "HTTP/1.1",
"responseLength": "35"
}
My handleRequest function takes a string, string map as input and returns a string as output:
public class StoreCategoryImporter implements RequestHandler<Map<String,String>, String> {
#Override
public String handleRequest(Map<String,String> event, Context context)
I don't even use the context object but it was there in the tutorial so it remained.
I googled for hours and I have not been able to find a solution, any help would be appreciated. I find most AWS tutorials to skip over some crucial details or they don't have it for POJO developers and use js which I don't understand.
Thank you in advance.
To simulate API Gateway event for tests in your lambda you, the lambda console has some pre-set values. In your lambda you go to Configure test event and choose the event you want to simulate, e.g.:
Alternatively, you can print out real event in your lambda to CloudWatch logs, and use that for tests.
I have solved this problem by more googling and finding a closer solution. Forget about the AWS tutorial, you need to override the handleRequest(APIGatewayProxyRequestEvent, Context) method, not the one that just takes in a Map(String,String) event as described in the hello world tutorial if you want to be able to trigger your lambda through a HTTP request.
Also, the "configure test event" in the AWS GUI is useless in this case. It cannot parse JSON that isn't a primitive. Probably the CLI would work better.

REST API Single Request - Multiple responses

I am writing a REST API in JAX-RS 2.0, JDK 8 for the below requirement
POST API /server/fileUpload/ (Multipart Form data) where I need to send a Big .AI (Adobe Illustrator) File in this.
The Server, takes the file and return Status 202 (Accepted), Acknowledging that file transfer happened Successfully. (From endpoint to Server)
Now at the Server, I am using Java + Imagemagik to convert .AI File (20-25 MB File) to small JPG Thumbnail, place on a Apache HTTP Server and share the location (like http://happyplace/thumbnail0987.jpg)
Now the Second Response should come from Server with Status 200 OK and Thumbnail URL
is it feasible with one REST API? (Async/similar)
or should I split it to 2 API calls, Please suggest
No. In http, one request gets one response. The client must send a second request to get a second response.
You can use WebSockets for that.
If you are calling from script the call will be async you can handle the Thumbnail URL when you get a response. When you are calling from java program i suggest to run it on a different thread, If the execution is not sequential i.e ( Remaining lines can be executed without getting URL). If url is needed for the remaining section of code you can make one call and wait for the response then execute remaining code.
You need to make different APIs for both scenarios. One for showing file upload status and another for all file conversion and manipulation.
On the client side second request must be callback of first request.
The best way to handle these kind of scenario is to use Java Reactive (Project Reactor, WebFlux).
You can return two response using custom middlewares in asp.net (however not recommended).
Return response from one middleware and subsequently you can invoke next middleware and return second response from second middleware

REST API Design sending JSON data and a file to the api in same request

I am creating a REST API on top of an existing application. One of the features takes in a json data along with a file uploaded by the user.
I am unsure how to send a file AND json data in the same request to the REST API?
I have the json part working and I test that using curl:
curl -XPOST http://localhost:8080/myapp/foo -d '{"mydata": {
"name": "somename",
"gender": "male"
}}'
//I would like to send an image (say, profile image) with the above request as well.
I'm using a grails application so I get this data in my controller like so: new Foo(params.mydata).
Question
Is it possible to send JSON data and a file in the same request to the API? If so, how can I do it using curl or REST Console (chrome extension)
What would be the contentType of this request?
I'm open to sending data in another format if it means that I can send file and other data (strings) within the same request. I'm not tied on JSON
Update
I found another SO question which is asking the same thing. From the answer to that question it seems there are only three choices and none of which say that its possible to send both, json data and file, within the same request. Which is very discouraging...I will keep this question open to see if anyone has other ideas.
I think the "right" way to do this is with a multipart message. That way, you can post up both the JSON and the Image with their corresponding correct MIME type. The wikipedia article on multipart mime types has an example of what this would look like. It looks like both Apache httpcommons and Jersey support this sort of thing, and apparently curl does too!

How to parse a custom XML-style error code response from a website

I'm developing a program that queries and prints out open data from the local transit authority, which is returned in the form of an XML response.
Normally, when there are buses scheduled to run in the next few hours (and in other typical situations), the XML response generated by the page is handled correctly by the java.net.URLConnection.getInputStream() function, and I am able to print the individual results afterwards.
The problem is when the buses are NOT running, or when some other problem with my queries develops after it is sent to the transit authority's web server. When the authority developed their service, they came up with their own unique error response codes, which are also sent as XMLs. For example, one of these error messages might look like this:
<Error xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Code>3005</Code>
<Message>Sorry, no stop estimates found for given values.</Message>
</Error>
(This code and similar is all that I receive from the transit authority in such situations.)
However, it appears that URLConnection.getInputStream() and some of its siblings are unable to interpret this custom code as a "valid" response that I can handle and print out as an error message. Instead, they give me a more generic HTTP/1.1 404 Not Found error. This problem cascades into my program which then prints out a java.io.FileNotFoundException error pointing to the offending input stream.
My question is therefore two-fold:
1. Is there a way to retrieve, parse, and print a custom XML-formatted error code sent by a web service using the plugins that are available in Java?
2. If the above is not possible, what other tools should I use or develop to handle such custom codes as described?
URLConnection isn't up to the job of REST, in my opinion, and if you're using getInputStream, I'm almost certain you're not handling character encoding correctly.
Check out Spring's RestTemplate - it's really easy to use (just as easy as URLConnection), powerful and flexible. You will need to change the ResponseErrorHandler, because the default one will throw an exception on 404, but it looks like you want it to carry on and parse the XML in the response.

Web service for retrieving chunks of data

I'm planning to develop a webservice, and I like to try the RESTful architecture. The issue is that I don't know if the service is adequate for it, or it is better to use SOAP.
The service is about downloading some data from the server to a device on the local computer. The data will be split into chunks. The service will be run with an ad-hoc client at the local machine that will manage the device the file is gonna be stored in.
I was thinking on having something like:
/files/{id} --> will inform about the details of the file
/files--> list all the files
The problem is for the action. In rest only GET, POST and (PUT DELETE) are defined. But I want to have something like download. My idea, although not fully restful is to create:
/files/{id}/download
This will return something like
{ "chunk" : "base64 string with chunk data"
"next" : "http://XXX/file/id/download?chunk=1
}
When next is empty the whole set of chunks would be downloaded.
What do you think? Is it ok to do it this way or would it be better the traditional way using SOAP and defining functions like getFiles(), getFileChunk(chunkNo, file)?
Any comment is really appreciated.
See you
If using REST, you don't need to define your own "chunking" protocol as the HTTP headers Content-Length, Content-Range and Transfer-Encoding are all used for sending chunked data.
See the RFC for HTTP header fields
As John already mentioned you might want to separate between your file resources and the file resource metadata (any information about your file). Additionally a more RESTful way to access your chunks could look like this:
http://url/files/{id}/chunks
{
"complete" : false,
"chunks": [
"http://url/files/<fileid>/chunks/1",
"http://url/files/<fileid>/chunks/2",
"http://url/files/<fileid>/chunks/3",
]
}
Basically, here, you return a list of RESTFUL URIs to all your file chunks and the information if all chunks of the file are already complete. I don't see that SOAP might have any advantage there since you would define the same methods (getFile and getChunks) that are already covered by the REST verb GET.
It sounds like you really have two different resources: file-metadatas and files. What about something like:
/file/{id} // GET: Retrieve this file's data.
/file-metadata/{id} // GET: Metadata about a particular file. Contains link to file:
// {
// ...
// data: "http://.../file/156", // Where to find file's data.
// }
/file-metadata // GET: List metadata for all files.

Categories

Resources