增加对纯文本方式HTTP请求的支持

优化部分error日志
优化部分方法的注解
This commit is contained in:
seagull 2018-08-13 10:16:53 +08:00
parent b7a4bfa6b9
commit b7029ffcf8
7 changed files with 490 additions and 166 deletions

View File

@ -323,7 +323,7 @@ public class EncapsulateOperation {
LogUtil.APP.info("执行JS...【" + operationValue + "】,返回的结果为:" + result);
} else {
result = "执行JS...【" + operationValue + "";
LogUtil.APP.info(result);
LogUtil.APP.info(result+"执行JS返回null或没有返回");
}
break;
case "gotodefaultcontent":

View File

@ -42,7 +42,7 @@ public class WebDriverInitialization{
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
webDriver = new InternetExplorerDriver();
}else{
luckyclient.publicclass.LogUtil.ERROR.info("当前操作系统无法进行IE浏览器的Web UI测试请选择火狐或是谷歌浏览器");
luckyclient.publicclass.LogUtil.APP.error("当前操作系统无法进行IE浏览器的Web UI测试请选择火狐或是谷歌浏览器");
}
}else if(drivertype==1){
if(os.startsWith("win")){
@ -67,11 +67,11 @@ public class WebDriverInitialization{
System.setProperty("webdriver.edge.driver",drivenpath+"MicrosoftWebDriver.exe");
webDriver = new EdgeDriver();
}else{
luckyclient.publicclass.LogUtil.ERROR.info("当前操作系统无法进行Edge浏览器的Web UI测试请选择火狐或是谷歌浏览器");
luckyclient.publicclass.LogUtil.APP.error("当前操作系统无法进行Edge浏览器的Web UI测试请选择火狐或是谷歌浏览器");
}
}else{
luckyclient.publicclass.LogUtil.ERROR.info("浏览器类型标识:"+drivertype);
luckyclient.publicclass.LogUtil.ERROR.info("获取到的浏览器类型标识未定义默认IE浏览器进行执行....");
luckyclient.publicclass.LogUtil.APP.error("浏览器类型标识:"+drivertype);
luckyclient.publicclass.LogUtil.APP.error("获取到的浏览器类型标识未定义默认IE浏览器进行执行....");
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
webDriver = new InternetExplorerDriver();
}

View File

@ -79,11 +79,11 @@ public class WebDriverAnalyticCase {
caselog.caseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepnum()),"");
}
}catch(Exception e) {
luckyclient.publicclass.LogUtil.ERROR.error("用例编号:"+projectcase.getSign()+" 步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!");
luckyclient.publicclass.LogUtil.APP.error("用例编号:"+projectcase.getSign()+" 步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!");
if(null!=caselog){
caselog.caseLogDetail(taskid, projectcase.getSign(),"步骤编号:"+step.getStepnum()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepnum()),"");
}
luckyclient.publicclass.LogUtil.ERROR.error(e,e);
luckyclient.publicclass.LogUtil.APP.error(e,e);
params.put("exception","用例编号:"+projectcase.getSign()+"|解析异常,用例步骤为空或是用例脚本错误!");
return params;
}

View File

