jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Felix Schumacher <felix.schumac...@internetallee.de>
Subject Re: Using JSON.stringify() in JSR223 preprocessor
Date Sun, 11 Jan 2015 12:56:32 GMT
Am 11.01.2015 um 13:53 schrieb Felix Schumacher:
> Am 11.01.2015 um 13:10 schrieb Shmuel Krakower:
>> Hi,
>> Maybe I'm taking the wrong approach here but I'm trying to create JSON
>> object nicely with a JSR223 preprocessor and provide it to the actual 
>> HTTP
>> Sampler.
>>
>> As JSON is native to java script, I am trying to use the javascipt 
>> language
>> in the JSR233 pre-proc.
>> All is fine, but once I put the resulting JSON into a variable using
>> vars.put() it is rendered as [Object][Object] in the actual HTTP 
>> sampler.
>>
>> When I try to stringify the object prior to saving it with the
>> JSON.stringify() I get the following error:
>>
>> ERROR - jmeter.modifiers.JSR223PreProcessor: Problem in JSR223 script
>>   javax.script.ScriptException:
>> sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "JSON" is
>> not defined. (<Unknown source>#6) in <Unknown source> at line number
6
>> at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
>> at com.sun.script.javascript.RhinoScriptEngine.eval(Unknown Source)
>> at javax.script.AbstractScriptEngine.eval(Unknown Source)
>> at
>> org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:202)

>>
>> at
>> org.apache.jmeter.modifiers.JSR223PreProcessor.process(JSR223PreProcessor.java:42)

>>
>> at
>> org.apache.jmeter.threads.JMeterThread.runPreProcessors(JMeterThread.java:749) 
>>
>> at
>> org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:414) 
>>
>> at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:257)
>> at java.lang.Thread.run(Unknown Source)
>>
>> So obviously JSON is not defined in the scope of the pre processor.
>>
>>
>> Any ideas on how to create nicely JSON objects in jmeter?
>> (As I don't have the same json payload / structure, I must dynamically
>> create it inside the script)
> There was a thread recently about this behavior (title: "JSON to 
> string in javascript via BSF post processor, etc.? Seem to come across 
> a problem. A bug? Any help or tips?") where one tip was to add an 
> empty javascript string to the java string to coerce it into a 
> javascript string.
>
> The javascript engine will convert java strings to javascript strings, 
> if they are set directly on the context. The java string will not be 
> converted, if it is passed in through a Map (like the ctx variable).
>
> I have done a simple test to show this, which I try to attach to this 
> mail. To see the error, you have to remove the adding of the 
> javascript string ('' +).
Oops, I haven't read your mail carefully enough. If JSON is not defined 
in the interpreter, your interpreter is not new enough.

Do you use java6? I think the JSON object is only available in java7 and 
newer.

Regards
  Felix
>
> Regards
>  Felix
>
>>
>> Best,
>>
>>
>> Shmuel Krakower.
>> www.Beatsoo.org - re-use your jmeter scripts for application performance
>> monitoring from worldwide locations for free.
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message