You've nailed it, thanks Felix, I was using java 6, not sure why I still
have it around...
Switching to java 7 resolved the issue!

Shmuel Krakower.
www.Beatsoo.org - re-use your jmeter scripts for application performance
monitoring from worldwide locations for free.

On Sun, Jan 11, 2015 at 2:56 PM, Felix Schumacher <
[email protected]> wrote:

> 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: [email protected]
>> For additional commands, e-mail: [email protected]
>>
>
>

Reply via email to