You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@jmeter.apache.org by bu...@apache.org on 2022/06/15 13:26:26 UTC
[Bug 66122] New: Error when using __FileToString to set GraphQL request body
https://bz.apache.org/bugzilla/show_bug.cgi?id=66122
Bug ID: 66122
Summary: Error when using __FileToString to set GraphQL request
body
Product: JMeter
Version: 5.5
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P2
Component: HTTP
Assignee: issues@jmeter.apache.org
Reporter: mateusdadalto@gmail.com
Target Milestone: JMETER_5.5
Created attachment 38317
--> https://bz.apache.org/bugzilla/attachment.cgi?id=38317&action=edit
A sample project to reproduce the bug
I'm trying to set my body based on what is in a file and it fails saying the
JSON is invalid. But when I set the request body manually the same content the
request works. In the results tree view I can see that the only difference is
that the manual request is "encoded", it has /n instead of visual newlines.
Steps to reproduce:
-1: Download and open the .jmx attached to this bug
-2: Create a file with the content being the body from the first request ("With
Body Set Manually")
-3: change the path on the second request ("With Body From File") to your file
path
-4: Run and see in the View Results Tree that the first one works and the
second one fails
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 66122] Error when using __FileToString to set GraphQL request body
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66122
--- Comment #1 from Felix Schumacher <fe...@internetallee.de> ---
I can reproduce the problem with JMeter 5.5 on Linux. Thanks for the detailed
bug description.
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 66122] Error when using __FileToString to set GraphQL request body
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66122
--- Comment #2 from Felix Schumacher <fe...@internetallee.de> ---
Well, after trying out to replace the newlines (\n) with the string values
"\n", it became clear to me, that you already found the solution yourself :)
When you are using giving the GraphQL Sampler the Query manually, JMeter knows,
that this is something, that has to be encoded for usage in JSON. If you store
the content in a file and include it, JMeter does not know, if it should do the
encoding, or not and does not do the encoding itself.
The POST data without the escaped newlines will break the JSON stuff.
So for the moment, you will have to encode it yourself (might be done with a
Pre-Processor). I am not sure, whether we can safely do the escaping
automatically. Will have to think about it (not sorry, if someone else provides
a good solution :))
--
You are receiving this mail because:
You are the assignee for the bug.
[Bug 66122] Error when using __FileToString to set GraphQL request body
Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=66122
--- Comment #3 from Mateus Dadalto <ma...@gmail.com> ---
I see what you mean... This will happen with anything that either comes from a
function or it's stored in a variable. I still hope that this behavior gets
fixed in future versions (IMHO it is not a user-friendly behavior).
I just want to add that you'll have to deal with everything that might break a
JSON (graphQL syntax has quotes in places that can cause this). E.G.:
mutation {
createCustomerV2(
input: {
firstname: "Bob"
lastname: "Loblaw"
email: "bobloblaw2@example.com"
password: "b0bl0bl@w"
is_subscribed: true
}
) {
customer {
firstname
lastname
email
is_subscribed
}
}
}
---
For now the solution I came up with was to add a JSR223 PreProcessor and just
treat these cases myself. Here's the PreProcessor code in case someone needs
it.
def content = new File(vars.get('fileName')).text;
vars.put('queryContent', content.replaceAll(/(\r\n|\r|\n)/,
/\\n/).replaceAll(/"/, /\\"/))
--
You are receiving this mail because:
You are the assignee for the bug.