修改使用FASTJSON做依赖包,解决产生的部分bug
This commit is contained in:
parent
c551f80b1a
commit
499d440e5e
15
pom.xml
15
pom.xml
|
@ -248,10 +248,9 @@
|
|||
<version>2.3.26-incubating</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<version>2.4</version>
|
||||
<classifier>jdk15</classifier>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
@ -264,9 +263,9 @@
|
|||
<version>6.0.0-BETA2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.4</version>
|
||||
</dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package luckyclient.planapi.api;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import luckyclient.planapi.entity.ProjectCase;
|
||||
import luckyclient.planapi.entity.ProjectCasesteps;
|
||||
import luckyclient.planapi.entity.PublicCaseParams;
|
||||
import luckyclient.planapi.entity.TestTaskexcute;
|
||||
import luckyclient.publicclass.remoterinterface.HttpRequest;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import net.sf.json.JsonConfig;
|
||||
|
||||
|
||||
/**
|
||||
* =================================================================
|
||||
|
@ -30,13 +31,13 @@ public class GetServerAPI {
|
|||
* @param planid
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<ProjectCase> getCasesbyplanid(int planid) {
|
||||
String result = HttpRequest.loadJSON("/projectPlanCase/cgetcasebyplanid.do?planid=" + planid);
|
||||
JSONObject jsonObject = JSONObject.fromObject(result.toString());
|
||||
JSONArray jsonarr = JSONArray.fromObject(jsonObject.getString("cases"));
|
||||
List<ProjectCase> list = JSONArray.toList(jsonarr, new ProjectCase(), new JsonConfig());
|
||||
return list;
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
|
||||
List<ProjectCase> caseslist = new ArrayList<ProjectCase>();
|
||||
caseslist = JSONObject.parseArray(jsonObject.getString("cases"), ProjectCase.class);
|
||||
return caseslist;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,13 +45,13 @@ public class GetServerAPI {
|
|||
* @param name
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<ProjectCase> getCasesbyplanname(String name) {
|
||||
String result = HttpRequest.loadJSON("/projectPlanCase/cgetcasebyplanname.do?name=" + name);
|
||||
JSONObject jsonObject = JSONObject.fromObject(result.toString());
|
||||
JSONArray jsonarr = JSONArray.fromObject(jsonObject.getString("cases"));
|
||||
List<ProjectCase> list = JSONArray.toList(jsonarr, new ProjectCase(), new JsonConfig());
|
||||
return list;
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
|
||||
List<ProjectCase> caseslist = new ArrayList<ProjectCase>();
|
||||
caseslist = JSONObject.parseArray(jsonObject.getString("cases"), ProjectCase.class);
|
||||
return caseslist;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -58,13 +59,13 @@ public class GetServerAPI {
|
|||
* @param caseid
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static List<ProjectCasesteps> getStepsbycaseid(int caseid) {
|
||||
String result = HttpRequest.loadJSON("/projectCasesteps/cgetStepsByCase.do?caseid=" + caseid);
|
||||
JSONObject jsonObject = JSONObject.fromObject(result.toString());
|
||||
JSONArray jsonarr = JSONArray.fromObject(jsonObject.getString("steps"));
|
||||
List<ProjectCasesteps> list = JSONArray.toList(jsonarr, new ProjectCasesteps(), new JsonConfig());
|
||||
return list;
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
|
||||
List<ProjectCasesteps> stepslist = new ArrayList<ProjectCasesteps>();
|
||||
stepslist = JSONObject.parseArray(jsonObject.getString("steps"), ProjectCasesteps.class);
|
||||
return stepslist;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,8 +75,7 @@ public class GetServerAPI {
|
|||
*/
|
||||
public static TestTaskexcute cgetTaskbyid(int taskid) {
|
||||
String result = HttpRequest.loadJSON("/tastExecute/cgettaskbyid.do?taskid=" + taskid);
|
||||
JSONObject jsonObject = JSONObject.fromObject(result.toString());
|
||||
TestTaskexcute task = (TestTaskexcute) JSONObject.toBean(jsonObject, TestTaskexcute.class);
|
||||
TestTaskexcute task = JSONObject.parseObject(result, TestTaskexcute.class);
|
||||
return task;
|
||||
}
|
||||
|
||||
|
@ -86,8 +86,7 @@ public class GetServerAPI {
|
|||
*/
|
||||
public static ProjectCase cgetCaseBysign(String sign) {
|
||||
String result = HttpRequest.loadJSON("/projectCase/cgetcasebysign.do?sign=" + sign);
|
||||
JSONObject jsonObject = JSONObject.fromObject(result.toString());
|
||||
ProjectCase pc = (ProjectCase) JSONObject.toBean(jsonObject, ProjectCase.class);
|
||||
ProjectCase pc = JSONObject.parseObject(result, ProjectCase.class);
|
||||
return pc;
|
||||
}
|
||||
|
||||
|
@ -98,11 +97,11 @@ public class GetServerAPI {
|
|||
*/
|
||||
public static List<PublicCaseParams> cgetParamsByProjectid(String projectid) {
|
||||
String result = HttpRequest.loadJSON("/publicCaseParams/cgetParamsByProjectid.do?projectid="+projectid);
|
||||
JSONObject jsonObject = JSONObject.fromObject(result.toString());
|
||||
JSONArray jsonarr = JSONArray.fromObject(jsonObject.getString("params"));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<PublicCaseParams> list = JSONArray.toList(jsonarr, new PublicCaseParams(), new JsonConfig());
|
||||
return list;
|
||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||
|
||||
List<PublicCaseParams> paramslist = new ArrayList<PublicCaseParams>();
|
||||
paramslist = JSONObject.parseArray(jsonObject.getString("params"), PublicCaseParams.class);
|
||||
return paramslist;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,17 +2,18 @@ package luckyclient.publicclass;
|
|||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import luckyclient.planapi.entity.ProjectProtocolTemplate;
|
||||
import luckyclient.planapi.entity.ProjectTemplateParams;
|
||||
import luckyclient.publicclass.remoterinterface.HttpClientHelper;
|
||||
import luckyclient.publicclass.remoterinterface.HttpRequest;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import net.sf.json.JsonConfig;
|
||||
|
||||
/**
|
||||
* =================================================================
|
||||
|
@ -63,27 +64,16 @@ public class InvokeMethod {
|
|||
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "】,ID【" + templateidstr + "】发送HTTP请求!");
|
||||
|
||||
String httpppt = HttpRequest.loadJSON("/projectprotocolTemplate/cgetPTemplateById.do?templateid=" + templateidstr);
|
||||
JSONObject jsonpptObject = JSONObject.fromObject(httpppt);
|
||||
ProjectProtocolTemplate ppt = (ProjectProtocolTemplate) JSONObject.toBean(jsonpptObject,
|
||||
ProjectProtocolTemplate.class);
|
||||
ProjectProtocolTemplate ppt = JSONObject.parseObject(httpppt, ProjectProtocolTemplate.class);
|
||||
if (null == ppt) {
|
||||
luckyclient.publicclass.LogUtil.APP.error("协议模板为空,请检查用例使用的协议模板是否已经删除!");
|
||||
return "协议模板为空,请确认用例使用的模板是否已经删除!";
|
||||
}
|
||||
|
||||
String httpptp = HttpRequest.loadJSON("/projectTemplateParams/cgetParamsByTemplate.do?templateid=" + templateidstr);
|
||||
JSONObject jsonptpObject = JSONObject.fromObject(httpptp);
|
||||
JSONArray jsonarr = JSONArray.fromObject(jsonptpObject.getString("params"));
|
||||
|
||||
//处理json-lib 2.4版本当遇到json格式字符串时,把它当成对象处理的bug
|
||||
for (int i = 0; i < jsonarr.size(); i++) {
|
||||
JSONObject tempobj = (JSONObject) jsonarr.get(i);
|
||||
String str = tempobj.get("param").toString();
|
||||
if (str.length() > 0 && "[".equals(str.substring(0, 1)) && "]".equals(str.substring(str.length() - 1))) {
|
||||
tempobj.element("param", "***" + str);
|
||||
jsonarr.set(i, tempobj);
|
||||
}
|
||||
}
|
||||
JSONObject jsonptpObject = JSONObject.parseObject(httpptp);
|
||||
List<ProjectTemplateParams> paramslist = new ArrayList<ProjectTemplateParams>();
|
||||
paramslist = JSONObject.parseArray(jsonptpObject.getString("params"), ProjectTemplateParams.class);
|
||||
|
||||
//处理头域
|
||||
Map<String, String> headmsg = new HashMap<>(0);
|
||||
|
@ -100,9 +90,6 @@ public class InvokeMethod {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ProjectTemplateParams> paramslist = JSONArray.toList(jsonarr, new ProjectTemplateParams(),
|
||||
new JsonConfig());
|
||||
//处理更换参数
|
||||
if (null != getParameterValues) {
|
||||
String booleanheadmsg = "headmsg(";
|
||||
|
@ -128,18 +115,15 @@ public class InvokeMethod {
|
|||
//处理参数
|
||||
Map<String, Object> params = new HashMap<String, Object>(0);
|
||||
for (ProjectTemplateParams ptp : paramslist) {
|
||||
if (ptp.getParam().contains("***[") && "***[".equals(ptp.getParam().substring(0, 4))) {
|
||||
ptp.setParam(ptp.getParam().substring(3));
|
||||
}
|
||||
//处理参数对象
|
||||
if (ptp.getParamtype() == 1) {
|
||||
String tempparam = ptp.getParam().replace(""", "\"");
|
||||
JSONObject json = JSONObject.fromObject(tempparam);
|
||||
JSONObject json = JSONObject.parseObject(tempparam);
|
||||
params.put(ptp.getParamname().replace(""", "\""), json);
|
||||
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 JSONObject类型参数值:【" + json.toString() + "】");
|
||||
} else if (ptp.getParamtype() == 2) {
|
||||
String tempparam = ptp.getParam().replace(""", "\"");
|
||||
JSONArray jarr = JSONArray.fromObject(tempparam);
|
||||
JSONArray jarr = JSONArray.parseArray(tempparam);
|
||||
params.put(ptp.getParamname().replace(""", "\""), jarr);
|
||||
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 JSONArray类型参数值:【" + jarr.toString() + "】");
|
||||
} else if (ptp.getParamtype() == 3) {
|
||||
|
@ -199,24 +183,13 @@ public class InvokeMethod {
|
|||
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "】 ID:【" + templateidstr + "】 发送SOCKET请求!");
|
||||
|
||||
String httpppt = HttpRequest.loadJSON("/projectprotocolTemplate/cgetPTemplateById.do?templateid=" + templateidstr);
|
||||
JSONObject jsonpptObject = JSONObject.fromObject(httpppt);
|
||||
ProjectProtocolTemplate ppt = (ProjectProtocolTemplate) JSONObject.toBean(jsonpptObject,
|
||||
ProjectProtocolTemplate.class);
|
||||
ProjectProtocolTemplate ppt = JSONObject.parseObject(httpppt,ProjectProtocolTemplate.class);
|
||||
|
||||
String httpptp = HttpRequest.loadJSON("/projectTemplateParams/cgetParamsByTemplate.do?templateid=" + templateidstr);
|
||||
JSONObject jsonptpObject = JSONObject.fromObject(httpptp);
|
||||
JSONArray jsonarr = JSONArray.fromObject(jsonptpObject.getString("params"));
|
||||
|
||||
//处理json-lib 2.4版本当遇到json格式字符串时,把它当成对象处理的bug
|
||||
for (int i = 0; i < jsonarr.size(); i++) {
|
||||
JSONObject tempobj = (JSONObject) jsonarr.get(i);
|
||||
String str = tempobj.get("param").toString();
|
||||
if (str.length() > 0 && "[".equals(str.substring(0, 1)) && "]".equals(str.substring(str.length() - 1))) {
|
||||
tempobj.element("param", "***" + str);
|
||||
jsonarr.set(i, tempobj);
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject jsonptpObject = JSONObject.parseObject(httpptp);
|
||||
List<ProjectTemplateParams> paramslist = new ArrayList<ProjectTemplateParams>();
|
||||
paramslist = JSONObject.parseArray(jsonptpObject.getString("params"), ProjectTemplateParams.class);
|
||||
|
||||
//处理头域
|
||||
Map<String, String> headmsg = new HashMap<String, String>(0);
|
||||
if (null != ppt.getHeadmsg() && !ppt.getHeadmsg().equals("") && ppt.getHeadmsg().indexOf("=") > 0) {
|
||||
|
@ -232,8 +205,6 @@ public class InvokeMethod {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ProjectTemplateParams> paramslist = JSONArray.toList(jsonarr, new ProjectTemplateParams(), new JsonConfig());
|
||||
//处理更换参数
|
||||
if (null != getParameterValues) {
|
||||
String booleanheadmsg = "headmsg(";
|
||||
|
@ -258,17 +229,14 @@ public class InvokeMethod {
|
|||
}
|
||||
Map<String, Object> params = new HashMap<String, Object>(0);
|
||||
for (ProjectTemplateParams ptp : paramslist) {
|
||||
if (ptp.getParam().contains("***[") && "***[".equals(ptp.getParam().substring(0, 4))) {
|
||||
ptp.setParam(ptp.getParam().substring(3));
|
||||
}
|
||||
//处理参数对象
|
||||
if (ptp.getParamtype() == 1) {
|
||||
String tempparam = ptp.getParam().replace(""", "\"");
|
||||
JSONObject json = JSONObject.fromObject(tempparam);
|
||||
JSONObject json = JSONObject.parseObject(tempparam);
|
||||
params.put(ptp.getParamname().replace(""", "\""), json);
|
||||
} else if (ptp.getParamtype() == 2) {
|
||||
String tempparam = ptp.getParam().replace(""", "\"");
|
||||
JSONArray jarr = JSONArray.fromObject(tempparam);
|
||||
JSONArray jarr = JSONArray.parseArray(tempparam);
|
||||
params.put(ptp.getParamname().replace(""", "\""), jarr);
|
||||
} else if (ptp.getParamtype() == 3) {
|
||||
String tempparam = ptp.getParam().replace(""", "\"");
|
||||
|
|
|
@ -51,7 +51,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.ssl.SSLContexts;
|
||||
|
||||
import net.sf.json.JSONObject;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
/**
|
||||
* =================================================================
|
||||
|
@ -523,9 +523,9 @@ public class HttpClientHelper {
|
|||
BufferedReader br = null;
|
||||
try {
|
||||
if(params.size()>0){
|
||||
JSONObject jsonObject = JSONObject.fromObject(params);
|
||||
luckyclient.publicclass.LogUtil.APP.info("设置HTTPPostJson参数信息...【"+jsonObject.toString()+"】");
|
||||
StringEntity entity = new StringEntity(jsonObject.toString(),charset);
|
||||
String jsonString = JSON.toJSONString(params);
|
||||
luckyclient.publicclass.LogUtil.APP.info("设置HTTPPostJson参数信息...【"+jsonString+"】");
|
||||
StringEntity entity = new StringEntity(jsonString,charset);
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
|
||||
|
@ -1170,9 +1170,9 @@ public class HttpClientHelper {
|
|||
BufferedReader br = null;
|
||||
try {
|
||||
if(params.size()>0){
|
||||
JSONObject jsonObject = JSONObject.fromObject(params);
|
||||
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientPutJson参数信息...【"+jsonObject.toString()+"】");
|
||||
StringEntity entity = new StringEntity(jsonObject.toString(),charset);
|
||||
String jsonString = JSON.toJSONString(params);
|
||||
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientPutJson参数信息...【"+jsonString+"】");
|
||||
StringEntity entity = new StringEntity(jsonString,charset);
|
||||
httpput.setEntity(entity);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue