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 2016/03/09 07:57:28 UTC

[Bug 59149] New: Bean Shell not able to parse JSON where some special characters are present in JSON Data(like # \)

https://bz.apache.org/bugzilla/show_bug.cgi?id=59149

            Bug ID: 59149
           Summary: Bean Shell not able to parse JSON where some special
                    characters are present in JSON Data(like # \)
           Product: JMeter
           Version: 2.13
          Hardware: Macintosh
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HTTP
          Assignee: issues@jmeter.apache.org
          Reporter: balendra.pathak@gmail.com

Created attachment 33652
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=33652&action=edit
JMX file and data file been used is given as an attachment

I am able to parse JSON without any issue while running same java code in
eclipse .But same code on Bean Shell Post processor gives error in log.Below
are data and log file given with sample code tried on both eclipse and Bean
Shell post processor.

JSON Data where parsing fails:
"streamProfiles": [{

        "mediaPlaylist":
"#EXT-X-STREAM-INF:BANDWIDTH=565400,AVERAGE-BANDWIDTH=565400,CODECS=\"avc1.77.30,mp4a.40.2\",RESOLUTION=640x360",
        "channels": 0,
        "mime_type": "audio\/x-mpegurl",
        "host":
"http:\/\/yahooios2-i.akamaihd.net\/hls\/live\/224964\/iosstream\/esports_us_main_highprofile\/master_514.m3u8",
    },  


Jmeter Log:
2016/03/08 12:05:02 INFO  - jmeter.util.BeanShellTestElement: Error in my
script Unexpected character (#) at position 0.
    at org.json.simple.parser.Yylex.yylex(Unknown Source)
    at org.json.simple.parser.JSONParser.nextToken(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at bsh.Reflect.invokeMethod(Reflect.java:134)
    at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
    at bsh.Name.invokeMethod(Name.java:858)
    at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
    at bsh.BSHCastExpression.eval(BSHCastExpression.java:60)
    at bsh.BSHAssignment.eval(BSHAssignment.java:77)
    at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
    at bsh.BSHBlock.eval(BSHBlock.java:80)
    at bsh.BSHBlock.eval(BSHBlock.java:46)
    at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
    at bsh.Interpreter.eval(Interpreter.java:645)
    at bsh.Interpreter.eval(Interpreter.java:739)
    at bsh.Interpreter.eval(Interpreter.java:728)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:170)
    at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:197)
    at
org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
    at
org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
    at
org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:750)
    at
org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:452)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
    at java.lang.Thread.run(Thread.java:745)

Another character which was creating issue while parsing:

2016/03/08 11:34:09 INFO  - jmeter.util.BeanShellTestElement: Error in my
script Unexpected character (\) at position 1.
    at org.json.simple.parser.Yylex.yylex(Unknown Source)
    at org.json.simple.parser.JSONParser.nextToken(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor40.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at bsh.Reflect.invokeMethod(Reflect.java:134)
    at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
    at bsh.Name.invokeMethod(Name.java:858)
    at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
    at bsh.BSHCastExpression.eval(BSHCastExpression.java:60)
    at bsh.BSHAssignment.eval(BSHAssignment.java:77)
    at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
    at bsh.BSHBlock.eval(BSHBlock.java:80)
    at bsh.BSHBlock.eval(BSHBlock.java:46)
    at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
    at bsh.Interpreter.eval(Interpreter.java:645)
    at bsh.Interpreter.eval(Interpreter.java:739)
    at bsh.Interpreter.eval(Interpreter.java:728)
    at sun.reflect.GeneratedMethodAccessor35.invoke(Unknown Source)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:170)
    at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:197)
    at
org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
    at
org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
    at
org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:750)
    at
org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:452)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
    at java.lang.Thread.run(Thread.java:745)

To Parse JSON Below jar been used:
json-simple-1.1.jar

and below is sample code:
in Bean shell:
import org.json.simple.JSONObject;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
#String jsonString = prev.getResponseDataAsString();

FileReader reader = new
FileReader("/Users/balendrapathak/my-app/src/main/java/com/mycompany/app/json.txt");

log.info("This is Output Data: ");
JSONParser jsonParser = new JSONParser();
                JSONObject jsonobj = null;
        try {
            jsonobj = (JSONObject) jsonParser.parse(reader);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            log.info("Error in my script", e);
            e.printStackTrace();
        }
        //System.out.println("This is object :"+jsonobj.toString());
        JSONObject obj= (JSONObject)jsonobj.get("query");
        JSONObject obj1= (JSONObject)obj.get("results");
        JSONArray objarr=(JSONArray) obj1.get("mediaObj");
        for(int i=0;i<objarr.size();i++){

            //System.out.println("Print all json oobject under mediaObj
:"+objarr.get(i).toString());
            JSONObject jsobj= (JSONObject) objarr.get(i);
            JSONArray ar=(JSONArray) jsobj.get("streamProfiles");
            JSONObject obj3= (JSONObject)ar.get(0);
            //System.out.println(obj3.get("host"));
            log.info("This is host extracted Data: "+host);

            }

