I recently took some interest in learning some load testing tools and Gatling seemed a very good choice. The only drawback related to other tools is the lack of documentation/examples for the upload of files with dynamic values.
For example, to upload a static CSV file I can use:
val scn: ScenarioBuilder = scenario("My First Test")
.exec(http("Upload CSV")
.post("/csv-upload")
.formUpload("file", "file.csv")
.check(status.is(202))
)
But if I want to add a feeder to add values to that CSV I would like to have something like:
val scn: ScenarioBuilder = scenario("My First Test")
.feed(customFeeder)
.exec(http("Upload CSV")
.post("/csv-upload")
.formUpload("file", ElFileBody("file.csv"))
.check(status.is(202))
)
I already tried multiple methods to upload body parts and for example, if I do something of the sort:
val scn: ScenarioBuilder = scenario("My First Test")
.feed(customFeeder)
.exec(http("Upload CSV")
.post("/csv-upload")
.bodyPart(ElFileBodyPart("file", "file.csv"))
.check(status.is(202))
)
I get an error on the server-side:
MissingServletRequestPartException: Required request part 'file' is not present
I was able to proxy the request that Gatling does and the generated curl request is:
curl --location --request POST 'http://localhost:8080/api/v1/resource/csv' \
--header 'accept: application/json' \
--header 'content-length: 310' \
--header 'content-type: multipart/form-data; boundary=UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj' \
--header 'host: localhost:8080' \
--header 'x-tenantid: t1' \
--data-raw '--UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj
Content-Disposition: form-data; name="file"
Content-Type: multipart/form-data; charset=UTF-8
Name,Phone,Address
PersonName,123456,ThatStreet
--UhyANQVVCm0hahnV9JvGEA8tPLU1Kc2Z5Fj--
'
Which constructs the request correctly, but the error on the server side remains.
Is there any way that this can be achievable?
The only drawback related to other tools is the upload of files with dynamic values.
No idea where this comes from.
.formUpload("name", "path") is merely a handy shortcut for bodyPart(RawFileBodyPart("name", "path")).
Please read the official documentation regarding multipart support.
Related
I am trying to convert a curl call to python request . The curl call looks like
$ curl -b $COOKIE_FILE \
-X FIND $URL \
-H 'Content-Type: application/json; charset=utf-8' \
I tried using request to get the correct response via requests.post() but i could not get the correct response. Can someone help me with this
Requests allows using arbitrary request methods with the request function, take a look at the documentation.
For example this is how it would look with a Session() object:
import requests
with requests.Session() as sess:
sess.headers = {
#headers in dict format, you could add cookies here too(or set it to sess.cookies)
}
response = sess.request("FIND", url)
When I execute a POST request using curl, it looks this way:
curl -k -X POST \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "Accept: application/json" \
--data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
--data-urlencode "apikey=<somekey>" \
"https://iam.bluemix.net/identity/token"
In the scalaj-http library, I know we can add header, but I don't see a way to add data-urlencode as an option. How can I add this? I need it for my POST Request to be successful.
Try postForm like so
Http("https://iam.bluemix.net/identity/token")
.header("Content-Type", "application/x-www-form-urlencoded")
.header("Accept", "application/json")
.postForm(Seq(
"grant_type" -> "urn:ibm:params:oauth:grant-type:apikey",
"apikey" -> "somekey"))
.asString
I am attempting to update a custom object using the Salesforce REST API as described here, but I consistently receive this 400 response
[
{
"message": "The HTTP entity body is required, but this request has no entity body.",
"errorCode": "JSON_PARSER_ERROR"
}
]
I have tried appending ?_HttpMethod=PATCH to the url and switching to a POSTcall, but while that yields 200 OK, it doesn't actually update the object. The object is "updateable" and I do have permission to edit it. Editing it directly in Salesforce works without issues.
Here is my (cleaned) request, as exported from Insomnia [Version 5.14.9 (5.14.9.1895)].
curl --request PATCH \
--url https://myInstance.salesforce.com/services/data/v20.0/sobjects/CUSTOMOBJECT/CUSTOMOBJECTID \
--header 'authorization: Bearer token' \
--header 'content-type: application/json' \
--data '{
"Additional_Information__c": "Test additional information"
}'
Any ideas on how I can resolve this?
According to the Salesforce documentation for sending HTTP requests with cURL, either a JSON data file needs to be sent or a ".json" extension needs to be appended to the URI.
curl --request PATCH \
--url https://myInstance.salesforce.com/services/data/v20.0/sobjects/CUSTOMOBJECT/CUSTOMOBJECTID.json \
--header 'authorization: Bearer token' \
--header 'content-type: application/json' \
--data '{
"Additional_Information__c": "Test additional information"
}'
When trying to upload a large file to a server as chunked entity in Multipart Form:
val chunked = HttpEntity.Chunked.fromData(mimeType, sourceOfByteString)
Multipart.FormData(
Multipart.FormData.BodyPart("downloadPath", HttpEntity(fileResourceRequest.downloadPath.path)),
Multipart.FormData.BodyPart("fileSize", HttpEntity(fileResourceRequest.fileSize.toString)),
Multipart.FormData.BodyPart("data", chunked, Map("filename" → "content"))
).toEntity()
I get this error:
Type mismatch: expected BodyPartEntity, actual HttpEntity.Chunked
When adding a Transfer-Encoding: chunked header manually, Akka-http removes it, as per documentation.
I am able to successfully perform exactly the same Upload using curl
curl -i -X POST \
-H "Content-Type:multipart/form-data" \
-H "Authorization:Bearer BB3F8B79384D08B9F268F21FF76ABFA" \
-H "Transfer-Encoding:chunked" \
-F "downloadPath=/user-data/media/dachi.png" \
-F "fileSize=733830" \
-F "data=#\"./dachi.png\";type=image/png;filename=\"dachi.png\"" \
'http://0.0.0.0:8000'
Use HttpEntity.IndefiniteLength as per documentation:
Hbase REST API, this interface get 'version/cluster', when I use the header Accept: application/json, the response is not JSON but plain text.
curl -X GET \
-H "Accept: application/json" \
"http://localhost:8888/version/cluster"
# "1.2.2"
But when I use Accept: text/xml, the response is correct XML.
curl -X GET \
-H "Accept: text/xml" \
"http://localhost:8888/version/cluster"
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ClusterVersion>1.2.2</ClusterVersion>
Hbase issue #17713. The Jan Hentschel's comment, he is right. The JSON spec has been updated from RFC 4627 to RFC 7159 and a String is valid JSON.