解决当遇到HTTP响应有响应头跟响应码时,转换JSON失败的Bug
This commit is contained in:
parent
532243b15e
commit
9e1de099da
|
@ -2,6 +2,7 @@ package luckyclient.caserun.publicdispose;
|
|||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import luckyclient.publicclass.Constants;
|
||||
import luckyclient.publicclass.LogUtil;
|
||||
|
||||
/**
|
||||
|
@ -28,6 +29,17 @@ public class ActionManageForSteps {
|
|||
LogUtil.APP.info("Action(动作)无需处理......");
|
||||
return testresult;
|
||||
}
|
||||
|
||||
//È¥³ý²âÊÔÏìӦͷÓòÏûÏ¢
|
||||
if(testresult.startsWith(Constants.RESPONSE_HEAD)){
|
||||
testresult = testresult.substring(testresult.indexOf(Constants.RESPONSE_END)+1);
|
||||
}
|
||||
|
||||
//È¥³ý²âÊÔÏìӦͷÓòÏûÏ¢
|
||||
if(testresult.startsWith(Constants.RESPONSE_CODE)){
|
||||
testresult = testresult.substring(testresult.indexOf(Constants.RESPONSE_END)+1);
|
||||
}
|
||||
|
||||
stepsaction=stepsaction.trim();
|
||||
String[] temp=stepsaction.split("\\|",-1);
|
||||
for(String actionorder:temp){
|
||||
|
@ -64,4 +76,9 @@ public class ActionManageForSteps {
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String testresult = Constants.RESPONSE_HEAD+"gfdssa"+Constants.RESPONSE_END+"21111"+Constants.RESPONSE_END+"111";
|
||||
testresult = testresult.substring(testresult.indexOf(Constants.RESPONSE_END)+1);
|
||||
System.out.println(testresult);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.alibaba.fastjson.parser.Feature;
|
|||
import com.jayway.jsonpath.JsonPath;
|
||||
import com.jayway.jsonpath.PathNotFoundException;
|
||||
|
||||
import luckyclient.publicclass.Constants;
|
||||
import luckyclient.publicclass.LogUtil;
|
||||
|
||||
/**
|
||||
|
@ -380,6 +381,16 @@ public class SubString {
|
|||
type=expressionParams.substring(0,expressionParams.indexOf("["));
|
||||
expression=expressionParams.substring(expressionParams.indexOf("[")+1, expressionParams.lastIndexOf("]"));
|
||||
if("list".equals(type.toLowerCase())){
|
||||
//È¥³ý²âÊÔÏìӦͷÓòÏûÏ¢
|
||||
if(jsonString.startsWith(Constants.RESPONSE_HEAD)){
|
||||
jsonString = jsonString.substring(jsonString.indexOf(Constants.RESPONSE_END)+1);
|
||||
}
|
||||
|
||||
//È¥³ý²âÊÔÏìӦͷÓòÏûÏ¢
|
||||
if(jsonString.startsWith(Constants.RESPONSE_CODE)){
|
||||
jsonString = jsonString.substring(jsonString.indexOf(Constants.RESPONSE_END)+1);
|
||||
}
|
||||
|
||||
List<Object> list = JsonPath.parse(jsonString).read(expression);
|
||||
jsonString="";
|
||||
for(Object result:list){
|
||||
|
|
|
@ -10,7 +10,7 @@ package luckyclient.publicclass;
|
|||
* @date 2019年10月22日
|
||||
*/
|
||||
public class Constants {
|
||||
/**
|
||||
/******************预期结果常量定义*************************
|
||||
* 预期结果赋值符---赋值单条用例作用域变量
|
||||
*/
|
||||
public static final String ASSIGNMENT_SIGN = "$=";
|
||||
|
@ -31,4 +31,17 @@ public class Constants {
|
|||
*/
|
||||
public static final String JSONPATH_SIGN = "$JP#";
|
||||
|
||||
|
||||
/************************HTTP 返回结果头域 响应码分隔符定义***************************
|
||||
* HTTP测试返回结果 是否接收头域
|
||||
*/
|
||||
public static final String RESPONSE_HEAD = "RESPONSE_HEAD:【";
|
||||
/**
|
||||
* HTTP测试返回结果 是否接收响应码
|
||||
*/
|
||||
public static final String RESPONSE_CODE = "RESPONSE_CODE:【";
|
||||
/**
|
||||
* HTTP测试返回结果 尾部链接符
|
||||
*/
|
||||
public static final String RESPONSE_END = "】 ";
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ import org.apache.http.util.EntityUtils;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import luckyclient.publicclass.Constants;
|
||||
import luckyclient.publicclass.LogUtil;
|
||||
import luckyclient.serverapi.entity.ProjectProtocolTemplate;
|
||||
|
||||
|
@ -148,10 +149,10 @@ public class HttpClientHelper {
|
|||
if(1==responsehead){
|
||||
Map<String, List<String>> headmsgstr=con.getHeaderFields();
|
||||
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(headmsgstr));
|
||||
resultBuffer.append("RESPONSE_HEAD:¡¾"+itemJSONObj+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_HEAD+itemJSONObj+Constants.RESPONSE_END);
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+con.getResponseCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+con.getResponseCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
if (contentLength > 0||"chunked".equals(con.getHeaderField("Transfer-Encoding"))) {
|
||||
br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
|
||||
|
@ -280,10 +281,10 @@ public class HttpClientHelper {
|
|||
if(1==responsehead){
|
||||
Map<String, List<String>> headmsgstr=con.getHeaderFields();
|
||||
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(headmsgstr));
|
||||
resultBuffer.append("RESPONSE_HEAD:¡¾"+itemJSONObj+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_HEAD+itemJSONObj+Constants.RESPONSE_END);
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+con.getHeaderField(null)+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+con.getHeaderField(null)+Constants.RESPONSE_END);
|
||||
}
|
||||
if (contentLength >= 0||"chunked".equals(con.getHeaderField("Transfer-Encoding"))) {
|
||||
br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
|
||||
|
@ -382,10 +383,10 @@ public class HttpClientHelper {
|
|||
if(1==responsehead){
|
||||
Map<String, List<String>> headmsgstr=con.getHeaderFields();
|
||||
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(headmsgstr));
|
||||
resultBuffer.append("RESPONSE_HEAD:¡¾"+itemJSONObj+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_HEAD+itemJSONObj+Constants.RESPONSE_END);
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+con.getResponseCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+con.getResponseCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
InputStream is = con.getInputStream();
|
||||
os = new FileOutputStream(fileSavePath);
|
||||
|
@ -495,10 +496,10 @@ public class HttpClientHelper {
|
|||
if(1==responsehead){
|
||||
Map<String, List<String>> headmsgstr=con.getHeaderFields();
|
||||
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(headmsgstr));
|
||||
resultBuffer.append("RESPONSE_HEAD:¡¾"+itemJSONObj+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_HEAD+itemJSONObj+Constants.RESPONSE_END);
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+con.getResponseCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+con.getResponseCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
|
||||
String temp;
|
||||
|
@ -599,10 +600,10 @@ public class HttpClientHelper {
|
|||
if(1==responsehead){
|
||||
Map<String, List<String>> headmsgstr=con.getHeaderFields();
|
||||
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(headmsgstr));
|
||||
resultBuffer.append("RESPONSE_HEAD:¡¾"+itemJSONObj+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_HEAD+itemJSONObj+Constants.RESPONSE_END);
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+con.getHeaderField(null)+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+con.getHeaderField(null)+Constants.RESPONSE_END);
|
||||
}
|
||||
br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
|
||||
String temp;
|
||||
|
@ -701,7 +702,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
if(null!=response.getEntity()){
|
||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
|
||||
|
@ -799,7 +800,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
|
||||
String temp;
|
||||
|
@ -908,7 +909,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
|
||||
String temp;
|
||||
|
@ -1019,7 +1020,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
while ((temp = br.readLine()) != null) {
|
||||
resultBuffer.append(temp);
|
||||
|
@ -1403,10 +1404,10 @@ public class HttpClientHelper {
|
|||
if(1==responsehead){
|
||||
Map<String, List<String>> headmsgstr=con.getHeaderFields();
|
||||
JSONObject itemJSONObj = JSONObject.parseObject(JSON.toJSONString(headmsgstr));
|
||||
resultBuffer.append("RESPONSE_HEAD:¡¾"+itemJSONObj+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_HEAD+itemJSONObj+Constants.RESPONSE_END);
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+con.getResponseCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+con.getResponseCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
if (null != con.getHeaderField("Content-Length") || null != con.getHeaderField("Transfer-Encoding")) {
|
||||
br = new BufferedReader(new InputStreamReader(con.getInputStream(), charset));
|
||||
|
@ -1526,7 +1527,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
if(null!=response.getEntity()){
|
||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
|
||||
|
@ -1626,7 +1627,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
if(null!=response.getEntity()){
|
||||
br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
|
||||
|
@ -1808,7 +1809,7 @@ public class HttpClientHelper {
|
|||
resultBuffer.delete(resultBuffer.length()-1, resultBuffer.length()).append("}¡¿ ");
|
||||
}
|
||||
if(1==responsecode){
|
||||
resultBuffer.append("RESPONSE_CODE:¡¾"+response.getStatusLine().getStatusCode()+"¡¿ ");
|
||||
resultBuffer.append(Constants.RESPONSE_CODE+response.getStatusLine().getStatusCode()+Constants.RESPONSE_END);
|
||||
}
|
||||
if(null!=response.getEntity()){
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
|
Loading…
Reference in New Issue