@ -1,8 +1,13 @@
package luckyclient.publicclass;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
/**
* =================================================================
* 这是一个受限制的自由软件您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途也不允许对程序代码修改后以任何形式任何目的的再发布
@ -111,6 +116,84 @@ public class ChangString {
return pattern.matcher(str).matches();
}
/**
* 替换变量类型
* @param object
* @param str
* @return
*/
public static Object settype(Object object,String str){
if(object instanceof Integer){
return Integer.valueOf(str);
}else if(object instanceof Boolean){
return Boolean.valueOf(str);
}else if(object instanceof Long){
return Long.valueOf(str);
}else if(object instanceof Timestamp){
return Timestamp.valueOf(str);
}else if(object instanceof JSONObject){
return JSONObject.parseObject(str);
}else if(object instanceof JSONArray){
return JSONArray.parseArray(str);
}else{
return str;
}
}
/**
* 替换json中的变量
* @param json
* @param key
* @param value
* @return
*/
public static Map<String,String> changjson(String json, String key, String value) {
Map<String,String> map=new HashMap<String,String>(0);
map.put("boolean", "false");
map.put("json", json);
if (json.startsWith("{") && json.endsWith("}")) {
try {
JSONObject jsonStr = JSONObject.parseObject(json);
if(jsonStr.containsKey(key)){
jsonStr.put(key, settype(jsonStr.get(key),value));
map.put("boolean", "true");
map.put("json", jsonStr.toJSONString());
luckyclient.publicclass.LogUtil.APP.info("JSON字符串替换成功原始JSON:【"+json+"】 新JSON:【"+jsonStr.toJSONString()+"");
}
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("格式化成JSON异常请检查参数"+json,e);
return map;
}
} else if (json.startsWith("[") && json.endsWith("]")) {
try {
JSONArray jsonarr = JSONArray.parseArray(json);
JSONObject jsonStr=new JSONObject();
int index=0;
if(key.indexOf("[")>=0 && key.endsWith("]")){
index=Integer.valueOf(key.substring(key.lastIndexOf("[")+1,key.lastIndexOf("]")));
key=key.substring(0, key.lastIndexOf("["));
jsonStr = jsonarr.getJSONObject(index);
luckyclient.publicclass.LogUtil.APP.info("准备替换JSONArray中的参数值未检测到指定参数名序号默认替换第1个参数...");
}else{
jsonStr = jsonarr.getJSONObject(index);
luckyclient.publicclass.LogUtil.APP.info("准备替换JSONArray中的参数值替换指定第"+index+"个参数...");
}
if(jsonStr.containsKey(key)){
jsonStr.put(key, settype(jsonStr.get(key),value));
jsonarr.set(index, jsonStr);
map.put("boolean", "true");
map.put("json", jsonarr.toJSONString());
}
luckyclient.publicclass.LogUtil.APP.info("JSONARRAY字符串替换成功原始JSONARRAY:【"+json+"】 新JSONARRAY:【"+jsonarr.toJSONString()+"");
} catch (Exception e) {
luckyclient.publicclass.LogUtil.APP.error("格式化成JSONArray异常请检查参数"+json,e);
return map;
}
}
return map;
}
public static void main(String[] args) {
}

View File