Same code in eclipse runs properly.

Please help to understand if this is an issue or I need to do some
preprocessing before parsing.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 59149] Bean Shell not able to parse JSON where some special characters are present in JSON Data(like # \)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59149

Balendra <ba...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #2 from Balendra <ba...@gmail.com> ---
I think that was mistakenly left out # in script itself but its not able to
parse JSON .

The real Bean shell code:

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import java.lang.String;
import java.util.*;
import java.lang.Integer;
import org.json.simple.JSONObject;
import java.io.*;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
String jsonString = prev.getResponseDataAsString();



log.info("This is Output Data: "+jsonString);
JSONParser jsonParser = new JSONParser();
                JSONObject jsonobj = null;
        try {
            jsonobj = (JSONObject) jsonParser.parse(jsonString);
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            log.info("Error in my script", e);
            e.printStackTrace();
        }
        //System.out.println("This is object :"+jsonobj.toString());
        JSONObject obj= (JSONObject)jsonobj.get("query");
        JSONObject obj1= (JSONObject)obj.get("results");
        JSONArray objarr=(JSONArray) obj1.get("mediaObj");
        for(int i=0;i<objarr.size();i++){

            //System.out.println("Print all json oobject under mediaObj
:"+objarr.get(i).toString());
            JSONObject jsobj= (JSONObject) objarr.get(i);
            JSONArray ar=(JSONArray) jsobj.get("streamProfiles");
            JSONObject obj3= (JSONObject)ar.get(0);
            //System.out.println(obj3.get("host"));
            log.info("This is host extracted Data: "+host);

            }


###### Log file:
2016/03/09 08:48:06 INFO  - jmeter.util.BeanShellTestElement: Error in my
script Unexpected character (#) at position 0.
    at org.json.simple.parser.Yylex.yylex(Unknown Source)
    at org.json.simple.parser.JSONParser.nextToken(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at org.json.simple.parser.JSONParser.parse(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at bsh.Reflect.invokeMethod(Reflect.java:134)
    at bsh.Reflect.invokeObjectMethod(Reflect.java:80)
    at bsh.Name.invokeMethod(Name.java:858)
    at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)
    at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)
    at bsh.BSHCastExpression.eval(BSHCastExpression.java:60)
    at bsh.BSHAssignment.eval(BSHAssignment.java:77)
    at bsh.BSHBlock.evalBlock(BSHBlock.java:130)
    at bsh.BSHBlock.eval(BSHBlock.java:80)
    at bsh.BSHBlock.eval(BSHBlock.java:46)
    at bsh.BSHTryStatement.eval(BSHTryStatement.java:86)
    at bsh.Interpreter.eval(Interpreter.java:645)
    at bsh.Interpreter.eval(Interpreter.java:739)
    at bsh.Interpreter.eval(Interpreter.java:728)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:170)
    at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:197)
    at
org.apache.jmeter.util.BeanShellTestElement.processFileOrScript(BeanShellTestElement.java:151)
    at
org.apache.jmeter.extractor.BeanShellPostProcessor.process(BeanShellPostProcessor.java:64)
    at
org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:750)
    at
org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:452)
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
    at java.lang.Thread.run(Thread.java:745)

2016/03/09 08:48:06 ERROR - jmeter.util.BeanShellInterpreter: Error invoking
bsh method: eval    Sourced file: inline evaluation of: ``import
org.json.simple.JSONArray; import org.json.simple.JSONObject; import org. . . .
'' : Typed variable declaration 


Just import the jmx given and paste above Bean Shell Post processor.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 59149] Bean Shell not able to parse JSON where some special characters are present in JSON Data(like # \)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59149

Sebb <se...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Sebb <se...@apache.org> ---
The problem is not in Beanshell or JMeter.

It's clear from the stack trace that the error was detected by the JSON
library.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 59149] Bean Shell not able to parse JSON where some special characters are present in JSON Data(like # \)

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=59149

Sebb <se...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
                 OS|                            |All
             Status|NEW                         |RESOLVED

--- Comment #1 from Sebb <se...@apache.org> ---
The error message is:

2016/03/08 12:05:02 INFO  - jmeter.util.BeanShellTestElement: Error in my
script Unexpected character (#) at position 0.


The BeanShell script contains:

.
.
import java.io.IOException;
#String jsonString = prev.getResponseDataAsString();

-- 
You are receiving this mail because:
You are the assignee for the bug.