How to upload json file through jmeter? - json

I have recorded my script to upload json file through Jmeter, but now I am facing the problem while uploading json file through jmeter which is on my local drive.
I am already done with following steps:
Either use full path to file, you're uploading, or copy it to JMeter's "bin" folder
Don't forget to tick Use multipart/form-data for HTTP POST box
Make sure you provide correct Parameter name and MIME Type
Getting exception in my response data:
{"Exception":"Object reference not set to an instance of an object."}

For me works like this. JSON example May be Your server prefer some specific headers? E.g. content type and so on
Why you're using json file?
If you facing problems with generating random JSON data, here is a JSR223 preprocessor:
import org.apache.commons.io.FileUtils;
def time = vars.get("stratup_time")
File myFile = File.createTempFile("upload-", "" );
// Generate Random length string and write to file
FileUtils.write(myFile, "{\"test\":\"$time\"", "UTF-8" )
// Store file name in variable.
vars.put( "filename", myFile.getCanonicalPath() )
And PostProcessor:
import org.apache.commons.io.FileUtils;
// Delete file and do not throw error
FileUtils.deleteQuietly(new File( vars.get("filename")));

In order to be able to record the file upload event you need to copy your .json file to JMeter's "bin" folder, this way HTTP(S) Test Script Recorder will be able to capture the request and generate necessary HTTP Request sampler. It will also populate the HTTP Header Manager
More information: Recording File Uploads with JMeter

Related

Writing data to an existing file in the host server using http in flutter

I want to make a json file on the server, and then update this json file using flutter http method in my app. I will get user ID, and if the user ID is already present in json file on the server, I just update the content of that items in the json file for this user only. If the user does not exist I add a new block into my json file on the server.
To do this, I first created a json file on the server and passed its url to http.post or http.put, but my json file is still empty. This means I cannot write anything in my json file.
Why?
Could you please let me know how I can achieve this?

I have been trying to add a dynamic value in the url path of an api in Jmeter script from response code of other api. Help me out

I have an api which has many folder to it and each folder have more than two contents and I want to compare each contentid in folder from response code with other duplicate api response code which has same contents as this api in Jmeter
For eg. The folders are in a path something like https://apple.test.com/user/folder(just an example url)
To extract each folder I have used json extractor for above url in http request and extracted the folder id (with json path as $..folderid...if I select ALL in the extractor and try to use ${folderid_ALL} in url path I am getting an error), then created another http request and passed this variable in the url something like
https://apple.test.com/user/folder/${folderid}
And used beanshell assertion to compare their contentid
When I execute this only the first folder is picking up and it's contents are compared and rest of the folders are not shown
Can you help me out on how to extract all the files and compare their contents!!
If you have multiple folder IDs extracted into JMeter Variables using JSON Extractor you can use ForEach Controller to iterate all the IDs.
Also since JMeter 3.1 it's recommended to use JSR223 Test Elements and Groovy language for scripting so consider migrating to the JSR223 Assertion
In order to get the comprehensive answer you should include:
The JMeter Variables generated by the JSON Extractor
The format of the "next" request for the "folder"
The response you're getting
What do you want to compare with what

Karate - upload csv file in form-data body [duplicate]

I am using Karate 0.9.0 version and I want to upload data using csv file. As per new update, it is converting data into JSON. But my API supports csv file format for upload function. How can I upload csv file in post request without converting data into json?
Example
Given path 'xxx/upload'
And header Authorization = xxx
And header Content-Type = 'text/csv'
And request read('classpath:xxx.csv')
When method POST
Then status 202
P.S. This example was working in Karate version: 0.9.0.RC5
Thanks, that is indeed an edge case we hadn't thought of, but you have 2 options that will work nicely:
1) rename your CSV file to *.txt
And request read('classpath:xxx.txt')
2) use the karate.readAsString() API
And request karate.readAsString('classpath:xxx.csv')

How to JSON wrapper ( {"text": " ) from CSV response in WSO2

I am new to WSO2. I wrote Custom Java Class Mediator to transform JSON request to CSV format. I have a proxy service to SFTP the generated CSV file to a (MoveIT) folder.
Custom Mediator converts the JSON request properly to CSV format. But, when send the CSV file using transport.vfs.replyfilename to the endpoint, I see the 'text' wrapper as below in the CSV file:
{"text":"1,F20175_A.CSV,20200623135039\n2,123456789,2017-MO-BX-0048,123456789,987654321,Y/N,C/A,20190101,20201231,20190930,75000,44475.86,15563.52,0.00,15563.52,0.00,60039.38,14960.62,60039.38,0.00,20191218\n3,1,999999999\n"}
I set contentType, MessageType properties "text/plain". I also used vfs.ContentType to set to text/plain as below:
text/plain
I know I am missing something. Has anybody come across this issue in WSO EI 6.6? Should I go ahead and write Custom Message Formatter? Any tips?
I want the output to be written as:
1,F20169_A.CSV,20200617153638
2,123456789,2017-MO-BX-0048,123456789,987654321,Y/N,C/A,20190101,20201231,20190930,75000,44475.86,15563.52,0.00,15563.52,0.00,60039.38,14960.62,60039.38,0.00,20191218
3,1,999999999
Thanks!
It seems that after converting to the CSV format the result is available within a text tag. Therefore using the file connector [1] when you write to the file access the text content using //text() XPath. Please refer to the following sample configuration of inputContent.
<fileconnector.create>
<filePath>{$ctx:filePath}</filePath>
<inputContent>{//text()}</inputContent>
<encoding>{$ctx:encoding}</encoding>
<setTimeout>{$ctx:setTimeout}</setTimeout>
<setPassiveMode>{$ctx:setPassiveMode}</setPassiveMode>
<setSoTimeout>{$ctx:setSoTimeout}</setSoTimeout>
<setUserDirIsRoot>{$ctx:setUserDirIsRoot}</setUserDirIsRoot>
<setStrictHostKeyChecking>{$ctx:setStrictHostKeyChecking}</setStrictHostKeyChecking>
</fileconnector.create>
[1]-https://docs.wso2.com/display/ESBCONNECTORS/Working+with+the+File+Connector#WorkingwiththeFileConnector-create

Azure Logic Apps: Read XML from file and Write a JSON with data

I'm new in it and trying to understand Azure Logic Apps.
I would like to create a LogicApp that:
Looks for new XML-Files
and for each file:
Read the XML
Check if Node "attachment" is present
and for each Attachment:
Read the Filename
Get the File from FTP and do BASE64-encoding
End for each Attachment.
Write JSON File (I have a schema)
DO HTTP-Post to API with JSON file as "application/json"
Is this possible with the Logic-Apps?
Yes, you can.
Check if a node is present, with xpath expression (e.g. xpath(xml(item()),'string(//Part/#ref)'))
For Get File from FTP, use the action FTP - Get File Content
Write JSON File, use the action Data Operations - Compose. If you need transformations, you have to use an Integration Account and Maps.
Do HTTP Post to API, use de action HTTP