@ -61,10 +61,10 @@ public class InvokeMethod {
} else if (steptype == 2) {
String templateidstr = action.substring(1, action.indexOf(""));
String templatenamestr = action.substring(action.indexOf("") + 1);
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID" + templateidstr + "】发送HTTP请求");
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID:" + templateidstr + "】发送HTTP请求");
String httpppt = HttpRequest.loadJSON("/projectprotocolTemplate/cgetPTemplateById.do?templateid=" + templateidstr);
ProjectProtocolTemplate ppt = JSONObject.parseObject(httpppt, ProjectProtocolTemplate.class);
ProjectProtocolTemplate ppt = JSONObject.parseObject(httpppt,ProjectProtocolTemplate.class);
if (null == ppt) {
luckyclient.publicclass.LogUtil.APP.error("协议模板为空,请检查用例使用的协议模板是否已经删除!");
return "协议模板为空,请确认用例使用的模板是否已经删除!";
@ -76,7 +76,7 @@ public class InvokeMethod {
paramslist = JSONObject.parseArray(jsonptpObject.getString("params"), ProjectTemplateParams.class);
//处理头域
Map<String, String> headmsg = new HashMap<>(0);
Map<String, String> headmsg = new HashMap<String, String>(0);
if (null != ppt.getHeadmsg() && !ppt.getHeadmsg().equals("") && ppt.getHeadmsg().indexOf("=") > 0) {
String headmsgtemp = ppt.getHeadmsg().replace("\\;", "!!!fhzh");
String[] temp = headmsgtemp.split(";", -1);
@ -107,11 +107,33 @@ public class InvokeMethod {
int replaceflag=0;
for (int i = 0; i < paramslist.size(); i++) {
ProjectTemplateParams ptp = paramslist.get(i);
if (ptp.getParamname().equals(key)) {
ptp.setParam(value);
paramslist.set(i, ptp);
replaceflag=1;
break;
if("_forTextJson".equals(ptp.getParamname())){
if(ptp.getParam().indexOf("\""+key+"\":")>=0){
Map<String,String> map=ChangString.changjson(ptp.getParam(), key, value);
if("true".equals(map.get("boolean"))){
ptp.setParam(map.get("json"));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("替换参数"+key+"完成...");
break;
}
}else if(ptp.getParam().indexOf(key)>=0){
ptp.setParam(ptp.getParam().replace(key, value));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParam()+"】中直接把【"+key+"】替换成【"+value+"】...");
break;
}else{
luckyclient.publicclass.LogUtil.APP.error("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
}
}else{
if (ptp.getParamname().equals(key)) {
ptp.setParam(value);
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"");
break;
}
}
}
if(replaceflag==0){
@ -193,11 +215,15 @@ public class InvokeMethod {
} else if (steptype == 3) {
String templateidstr = action.substring(1, action.indexOf(""));
String templatenamestr = action.substring(action.indexOf("") + 1);
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + " ID:【" + templateidstr + "】 发送SOCKET请求");
luckyclient.publicclass.LogUtil.APP.info("即将使用模板【" + templatenamestr + "ID:【" + templateidstr + "】 发送SOCKET请求");
String httpppt = HttpRequest.loadJSON("/projectprotocolTemplate/cgetPTemplateById.do?templateid=" + templateidstr);
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.parseObject(httpptp);
List<ProjectTemplateParams> paramslist = new ArrayList<ProjectTemplateParams>();
@ -224,22 +250,58 @@ public class InvokeMethod {
String msgend = ")";
for (Object obp : getParameterValues) {
String paramob = obp.toString();
String key = paramob.substring(0, paramob.indexOf("#"));
String value = paramob.substring(paramob.indexOf("#") + 1);
if (key.contains(booleanheadmsg) && key.contains(msgend)) {
String head = key.substring(key.indexOf(booleanheadmsg) + 8, key.lastIndexOf(msgend));
headmsg.put(head, value);
continue;
}
for (int i = 0; i < paramslist.size(); i++) {
ProjectTemplateParams ptp = paramslist.get(i);
if (ptp.getParamname().equals(key)) {
ptp.setParam(value);
paramslist.set(i, ptp);
if(paramob.contains("#")){
String key = paramob.substring(0, paramob.indexOf("#"));
String value = paramob.substring(paramob.indexOf("#") + 1);
if (key.contains(booleanheadmsg) && key.contains(msgend)) {
String head = key.substring(key.indexOf(booleanheadmsg) + 8, key.lastIndexOf(msgend));
headmsg.put(head, value);
continue;
}
int replaceflag=0;
for (int i = 0; i < paramslist.size(); i++) {
ProjectTemplateParams ptp = paramslist.get(i);
if("_forTextJson".equals(ptp.getParamname())){
if(ptp.getParam().indexOf("\""+key+"\":")>=0){
Map<String,String> map=ChangString.changjson(ptp.getParam(), key, value);
if("true".equals(map.get("boolean"))){
ptp.setParam(map.get("json"));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("替换参数"+key+"完成...");
break;
}
}else if(ptp.getParam().indexOf(key)>=0){
ptp.setParam(ptp.getParam().replace(key, value));
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParam()+"】中直接把【"+key+"】替换成【"+value+"】...");
break;
}else{
luckyclient.publicclass.LogUtil.APP.error("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
}
}else{
if (ptp.getParamname().equals(key)) {
ptp.setParam(value);
paramslist.set(i, ptp);
replaceflag=1;
luckyclient.publicclass.LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"");
break;
}
}
}
if(replaceflag==0){
luckyclient.publicclass.LogUtil.APP.error("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
+ "设置请求参数失败,请检查协议模板中此参数是否存在。");
}
}else{
luckyclient.publicclass.LogUtil.APP.error("替换模板或是头域参数失败,原因是因为没有检测到#"
+ "注意HTTP请求替换参数格式是【headmsg(头域名#头域值)|参数名#参数值|参数名2#参数值2】");
}
}
}
//处理参数
Map<String, Object> params = new HashMap<String, Object>(0);
for (ProjectTemplateParams ptp : paramslist) {
//处理参数对象
@ -247,16 +309,30 @@ public class InvokeMethod {
String tempparam = ptp.getParam().replace("&quot;", "\"");
JSONObject json = JSONObject.parseObject(tempparam);
params.put(ptp.getParamname().replace("&quot;", "\""), json);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 JSONObject类型参数值:【" + json.toString() + "");
} else if (ptp.getParamtype() == 2) {
String tempparam = ptp.getParam().replace("&quot;", "\"");
JSONArray jarr = JSONArray.parseArray(tempparam);
params.put(ptp.getParamname().replace("&quot;", "\""), jarr);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 JSONArray类型参数值:【" + jarr.toString() + "");
} else if (ptp.getParamtype() == 3) {
String tempparam = ptp.getParam().replace("&quot;", "\"");
File file = new File(tempparam);
params.put(ptp.getParamname().replace("&quot;", "\""), file);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 File类型参数值:【" + file.getAbsolutePath() + "");
} else if (ptp.getParamtype() == 4) {
String tempparam = ptp.getParam().replace("&quot;", "\"");
Double dp = Double.valueOf(tempparam);
params.put(ptp.getParamname().replace("&quot;", "\""), dp);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 数字类型参数值:【" + tempparam + "");
} else if (ptp.getParamtype() == 5) {
String tempparam = ptp.getParam().replace("&quot;", "\"");
Boolean bn = Boolean.valueOf(tempparam);
params.put(ptp.getParamname().replace("&quot;", "\""), bn);
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 Boolean类型参数值:【" + bn + "");
} else {
params.put(ptp.getParamname().replace("&quot;", "\""), ptp.getParam().replace("&quot;", "\""));
luckyclient.publicclass.LogUtil.APP.info("模板参数【" + ptp.getParamname() + "】 String类型参数值:【" + ptp.getParam().replace("&quot;", "\"") + "");
}
}

View File

@ -65,7 +65,13 @@ import com.alibaba.fastjson.JSON;
*/
public class HttpClientHelper {
/**
* @Description:使用HttpURLConnection发送post请求
* 使用HttpURLConnection发送post请求
* @param urlParam
* @param params
* @param charset
* @param timeout
* @param headmsg
* @return
*/
public static String sendHttpURLPost(String urlParam, Map<String, Object> params, String charset, int timeout,Map<String, String> headmsg) {
StringBuffer resultBuffer = null;
@ -73,12 +79,17 @@ public class HttpClientHelper {
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> e : params.entrySet()) {
sbParams.append(e.getKey());
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPURLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLPost请求(必须为key-value)...");
return "协议模板是纯文本无法使用sendHttpURLPost请求(必须为key-value)...";
}else{
for (Entry<String, Object> e : params.entrySet()) {
sbParams.append(e.getKey());
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPURLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
}
}
}
HttpURLConnection con = null;
@ -167,7 +178,13 @@ public class HttpClientHelper {
}
/**
* @Description:使用URLConnection发送post
* 使用URLConnection发送post
* @param urlParam
* @param params
* @param charset
* @param timeout
* @param headmsg
* @return
*/
public static String sendURLPost(String urlParam, Map<String, Object> params, String charset, int timeout,Map<String, String> headmsg) {
StringBuffer resultBuffer = null;
@ -175,12 +192,17 @@ public class HttpClientHelper {
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> e : params.entrySet()) {
sbParams.append(e.getKey());
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置URLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLPost请求(必须为key-value)...");
return "协议模板是纯文本无法使用sendURLPost请求(必须为key-value)...";
}else{
for (Entry<String, Object> e : params.entrySet()) {
sbParams.append(e.getKey());
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置URLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
}
}
}
URLConnection con = null;
@ -264,19 +286,28 @@ public class HttpClientHelper {
}
/**
* @Description:发送get请求保存下载文件
* 发送get请求保存下载文件
* @param urlParam
* @param params
* @param fileSavePath
* @param timeout
* @param headmsg
*/
public static void sendGetAndSaveFile(String urlParam, Map<String, Object> params, String fileSavePath, int timeout,Map<String, String> headmsg) {
// 构建请求参数
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPSaveFile参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendGetAndSaveFile请求(必须为key-value)...");
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPSaveFile参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
HttpURLConnection con = null;
@ -351,7 +382,13 @@ public class HttpClientHelper {
}
/**
* @Description:使用HttpURLConnection发送get请求
* 使用HttpURLConnection发送get请求
* @param urlParam
* @param params
* @param charset
* @param timeout
* @param headmsg
* @return
*/
public static String sendHttpURLGet(String urlParam, Map<String, Object> params, String charset, int timeout,Map<String, String> headmsg) {
StringBuffer resultBuffer = null;
@ -359,12 +396,17 @@ public class HttpClientHelper {
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPURLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPURLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
HttpURLConnection con = null;
@ -426,7 +468,13 @@ public class HttpClientHelper {
}
/**
* @Description:使用URLConnection发送get请求
* 使用URLConnection发送get请求
* @param urlParam
* @param params
* @param charset
* @param timeout
* @param headmsg
* @return
*/
public static String sendURLGet(String urlParam, Map<String, Object> params, String charset, int timeout,Map<String, String> headmsg) {
StringBuffer resultBuffer = null;
@ -434,13 +482,19 @@ public class HttpClientHelper {
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置URLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendURLGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置URLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
BufferedReader br = null;
try {
@ -500,9 +554,15 @@ public class HttpClientHelper {
}
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @Description:使用HttpClient以JSON格式发送post请求
* 使用HttpClient以JSON格式发送post请求
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @param cerpath
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static String httpClientPostJson(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg,String cerpath) throws NoSuchAlgorithmException, KeyManagementException {
StringBuffer resultBuffer = null;
@ -528,11 +588,17 @@ public class HttpClientHelper {
BufferedReader br = null;
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.info("参数类型TEXT,设置HTTPPostJson参数信息...【"+params.get("_forTextJson").toString()+"");
StringEntity entity = new StringEntity(params.get("_forTextJson").toString(),charset);
httpPost.setEntity(entity);
}else{
String jsonString = JSON.toJSONString(params);
luckyclient.publicclass.LogUtil.APP.info("设置HTTPPostJson参数信息...【"+jsonString+"");
luckyclient.publicclass.LogUtil.APP.info("参数类型FORM,设置HTTPPostJson参数信息...【"+jsonString+"");
StringEntity entity = new StringEntity(jsonString,charset);
httpPost.setEntity(entity);
}
}
CloseableHttpResponse response = httpclient.execute(httpPost);
@ -566,9 +632,15 @@ public class HttpClientHelper {
}
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @Description:使用HttpClient发送post请求
* 使用HttpClient发送post请求
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @param cerpath
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static String httpClientPost(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg,String cerpath) throws NoSuchAlgorithmException, KeyManagementException {
StringBuffer resultBuffer = null;
@ -593,13 +665,18 @@ public class HttpClientHelper {
BufferedReader br = null;
try {
if(params.size()>0){
//拼接参数
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
for (Map.Entry<String, Object> m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientPost参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps,charset));
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPost请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPost请求(必须为key-value)...";
}else{
//拼接参数
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
for (Map.Entry<String, Object> m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientPost参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps,charset));
}
}
CloseableHttpResponse response = httpclient.execute(httpPost);
@ -635,9 +712,15 @@ public class HttpClientHelper {
}
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @Description:使用HttpClient上传文件
* 使用HttpClient上传文件
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @param cerpath
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static String httpClientUploadFile(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg,String cerpath) throws NoSuchAlgorithmException, KeyManagementException {
StringBuffer resultBuffer = null;
@ -662,22 +745,27 @@ public class HttpClientHelper {
BufferedReader br = null;
try {
if(params.size()>0){
//拼接参数
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
//设置请求的编码格式
entityBuilder.setCharset(Charset.forName(charset));
for (Map.Entry<String, Object> m :params.entrySet()) {
if (m.getValue() instanceof File) {
entityBuilder.addBinaryBody(m.getKey(), (File)m.getValue());
luckyclient.publicclass.LogUtil.APP.info("设置httpClientUploadFile 上传文件参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}else{
entityBuilder.addTextBody(m.getKey(), m.getValue().toString());
luckyclient.publicclass.LogUtil.APP.info("设置httpClientUploadFile参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
}
HttpEntity reqEntity =entityBuilder.build();
httpPost.setEntity(reqEntity);
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientUploadFile请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientUploadFile请求(必须为key-value)...";
}else{
//拼接参数
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
//设置请求的编码格式
entityBuilder.setCharset(Charset.forName(charset));
for (Map.Entry<String, Object> m :params.entrySet()) {
if (m.getValue() instanceof File) {
entityBuilder.addBinaryBody(m.getKey(), (File)m.getValue());
luckyclient.publicclass.LogUtil.APP.info("设置httpClientUploadFile 上传文件参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}else{
entityBuilder.addTextBody(m.getKey(), m.getValue().toString());
luckyclient.publicclass.LogUtil.APP.info("设置httpClientUploadFile参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
}
HttpEntity reqEntity =entityBuilder.build();
httpPost.setEntity(reqEntity);
}
}
CloseableHttpResponse response = httpclient.execute(httpPost);
@ -712,9 +800,15 @@ public class HttpClientHelper {
}
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @Description:使用HttpClient发送get请求
* 使用HttpClient发送get请求
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @param cerpath
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
*/
public static String httpClientGet(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg,String cerpath) throws NoSuchAlgorithmException, KeyManagementException {
StringBuffer resultBuffer = null;
@ -724,18 +818,24 @@ public class HttpClientHelper {
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
try {
sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), charset));
} catch (UnsupportedEncodingException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
try {
sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), charset));
} catch (UnsupportedEncodingException e) {
luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e);
throw new RuntimeException(e);
}
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
if (sbParams != null && sbParams.length() > 0) {
urlParam = urlParam + "?" + sbParams.substring(0, sbParams.length() - 1);
@ -785,7 +885,12 @@ public class HttpClientHelper {
}
/**
* @Description:使用socket发送post请求
* 使用socket发送post请求
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @return
*/
public static String sendSocketPost(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg) {
String result = "";
@ -793,12 +898,17 @@ public class HttpClientHelper {
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketPost请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketPost请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
Socket socket = null;
@ -903,7 +1013,12 @@ public class HttpClientHelper {
}
/**
* @Description:使用socket发送get请求
* 使用socket发送get请求
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @return
*/
public static String sendSocketGet(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg) {
String result = "";
@ -911,13 +1026,19 @@ public class HttpClientHelper {
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketGet请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendSocketGet请求(必须为key-value)...";
}else{
for (Entry<String, Object> entry : params.entrySet()) {
sbParams.append(entry.getKey());
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"");
}
}
}
Socket socket = null;
OutputStreamWriter osw = null;
@ -1021,7 +1142,12 @@ public class HttpClientHelper {
}
/**
* @Description:读取一行数据contentLe内容长度为0时读取响应头信息不为0时读正文
* 读取一行数据contentLe内容长度为0时读取响应头信息不为0时读正文
* @param is
* @param contentLength
* @param charset
* @return
* @throws IOException
*/
private static String readLine(InputStream is, int contentLength, String charset) throws IOException {
List<Byte> lineByte = new ArrayList<Byte>();
@ -1049,8 +1175,14 @@ public class HttpClientHelper {
return new String(resutlBytes, charset);
}
/**
* @Description:使用HttpURLConnection发送delete请求
/**
* 使用HttpURLConnection发送delete请求
* @param urlParam
* @param params
* @param charset
* @param timeout
* @param headmsg
* @return
*/
public static String sendHttpURLDel(String urlParam, Map<String, Object> params, String charset, int timeout,Map<String, String> headmsg) {
StringBuffer resultBuffer = null;
@ -1059,12 +1191,17 @@ public class HttpClientHelper {
luckyclient.publicclass.LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"");
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
for (Entry<String, Object> e : params.entrySet()) {
sbParams.append(e.getKey());
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HttpURLDel参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLDel请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用sendHttpURLDel请求(必须为key-value)...";
}else{
for (Entry<String, Object> e : params.entrySet()) {
sbParams.append(e.getKey());
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
luckyclient.publicclass.LogUtil.APP.info("设置HttpURLDel参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"");
}
}
}
HttpURLConnection con = null;
@ -1150,10 +1287,16 @@ public class HttpClientHelper {
}
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @Description:使用HttpClient发送put请求 参数JSON格式
/**
* 使用HttpClient发送put请求 参数JSON格式
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @param cerpath
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
public static String httpClientPutJson(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg,String cerpath) throws KeyManagementException, NoSuchAlgorithmException {
StringBuffer resultBuffer = null;
@ -1180,11 +1323,18 @@ public class HttpClientHelper {
BufferedReader br = null;
try {
if(params.size()>0){
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.info("参数类型TEXT,设置HTTPClientPutJson参数信息...【"+params.get("_forTextJson").toString()+"");
StringEntity entity = new StringEntity(params.get("_forTextJson").toString(),charset);
httpput.setEntity(entity);
}else{
String jsonString = JSON.toJSONString(params);
luckyclient.publicclass.LogUtil.APP.info("设置HTTPClientPutJson参数信息...【"+jsonString+"");
luckyclient.publicclass.LogUtil.APP.info("参数类型FORM,设置HTTPClientPutJson参数信息...【"+jsonString+"");
StringEntity entity = new StringEntity(jsonString,charset);
httpput.setEntity(entity);
}
}
CloseableHttpResponse response = httpclient.execute(httpput);
@ -1219,9 +1369,15 @@ public class HttpClientHelper {
}
/**
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @Description:使用HttpClient发送put请求
* 使用HttpClient发送put请求
* @param urlParam
* @param params
* @param charset
* @param headmsg
* @param cerpath
* @return
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
public static String httpClientPut(String urlParam, Map<String, Object> params, String charset,Map<String, String> headmsg,String cerpath) throws KeyManagementException, NoSuchAlgorithmException {
StringBuffer resultBuffer = null;
@ -1247,13 +1403,19 @@ public class HttpClientHelper {
BufferedReader br = null;
try {
if(params.size()>0){
//拼接参数
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
for (Map.Entry<String, Object> m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
luckyclient.publicclass.LogUtil.APP.info("开始设置HTTPClientPut参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
httpput.setEntity(new UrlEncodedFormEntity(nvps,charset));
if(1==params.size()&&params.containsKey("_forTextJson")){
luckyclient.publicclass.LogUtil.APP.error("协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPut请求(必须为key-value)...");
return "协议模板是纯文本模式(仅限httpClientPostJson以及httpClientPutJson请求)无法使用httpClientPut请求(必须为key-value)...";
}else{
//拼接参数
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
for (Map.Entry<String, Object> m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
luckyclient.publicclass.LogUtil.APP.info("开始设置HTTPClientPut参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"");
}
httpput.setEntity(new UrlEncodedFormEntity(nvps,charset));
}
}
CloseableHttpResponse response = httpclient.execute(httpput);
@ -1289,19 +1451,11 @@ public class HttpClientHelper {
}
/**
* 设置信任自签名证书
*
* @param keyStorePath 密钥库路径
* @param keyStorepass 密钥库密码
* @param keyStorePath
* @param keyStorepass
* @return
*/
private static SSLContext sslContextKeyStore(String keyStorePath, String keyStorepass) {
SSLContext sslContext = null;
FileInputStream instream = null;
@ -1377,6 +1531,6 @@ public class HttpClientHelper {
}
public static void main(String[] args) throws KeyManagementException, NoSuchAlgorithmException {
}
}

View File

@ -70,7 +70,7 @@ public class HttpImpl {
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.info("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
@ -85,6 +85,7 @@ public class HttpImpl {
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动任务模式测试程序异常!!!",e);
return "启动任务模式测试程序异常!!!";
}
return "启动任务模式测试程序正常";
@ -121,7 +122,7 @@ public class HttpImpl {
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.info("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
@ -138,6 +139,7 @@ public class HttpImpl {
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动单用例模式测试程序异常!!!",e);
return "启动单用例模式测试程序异常!!!";
}
return "启动单用例模式测试程序正常";
@ -172,7 +174,7 @@ public class HttpImpl {
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.info("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
@ -188,6 +190,7 @@ public class HttpImpl {
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动批量用例模式测试程序异常!!!",e);
return "启动批量用例模式测试程序异常!!!";
}
return "启动批量用例模式测试程序正常";
@ -220,7 +223,7 @@ public class HttpImpl {
File file =new File(System.getProperty("user.dir")+loadpath);
if (!file .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.info("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"");
return "客户端测试驱动桩路径不存在,请检查【"+file.getPath()+"";
}
Runtime run = Runtime.getRuntime();
@ -236,6 +239,7 @@ public class HttpImpl {
}
} catch (Exception e) {
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("启动Web调试模式测试程序异常",e);
return "启动Web调试模式测试程序异常";
}
return "启动Web调试模式测试程序正常";
@ -263,6 +267,7 @@ public class HttpImpl {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath,e);
return "读取日志路径错误,请检查客户端日志路径是否存在!downLoadPath: "+downLoadPath;
}
BufferedReader bos = new BufferedReader(isr);
@ -277,6 +282,7 @@ public class HttpImpl {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("客户端转BufferedReader失败请检查原因",e);
return "客户端转BufferedReader失败请检查原因";
}
return sb.toString();
@ -304,6 +310,7 @@ public class HttpImpl {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("此文件不存在,请检查:"+downLoadPath,e);
return b;
} catch (IOException e) {
// TODO Auto-generated catch block
@ -318,9 +325,11 @@ public class HttpImpl {
if (!jarfile.isEmpty()){
if (!FilenameUtils.getExtension(jarfile.getOriginalFilename())
.equalsIgnoreCase("jar")) {
luckyclient.publicclass.LogUtil.APP.error("文件格式后续不是.jar上传失败");
return "文件格式后续不是.jar上传失败";
}
}else{
luckyclient.publicclass.LogUtil.APP.error("上传文件为空,请检查!");
return "上传文件为空,请检查!";
}
@ -329,7 +338,7 @@ public class HttpImpl {
String path = System.getProperty("user.dir")+loadpath;
if (!new File(path) .isDirectory())
{
luckyclient.publicclass.LogUtil.APP.info("客户端测试驱动桩路径不存在,请检查【"+path+"");
luckyclient.publicclass.LogUtil.APP.error("客户端测试驱动桩路径不存在,请检查【"+path+"");
return "客户端测试驱动桩路径不存在,请检查【"+path+"";
}
String pathName = path +File.separator+ name;
@ -350,10 +359,12 @@ public class HttpImpl {
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("客户端未找到正确路径或文件,上传失败!文件路径名称:"+pathName,e);
return "客户端未找到正确路径或文件,上传失败!文件路径名称:"+pathName;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
luckyclient.publicclass.LogUtil.APP.error("客户端IOExceptiona或是未找到驱动路径文件路径名称"+pathName,e);
return "客户端IOExceptiona或是未找到驱动路径文件路径名称"+pathName;
}
}
@ -384,14 +395,14 @@ public class HttpImpl {
websocket.connect(new InetSocketAddress(webip, webport));
luckyclient.publicclass.LogUtil.APP.info("客户端访问Web端配置"+webip+":"+webport+" 检测通过......");
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.info("客户端配置检测异常,请确认您项目根目录下的客户端配置文件(sys_config.properties)是否已经正确配置。",e);
luckyclient.publicclass.LogUtil.APP.error("客户端配置检测异常,请确认您项目根目录下的客户端配置文件(sys_config.properties)是否已经正确配置。",e);
return false;
} finally {
try {
dbsocket.close();
websocket.close();
} catch (IOException e) {
luckyclient.publicclass.LogUtil.APP.info("关闭Socket链接异常......",e);
luckyclient.publicclass.LogUtil.APP.error("关闭Socket链接异常......",e);
}
}
return true;