标签:form for view 文件 需要 ref 源码 utf-8 spl
修改jmeter源码,可能会对其他格式的responseData有一定影响,图片或者其他
在 ListenerNotifier 类中找到 notifyListeners 方法,在其下面添加如下代码:
1 if(res.getResult().getURL()!= null) { 2 try { 3 String s2 = new String(res.getResult().getResponseData(), "UTF-8"); 4 char aChar; 5 int len = s2.length(); 6 StringBuffer outBuffer = new StringBuffer(len); 7 for (int x = 0; x < len; ) { 8 aChar = s2.charAt(x++); 9 if (aChar == ‘\\‘) { 10 aChar = s2.charAt(x++); 11 if (aChar == ‘u‘) { 12 int value = 0; 13 for (int i = 0; i < 4; i++) { 14 aChar = s2.charAt(x++); 15 switch (aChar) { 16 case ‘0‘: 17 case ‘1‘: 18 case ‘2‘: 19 case ‘3‘: 20 case ‘4‘: 21 case ‘5‘: 22 case ‘6‘: 23 case ‘7‘: 24 case ‘8‘: 25 case ‘9‘: 26 value = (value << 4) + aChar - ‘0‘; 27 break; 28 case ‘a‘: 29 case ‘b‘: 30 case ‘c‘: 31 case ‘d‘: 32 case ‘e‘: 33 case ‘f‘: 34 value = (value << 4) + 10 + aChar - ‘a‘; 35 break; 36 case ‘A‘: 37 case ‘B‘: 38 case ‘C‘: 39 case ‘D‘: 40 case ‘E‘: 41 case ‘F‘: 42 value = (value << 4) + 10 + aChar - ‘A‘; 43 break; 44 default: 45 throw new IllegalArgumentException( 46 "Malformed \\uxxxx encoding."); 47 } 48 } 49 outBuffer.append((char) value); 50 } else { 51 if (aChar == ‘t‘) 52 aChar = ‘\t‘; 53 else if (aChar == ‘r‘) 54 aChar = ‘\r‘; 55 else if (aChar == ‘n‘) 56 aChar = ‘\n‘; 57 else if (aChar == ‘f‘) 58 aChar = ‘\f‘; 59 outBuffer.append(aChar); 60 } 61 } else 62 outBuffer.append(aChar); 63 } 64 //-----------------以上内容为转码过程--------------------------- 65 //将转成中文的响应结果在查看结果树中显示 66 67 res.getResult().setResponseData(outBuffer.toString()); 68 String s3 = URLDecoder.decode(res.getResult().getURL().toString()); 69 try { 70 res.getResult().setURL(new URL(s3)); 71 } catch (MalformedURLException e) { 72 e.printStackTrace(); 73 } 74 75 76 } catch (UnsupportedEncodingException e) { 77 e.printStackTrace(); 78 } 79 }
在此处修改,保存的jtl文件、结果树展示修改为中文,后续使用jtl数据做report时正常取值即可
只有http请求需要做此处理,因此在开始判断了URL是否未NULL;
request请求中encode转码,未转码前部分显示%5B等,转码后正常显示为[""]
responseData数据Unicode编码,转码前显示/u0213,转码后正常显示中文
responseData中文转码部分为网上使用beanshell添加部分代码,由于不想每个请求都加shell,逐修改了源码,目前还未发现其他影响。
PS:
1.需修改jmeter/bin/目录下jmeter.properties文件中sampleresult.default.encoding=utf-8
2.结果树返回值中文显示"??"是乱码,即sampleresult.default.encoding参数未修改,返回值显示"/u023"这种为Unicode编码
3.快捷解决Unicode编码问题可参考添加beanshell:https://www.cnblogs.com/liuchunxiao83/p/6634524.html
标签:form for view 文件 需要 ref 源码 utf-8 spl
原文地址:https://www.cnblogs.com/lanrumeng/p/9377103.html