diff --git a/pom.xml b/pom.xml
index f03e7e1..e48dd96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -235,14 +235,7 @@
commons-net
3.6
-
-
- org.slf4j
- slf4j-api
- 1.7.26
-
-
+
org.springframework.boot
spring-boot-starter-log4j
1.3.8.RELEASE
diff --git a/src/main/java/luckyclient/caserun/BatchCaseExecute.java b/src/main/java/luckyclient/caserun/BatchCaseExecute.java
index 5773b42..ecb7dec 100644
--- a/src/main/java/luckyclient/caserun/BatchCaseExecute.java
+++ b/src/main/java/luckyclient/caserun/BatchCaseExecute.java
@@ -11,6 +11,7 @@ import luckyclient.caserun.exinterface.BatchTestCaseExecution;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.ex.WebBatchExecute;
import luckyclient.publicclass.AppiumConfig;
+import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
@@ -58,9 +59,10 @@ public class BatchCaseExecute extends TestControl {
}
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("启动批量运行用例主函数出现异常,请检查!",e);
+ } finally{
+ System.exit(0);
}
- System.exit(0);
}
}
diff --git a/src/main/java/luckyclient/caserun/OneCaseExecute.java b/src/main/java/luckyclient/caserun/OneCaseExecute.java
index 773b0d2..c8532b4 100644
--- a/src/main/java/luckyclient/caserun/OneCaseExecute.java
+++ b/src/main/java/luckyclient/caserun/OneCaseExecute.java
@@ -11,6 +11,7 @@ import luckyclient.caserun.exinterface.TestCaseExecution;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.ex.WebOneCaseExecute;
import luckyclient.publicclass.AppiumConfig;
+import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
@@ -30,32 +31,37 @@ public class OneCaseExecute extends TestControl {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
- PropertyConfigurator.configure(System.getProperty("user.dir")+ File.separator +"log4j.conf");
- String taskId = args[0];
- String caseId = args[1];
- int version = Integer.parseInt(args[2]);
- TaskExecute task = GetServerAPI.cgetTaskbyid(Integer.valueOf(taskId));
- TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(Integer.valueOf(taskId));
- if (taskScheduling.getTaskType() == 0) {
- // 接口测试
- TestCaseExecution.oneCaseExecuteForTask(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), String.valueOf(task.getTaskId()));
+ try{
+ PropertyConfigurator.configure(System.getProperty("user.dir")+ File.separator +"log4j.conf");
+ String taskId = args[0];
+ String caseId = args[1];
+ int version = Integer.parseInt(args[2]);
+ TaskExecute task = GetServerAPI.cgetTaskbyid(Integer.valueOf(taskId));
+ TaskScheduling taskScheduling = GetServerAPI.cGetTaskSchedulingByTaskId(Integer.valueOf(taskId));
+ if (taskScheduling.getTaskType() == 0) {
+ // 接口测试
+ TestCaseExecution.oneCaseExecuteForTask(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), String.valueOf(task.getTaskId()));
- } else if (taskScheduling.getTaskType() == 1) {
- WebOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), version,
- String.valueOf(task.getTaskId()));
+ } else if (taskScheduling.getTaskType() == 1) {
+ WebOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), version,
+ String.valueOf(task.getTaskId()));
- } else if (taskScheduling.getTaskType() == 2) {
- Properties properties = AppiumConfig.getConfiguration();
+ } else if (taskScheduling.getTaskType() == 2) {
+ Properties properties = AppiumConfig.getConfiguration();
- if ("Android".equals(properties.getProperty("platformName"))) {
- AndroidOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId),
- version, String.valueOf(task.getTaskId()));
- } else if ("IOS".equals(properties.getProperty("platformName"))) {
- IosOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), version,
- String.valueOf(task.getTaskId()));
- }
+ if ("Android".equals(properties.getProperty("platformName"))) {
+ AndroidOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId),
+ version, String.valueOf(task.getTaskId()));
+ } else if ("IOS".equals(properties.getProperty("platformName"))) {
+ IosOneCaseExecute.oneCaseExecuteForTast(taskScheduling.getProject().getProjectName(), Integer.valueOf(caseId), version,
+ String.valueOf(task.getTaskId()));
+ }
+ }
+ }catch(Exception e){
+ LogUtil.APP.error("启动单个用例运行主函数出现异常,请检查!",e);
+ } finally{
+ System.exit(0);
}
- System.exit(0);
}
}
diff --git a/src/main/java/luckyclient/caserun/RunAutomationTest.java b/src/main/java/luckyclient/caserun/RunAutomationTest.java
index f7b52c0..18ba658 100644
--- a/src/main/java/luckyclient/caserun/RunAutomationTest.java
+++ b/src/main/java/luckyclient/caserun/RunAutomationTest.java
@@ -7,6 +7,7 @@ import org.apache.log4j.PropertyConfigurator;
import luckyclient.caserun.exappium.AppTestControl;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exwebdriver.WebTestControl;
+import luckyclient.publicclass.LogUtil;
import luckyclient.serverapi.api.GetServerAPI;
import luckyclient.serverapi.entity.TaskExecute;
import luckyclient.serverapi.entity.TaskScheduling;
@@ -39,10 +40,11 @@ public class RunAutomationTest extends TestControl {
} else if (taskScheduling.getTaskType() == 2) {
AppTestControl.taskExecutionPlan(task);
}
- System.exit(0);
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("启动测试任务运行主函数出现异常,请检查!",e);
+ } finally{
+ System.exit(0);
}
}
}
diff --git a/src/main/java/luckyclient/caserun/WebDebugExecute.java b/src/main/java/luckyclient/caserun/WebDebugExecute.java
index 766660d..e9372c2 100644
--- a/src/main/java/luckyclient/caserun/WebDebugExecute.java
+++ b/src/main/java/luckyclient/caserun/WebDebugExecute.java
@@ -6,6 +6,7 @@ import org.apache.log4j.PropertyConfigurator;
import luckyclient.caserun.exinterface.TestControl;
import luckyclient.caserun.exinterface.WebTestCaseDebug;
+import luckyclient.publicclass.LogUtil;
/**
* =================================================================
@@ -22,10 +23,16 @@ public class WebDebugExecute extends TestControl{
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
- PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
- String caseIdStr = args[0];
- String userIdStr = args[1];
- WebTestCaseDebug.oneCaseDebug(caseIdStr, userIdStr);
- System.exit(0);
+ try {
+ PropertyConfigurator.configure(System.getProperty("user.dir") + File.separator + "log4j.conf");
+ String caseIdStr = args[0];
+ String userIdStr = args[1];
+ WebTestCaseDebug.oneCaseDebug(caseIdStr, userIdStr);
+ } catch (Exception e) {
+ // TODO: handle exception
+ LogUtil.APP.error("启动用例调试主函数出现异常,请检查!",e);
+ } finally{
+ System.exit(0);
+ }
}
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/BaseWebDrive.java b/src/main/java/luckyclient/caserun/exwebdriver/BaseWebDrive.java
index 50ff12f..4f1b538 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/BaseWebDrive.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/BaseWebDrive.java
@@ -41,11 +41,10 @@ public class BaseWebDrive {
FileUtils.copyFile(scrFile, new File(pngpath));
} catch (IOException e) {
LogUtil.APP.error("截图操作失败,抛出异常请查看日志...", e);
- e.printStackTrace();
}
scrFile.deleteOnExit();
LogUtil.APP
- .info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【" + pngpath + "】");
+ .info("已对当前界面进行截图操作,可通过用例执行界面的日志明细查看,也可以前往客户端上查看...【{}】",pngpath);
return result;
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/CaseLocalDebug.java b/src/main/java/luckyclient/caserun/exwebdriver/CaseLocalDebug.java
index be17d2d..1cb066c 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/CaseLocalDebug.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/CaseLocalDebug.java
@@ -34,13 +34,12 @@ public class CaseLocalDebug{
try {
ProjectCase testcase = GetServerAPI.cgetCaseBysign(testCaseExternalId);
List pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
- LogUtil.APP.info("开始执行用例:【"+testCaseExternalId+"】......");
+ LogUtil.APP.info("开始执行用例:【{}】......",testCaseExternalId);
List steps=GetServerAPI.getStepsbycaseid(testcase.getCaseId());
WebCaseExecution.caseExcution(testcase,steps, "888888",wd,caselog,pcplist);
- LogUtil.APP.info("当前用例:【"+testcase.getCaseSign()+"】执行完成......进入下一条");
+ LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
} catch (Exception e) {
- LogUtil.APP.info("用户执行过程中抛出异常!", e);
- e.printStackTrace();
+ LogUtil.APP.error("用户执行过程中抛出异常!", e);
}
//关闭浏览器
wd.quit();
@@ -56,17 +55,12 @@ public class CaseLocalDebug{
System.out.println("当前调试用例总共:"+addtestcase.size());
for(String testCaseExternalId:addtestcase) {
try{
- LogUtil.APP.info("开始调用方法,项目名:"+projectname+",用例编号:" + testCaseExternalId);
+ LogUtil.APP.info("开始调用方法,项目名:{},用例编号:{}",projectname,testCaseExternalId);
oneCasedebug(wd,testCaseExternalId);
}catch(Exception e){
continue;
}
}
}
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/EncapsulateOperation.java b/src/main/java/luckyclient/caserun/exwebdriver/EncapsulateOperation.java
index 24fc646..11596b4 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/EncapsulateOperation.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/EncapsulateOperation.java
@@ -52,21 +52,21 @@ public class EncapsulateOperation {
case "selectbyvisibletext":
select.selectByVisibleText(operationValue);
result = "下拉框对象通过VisibleText属性选择...【VisibleText属性值:" + operationValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("下拉框对象通过VisibleText属性选择...【VisibleText属性值:{}】",operationValue);
break;
case "selectbyvalue":
select.selectByValue(operationValue);
result = "下拉框对象通过Value属性选择...【Value属性值:" + operationValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("下拉框对象通过Value属性选择...【Value属性值:{}】",operationValue);
break;
case "selectbyindex":
select.selectByIndex(Integer.valueOf(operationValue));
result = "下拉框对象通过Index属性选择...【Index属性值:" + operationValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("下拉框对象通过Index属性选择...【Index属性值:{}】",operationValue);
break;
case "isselect":
result = "获取到的值是【" + we.isSelected() + "】";
- LogUtil.APP.info("判断对象是否已经被选择...【结果值:" + we.isSelected() + "】");
+ LogUtil.APP.info("判断对象是否已经被选择...【结果值:{}】",we.isSelected());
break;
default:
break;
@@ -80,23 +80,23 @@ public class EncapsulateOperation {
switch (operation) {
case "gettext":
result = "获取到的值是【" + we.getText() + "】";
- LogUtil.APP.info("getText获取对象text属性...【text属性值:" + result + "】");
+ LogUtil.APP.info("getText获取对象text属性...【text属性值:{}】",result);
break; // 获取输入框内容
case "gettagname":
result = "获取到的值是【" + we.getTagName() + "】";
- LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:" + result + "】");
+ LogUtil.APP.info("getTagName获取对象tagname属性...【tagname属性值:{}】",result);
break;
case "getattribute":
result = "获取到的值是【" + we.getAttribute(value) + "】";
- LogUtil.APP.info("getAttribute获取对象【" + value + "】属性...【" + value + "属性值:" + result + "】");
+ LogUtil.APP.info("getAttribute获取对象【{}】属性...【{}属性值:{}】",value,value,result);
break;
case "getcssvalue":
result = "获取到的值是【" + we.getCssValue(value) + "】";
- LogUtil.APP.info("getCssValue获取对象【" + value + "】属性...【" + value + "属性值:" + result + "】");
+ LogUtil.APP.info("getCssValue获取对象【{}】属性...【{}属性值:{}】",value,value,result);
break;
case "getcaptcha":
result = "获取到的值是【" + Ocr.getCAPTCHA(wd, we) + "】";
- LogUtil.APP.info("getcaptcha获取验证码...【验证码值:" + result + "】");
+ LogUtil.APP.info("getcaptcha获取验证码...【验证码值:{}】",result);
break;
default:
break;
@@ -113,41 +113,41 @@ public class EncapsulateOperation {
case "mouselkclick":
action.click(we).perform();
result = "mouselkclick鼠标左键点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mouselkclick鼠标左键点击对象...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
case "mouserkclick":
action.contextClick(we).perform();
result = "mouserkclick鼠标右键点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mouserkclick鼠标右键点击对象...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
case "mousedclick":
action.doubleClick(we).perform();
result = "mousedclick鼠标双击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mousedclick鼠标双击对象...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
case "mouseclickhold":
action.clickAndHold(we).perform();
result = "mouseclickhold鼠标点击对象后不释放...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mouseclickhold鼠标点击对象后不释放...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
case "mousedrag":
int[] location = getLocationFromParam(operationValue, ",");
// String[] temp = operationValue.split(",", -1);
action.dragAndDropBy(we, location[0], location[1]).perform();
result = "mousedrag鼠标移动至对象相对坐标...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 相对坐标(x,y):" + location[0] + "," + location[1] + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mousedrag鼠标移动至对象相对坐标...【对象定位属性:{}; 定位属性值:{}; 相对坐标(x,y):{},{}】",property,propertyValue,location[0],location[1]);
break;
case "mouseto":
int[] location1 = getLocationFromParam(operationValue, ",");
// String[] temp1 = operationValue.split(",", -1);
action.moveToElement(we, location1[0], location1[1]).perform();
result = "mouseto鼠标移动至对象相对坐标...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 相对坐标(x,y):" + location1[0] + "," + location1[1] + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mouseto鼠标移动至对象相对坐标...【对象定位属性:{}; 定位属性值:{}; 相对坐标(x,y):{},{}】",property,propertyValue,location1[0],location1[1]);
break;
case "mouserelease":
action.release(we).perform();
result = "mouserelease鼠标释放...";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mouserelease鼠标释放...");
break;
default:
break;
@@ -186,7 +186,7 @@ public class EncapsulateOperation {
// String[] temp1 = operationValue.split(",", -1);
action.moveByOffset(location[0], location[1]).perform();
result = "mouseto鼠标移动至对象相对坐标...坐标x:" + location[0] + " 坐标y:" + location[1];
- LogUtil.APP.info(result);
+ LogUtil.APP.info("mouseto鼠标移动至对象相对坐标...坐标x:{} 坐标y:{}",location[0],location[1]);
break;
case "mouserelease":
action.release().perform();
@@ -237,30 +237,30 @@ public class EncapsulateOperation {
case "click":
we.click();
result = "click点击对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("click点击对象...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
case "sendkeys":
we.sendKeys(operationValue);
result = "sendKeys对象输入...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 操作值:" + operationValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("sendKeys对象输入...【对象定位属性:{}; 定位属性值:{}; 操作值:{}】",property,propertyValue,operationValue);
break;
case "clear":
we.clear();
result = "clear清空输入框...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("clear清空输入框...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break; // 清空输入框
case "gotoframe":
wd.switchTo().frame(we);
result = "gotoframe切换Frame...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("gotoframe切换Frame...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
case "isenabled":
- result = "获取到的值是【" + we.isEnabled() + "】";
- LogUtil.APP.info(result);
+ result = "获取到的值是【"+we.isEnabled()+"】";
+ LogUtil.APP.info("获取到的值是【{}】",we.isEnabled());
break;
case "isdisplayed":
result = "获取到的值是【" + we.isDisplayed() + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("获取到的值是【{}】",we.isDisplayed());
break;
case "exjsob":
JavascriptExecutor jse = (JavascriptExecutor) wd;
@@ -269,23 +269,23 @@ public class EncapsulateOperation {
String tmp = obj.toString();
result = (100 < tmp.length()) ? tmp.substring(0, 100) + "..." : tmp;
result = "获取到的值是【" + result + "】";
- LogUtil.APP.info("执行JS...【" + operationValue + "】,返回的结果为:" + result);
+ LogUtil.APP.info("执行JS...【{}】,返回的结果为:{}",operationValue,result);
} else {
result = "执行JS...【" + operationValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("执行JS...【{}】",operationValue);
}
break;
case "scrollto":
Point location = we.getLocation();
((JavascriptExecutor) wd).executeScript("window.scrollTo(" + location.getX() + ", " + location.getY() + ")");
- result = "滚动到目标对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 对象坐标(x,y):" + location.getX() + "," + location.getY() + "】";;
- LogUtil.APP.info(result);
+ result = "滚动到目标对象...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "; 对象坐标(x,y):" + location.getX() + "," + location.getY() + "】";
+ LogUtil.APP.info("滚动到目标对象...【对象定位属性:{}; 定位属性值:{}; 对象坐标(x,y):{},{}】",property,propertyValue,location.getX(),location.getY());
break;
case "scrollintoview":
// 此方法可以用执行js命令来代替
((JavascriptExecutor) wd).executeScript("arguments[0].scrollIntoView(" + operationValue + ")", we);
result = "将目标对象滚动到可视...【对象定位属性:" + property + "; 定位属性值:" + propertyValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("将目标对象滚动到可视...【对象定位属性:{}; 定位属性值:{}】",property,propertyValue);
break;
default:
break;
@@ -309,7 +309,7 @@ public class EncapsulateOperation {
break;
case "alertgettext":
result = "获取到的值是【" + alert.getText() + "】";
- LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:" + alert.getText() + "】");
+ LogUtil.APP.info("弹出框对象通过getText获取对象text属性...【Text属性值:{}】",alert.getText());
break;
default:
break;
@@ -324,14 +324,14 @@ public class EncapsulateOperation {
case "open":
wd.get(operationValue);
result = "Open页面...【" + operationValue + "】";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("Open页面...【{}】",operationValue);
break;
case "addcookie":
List cookies = buildCookie(operationValue);
if (null != cookies && cookies.size() > 0) {
for (Cookie cookie : cookies) {
wd.manage().addCookie(cookie);
- LogUtil.APP.info("添加Cookie:【"+cookie+"】成功!");
+ LogUtil.APP.info("添加Cookie:【{}】成功!",cookie);
}
}
result = "添加cookie...【" + operationValue + "】";
@@ -343,10 +343,10 @@ public class EncapsulateOperation {
String tmp = obj.toString();
result = (100 < tmp.length()) ? tmp.substring(0, 100) + "..." : tmp;
result = "获取到的值是【" + result + "】";
- LogUtil.APP.info("执行JS...【" + operationValue + "】,返回的结果为:" + result);
+ LogUtil.APP.info("执行JS...【{}】,返回的结果为:{}",operationValue,result);
} else {
result = "执行JS...【" + operationValue + "】";
- LogUtil.APP.info(result+",执行JS返回null或没有返回");
+ LogUtil.APP.info("{},执行JS返回null或没有返回",result);
}
break;
case "gotodefaultcontent":
@@ -361,7 +361,7 @@ public class EncapsulateOperation {
break;
case "gettitle":
result = "获取到的值是【" + wd.getTitle() + "】";
- LogUtil.APP.info("获取页面Title...【" + wd.getTitle() + "】");
+ LogUtil.APP.info("获取页面Title...【{}】",wd.getTitle());
break;
case "getwindowhandle":
result = getTargetWindowHandle(wd, operationValue);
@@ -380,11 +380,10 @@ public class EncapsulateOperation {
// 设置元素出现最大时长30秒
wd.manage().timeouts().implicitlyWait(Integer.valueOf(operationValue), TimeUnit.SECONDS);
result = "当前任务操作等待【" + operationValue + "】秒...";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("当前任务操作等待【{}】秒...",operationValue);
break;
} catch (NumberFormatException e) {
- LogUtil.APP.error("等待时间转换出错!");
- e.printStackTrace();
+ LogUtil.APP.error("等待时间转换出现异常!",e);
result = "【等待时间转换出错,请检查参数】";
break;
}
@@ -419,16 +418,15 @@ public class EncapsulateOperation {
//String expire = jsonObject.getString("expire");
if (!StringUtils.isBlank(name) && !StringUtils.isBlank(val)) {
Cookie cookie = new Cookie(name, val, domain, path, null);
- LogUtil.APP.info("解析Cookie成功:【"+cookie+"】");
+ LogUtil.APP.info("解析Cookie成功:【{}】",cookie);
result.add(cookie);
}else{
- LogUtil.APP.warn("cookie:" + jsonObject + "错误,name或是val为空!");
+ LogUtil.APP.warn("cookie:{} 错误,name或是val为空!",jsonObject);
}
}
return result;
} catch (Exception e) {
- e.printStackTrace();
- LogUtil.APP.error("格式化Cookie对象出错,请检查您的格式是否正确!【"+operationValue+"】");
+ LogUtil.APP.error("格式化Cookie对象出错,请检查您的格式是否正确!【{}】",operationValue,e);
return null;
}
}
@@ -466,7 +464,7 @@ public class EncapsulateOperation {
result = "获取窗口句柄值失败,WebDriver为空";
}
if (result.contains("获取窗口句柄值失败")) LogUtil.APP.warn(result);
- else LogUtil.APP.info("获取窗口句柄值成功,目标窗口句柄值为【" + result + "】");
+ else LogUtil.APP.info("获取窗口句柄值成功,目标窗口句柄值为【{}】",result);
return result;
}
@@ -501,6 +499,7 @@ public class EncapsulateOperation {
else result = "获取到的值是【" + windowHandles.get(index - 1) + "】";
}
} catch (IndexOutOfBoundsException e) {
+ LogUtil.APP.error("获取窗口句柄值出现异常,需要获取窗口句柄值的下标【{}】越界",index,e);
result = "获取窗口句柄值失败,需要获取窗口句柄值的下标【" + index + "】越界";
}
return result;
@@ -558,23 +557,18 @@ public class EncapsulateOperation {
try {
if (null == Wait(driver).until(windowToBeAvailableAndSwitchToIt(target))) {
result = "切换窗口句柄失败,未找到句柄值为【" + target + "】的对象";
- LogUtil.APP.warn(result);
+ LogUtil.APP.warn("切换窗口句柄失败,未找到句柄值为【{}】的对象",target);
} else {
result = "切换窗口句柄成功,找到句柄值为【" + target + "】的对象";
- LogUtil.APP.info(result);
+ LogUtil.APP.info("切换窗口句柄成功,找到句柄值为【{}】的对象",target);
}
return result;
} catch (TimeoutException e) {
result = "切换窗口句柄失败,等待超时,未找到句柄值为【" + target + "】的对象";
- LogUtil.APP.error(result);
+ LogUtil.APP.error("切换窗口句柄失败,等待超时,未找到句柄值为【{}】的对象",target,e);
return result;
}
}
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
-
+
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/WebDriverInitialization.java b/src/main/java/luckyclient/caserun/exwebdriver/WebDriverInitialization.java
index 910030e..78f8379 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/WebDriverInitialization.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/WebDriverInitialization.java
@@ -40,7 +40,7 @@ public class WebDriverInitialization{
File directory = new File("");
String drivenpath=directory.getCanonicalPath()+File.separator+"BrowserDriven"+File.separator;
WebDriver webDriver = null;
- LogUtil.APP.info("准备初始化WebDriver对象...检查到当前操作系统是:"+os);
+ LogUtil.APP.info("准备初始化WebDriver对象...检查到当前操作系统是:{}",os);
if(drivertype==0){
if(os.startsWith("win")){
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
@@ -90,7 +90,7 @@ public class WebDriverInitialization{
LogUtil.APP.warn("当前操作系统无法进行Edge浏览器的Web UI测试,请选择火狐或是谷歌浏览器!");
}
}else{
- LogUtil.APP.warn("浏览器类型标识:"+drivertype+",获取到的浏览器类型标识未定义,默认IE浏览器进行执行....");
+ LogUtil.APP.warn("浏览器类型标识:{},获取到的浏览器类型标识未定义,默认IE浏览器进行执行....",drivertype);
System.setProperty("webdriver.ie.driver",drivenpath+"IEDriverServer.exe");
webDriver = new InternetExplorerDriver();
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java b/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java
index 9b5401d..716321f 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/WebTestControl.java
@@ -4,7 +4,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-import org.apache.log4j.PropertyConfigurator;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
@@ -52,7 +51,7 @@ public class WebTestControl {
wd = WebDriverInitialization.setWebDriverForLocal();
} catch (IOException e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("初始化WebDriver出现异常!",e);
}
LogOperation caselog = new LogOperation();
List testCases = GetServerAPI.getCasesbyplanname(planname);
@@ -60,7 +59,7 @@ public class WebTestControl {
if (testCases.size() != 0) {
pcplist = GetServerAPI.cgetParamsByProjectid(String.valueOf(testCases.get(0).getProjectId()));
}
- LogUtil.APP.info("当前计划中读取到用例共 " + testCases.size() + " 个");
+ LogUtil.APP.info("当前计划中读取到用例共【{}】个",testCases.size());
int i = 0;
for (ProjectCase testcase : testCases) {
List steps = GetServerAPI.getStepsbycaseid(testcase.getCaseId());
@@ -68,15 +67,14 @@ public class WebTestControl {
continue;
}
i++;
- LogUtil.APP.info("开始执行第" + i + "条用例:【" + testcase.getCaseSign() + "】......");
+ LogUtil.APP.info("开始执行第{}条用例:【{}】......",i,testcase.getCaseSign());
try {
WebCaseExecution.caseExcution(testcase, steps, taskid, wd, caselog, pcplist);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
LogUtil.APP.error("用户执行过程中抛出异常!", e);
- e.printStackTrace();
}
- LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
+ LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
}
LogUtil.APP.info("当前项目测试计划中的用例已经全部执行完成...");
// 关闭浏览器
@@ -106,15 +104,13 @@ public class WebTestControl {
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
} catch (WebDriverException e1) {
LogUtil.APP.error("初始化WebDriver出错 WebDriverException!", e1);
- e1.printStackTrace();
} catch (IOException e2) {
LogUtil.APP.error("初始化WebDriver出错 IOException!", e2);
- e2.printStackTrace();
}
LogOperation caselog = new LogOperation();
List cases = GetServerAPI.getCasesbyplanId(taskScheduling.getPlanId());
- LogUtil.APP.info("当前计划中读取到用例共 " + cases.size() + " 个");
+ LogUtil.APP.info("当前计划中读取到用例共【{}】个",cases.size());
LogOperation.updateTaskExecuteStatus(taskid, cases.size());
for (ProjectCase testcase : cases) {
@@ -122,7 +118,7 @@ public class WebTestControl {
if (steps.size() == 0) {
continue;
}
- LogUtil.APP.info("开始执行用例:【" + testcase.getCaseSign() + "】......");
+ LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
try {
// 插入开始执行的用例
caselog.insertTaskCaseExecute(taskid, taskScheduling.getProjectId(),testcase.getCaseId(),testcase.getCaseSign(), testcase.getCaseName(), 4);
@@ -130,14 +126,13 @@ public class WebTestControl {
} catch (InterruptedException e) {
// TODO Auto-generated catch block
LogUtil.APP.error("用户执行过程中抛出异常!", e);
- e.printStackTrace();
}
- LogUtil.APP.info("当前用例:【" + testcase.getCaseSign() + "】执行完成......进入下一条");
+ LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
}
tastcount = LogOperation.updateTaskExecuteData(taskid, cases.size());
String testtime = LogOperation.getTestTime(taskid);
- LogUtil.APP.info("当前项目【" + projectname + "】测试计划中的用例已经全部执行完成...");
+ LogUtil.APP.info("当前项目【{}】测试计划中的用例已经全部执行完成...",projectname);
MailSendInitialization.sendMailInitialization(HtmlMail.htmlSubjectFormat(jobname),
HtmlMail.htmlContentFormat(tastcount, taskid, buildstatus, restartstatus, testtime, jobname),
taskid, taskScheduling, tastcount);
@@ -155,15 +150,4 @@ public class WebTestControl {
}
}
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- try {
- PropertyConfigurator.configure(System.getProperty("user.dir") + "\\log4j.conf");
- // ManualExecutionPlan("automation test");
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebBatchExecute.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebBatchExecute.java
index 15010f7..a42a622 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebBatchExecute.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebBatchExecute.java
@@ -40,7 +40,7 @@ public class WebBatchExecute{
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
- e1.printStackTrace();
+ LogUtil.APP.error("初始化WebDriver出现异常!", e1);
}
LogOperation caselog = new LogOperation();
TaskExecute task=GetServerAPI.cgetTaskbyid(Integer.valueOf(taskid));
@@ -58,7 +58,6 @@ public class WebBatchExecute{
} catch (InterruptedException e) {
// TODO Auto-generated catch block
LogUtil.APP.error("用户执行过程中抛出异常!", e);
- e.printStackTrace();
}
}
}else{ //批量执行用例
@@ -73,7 +72,6 @@ public class WebBatchExecute{
} catch (InterruptedException e) {
// TODO Auto-generated catch block
LogUtil.APP.error("用户执行过程中抛出异常!", e);
- e.printStackTrace();
}
}
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java
index 0a97143..9e43bf7 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebCaseExecution.java
@@ -82,10 +82,10 @@ public class WebCaseExecution extends TestCaseExecution {
if (0 != stepresult) {
setcaseresult = stepresult;
if (testcase.getFailcontinue() == 0) {
- LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......");
+ LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,中断本条用例后续步骤执行,进入到下一条用例执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
break;
} else {
- LogUtil.APP.warn("用例【"+testcase.getCaseSign()+"】第【"+step.getStepSerialNumber()+"】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......");
+ LogUtil.APP.warn("用例【{}】第【{}】步骤执行失败,继续本条用例后续步骤执行,进入下个步骤执行中......",testcase.getCaseSign(),step.getStepSerialNumber());
}
}
}
@@ -93,10 +93,10 @@ public class WebCaseExecution extends TestCaseExecution {
variable.clear();
caselog.updateTaskCaseExecuteStatus(taskid, testcase.getCaseId(), setcaseresult);
if (setcaseresult == 0) {
- LogUtil.APP.info("用例【" + testcase.getCaseSign() + "】全部步骤执行结果成功...");
+ LogUtil.APP.info("用例【{}】全部步骤执行结果成功...",testcase.getCaseSign());
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例全部步骤执行结果成功", "info", "ending", "");
} else {
- LogUtil.APP.warn("用例【" + testcase.getCaseSign() + "】步骤执行过程中失败或是锁定...请查看具体原因!" + casenote);
+ LogUtil.APP.warn("用例【{}】步骤执行过程中失败或是锁定...请查看具体原因:{}",testcase.getCaseSign(),casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "用例执行过程中失败或是锁定" + casenote, "error", "ending", "");
}
}
@@ -123,8 +123,7 @@ public class WebCaseExecution extends TestCaseExecution {
LogUtil.APP.info("二次解析用例过程完成,等待进行对象操作......");
caselog.insertTaskCaseLog(taskid, caseId, "对象操作:" + operation + "; 操作值:" + operationValue, "info", String.valueOf(stepno), "");
} catch (Exception e) {
- e.printStackTrace();
- LogUtil.APP.error("二次解析用例过程抛出异常!---" + e.getMessage());
+ LogUtil.APP.error("二次解析用例过程抛出异常!",e);
return "步骤执行失败:解析用例失败!";
}
@@ -173,7 +172,7 @@ public class WebCaseExecution extends TestCaseExecution {
result = "步骤执行失败:元素操作过程失败!";
}
} catch (Exception e) {
- LogUtil.APP.error("元素定位过程或是操作过程失败或异常!" + e.getMessage());
+ LogUtil.APP.error("元素定位过程或是操作过程失败或异常!",e);
return "步骤执行失败:元素定位过程或是操作过程失败或异常!" + e.getMessage();
}
@@ -218,7 +217,7 @@ public class WebCaseExecution extends TestCaseExecution {
return we;
} catch (Exception e) {
- LogUtil.APP.error("当前对象定位失败:" + e.getMessage());
+ LogUtil.APP.error("当前对象定位失败!",e);
return null;
}
@@ -233,18 +232,18 @@ public class WebCaseExecution extends TestCaseExecution {
if (null != result && !result.contains("步骤执行失败:")) {
// 有预期结果
if (null != expect && !expect.isEmpty()) {
- LogUtil.APP.info("期望结果为【" + expect + "】");
+ LogUtil.APP.info("期望结果为【{}】",expect);
// 赋值传参模式
if (expect.length() > ASSIGNMENT_SIGN.length() && expect.startsWith(ASSIGNMENT_SIGN)) {
variable.put(expect.substring(ASSIGNMENT_SIGN.length()), result);
- LogUtil.APP.info("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "】");
+ LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(ASSIGNMENT_SIGN.length()));
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给变量【" + expect.substring(ASSIGNMENT_SIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// 赋值全局变量
else if (expect.length() > ASSIGNMENT_GLOBALSIGN.length() && expect.startsWith(ASSIGNMENT_GLOBALSIGN)) {
variable.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
ParamsManageForSteps.GLOBAL_VARIABLE.put(expect.substring(ASSIGNMENT_GLOBALSIGN.length()), result);
- LogUtil.APP.info("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "】");
+ LogUtil.APP.info("用例:{} 第{}步,将测试结果【{}】赋值给全局变量【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),result,expect.substring(ASSIGNMENT_GLOBALSIGN.length()));
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "将测试结果【" + result + "】赋值给全局变量【" + expect.substring(ASSIGNMENT_GLOBALSIGN.length()) + "】", "info", String.valueOf(step.getStepSerialNumber()), "");
}
// WebUI检查模式
@@ -254,13 +253,13 @@ public class WebCaseExecution extends TestCaseExecution {
WebElement we = isElementExist(driver, checkproperty, checkPropertyValue);
if (null != we) {
- LogUtil.APP.info("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,在当前页面中找到预期结果中对象。当前步骤执行成功!");
+ LogUtil.APP.info("用例:{} 第{}步,在当前页面中找到预期结果中对象。当前步骤执行成功!",testcase.getCaseSign(),step.getStepSerialNumber());
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中找到预期结果中对象。当前步骤执行成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。执行失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
- LogUtil.APP.warn("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!");
+ LogUtil.APP.warn("用例:{} 第{}步,没有在当前页面中找到预期结果中对象。当前步骤执行失败!",testcase.getCaseSign(),step.getStepSerialNumber());
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "在当前页面中没有找到预期结果中对象。当前步骤执行失败!" + "checkproperty【" + checkproperty + "】 checkproperty_value【" + checkPropertyValue + "】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@@ -269,13 +268,13 @@ public class WebCaseExecution extends TestCaseExecution {
// 模糊匹配预期结果模式
if (expect.length() > FUZZY_MATCHING_SIGN.length() && expect.startsWith(FUZZY_MATCHING_SIGN)) {
if (result.contains(expect.substring(FUZZY_MATCHING_SIGN.length()))) {
- LogUtil.APP.info("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,模糊匹配预期结果成功!执行结果:" + result);
+ LogUtil.APP.info("用例:{} 第{}步,模糊匹配预期结果成功!执行结果:",testcase.getCaseSign(),step.getStepSerialNumber(),result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果成功!执行结果:" + result, "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
- LogUtil.APP.warn("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result);
+ LogUtil.APP.warn("用例:{} 第{}步,模糊匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(FUZZY_MATCHING_SIGN.length()),result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "模糊匹配预期结果失败!预期结果:" + expect.substring(FUZZY_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@@ -284,26 +283,26 @@ public class WebCaseExecution extends TestCaseExecution {
Pattern pattern = Pattern.compile(expect.substring(REGULAR_MATCHING_SIGN.length()));
Matcher matcher = pattern.matcher(result);
if (matcher.find()) {
- LogUtil.APP.info("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,正则匹配预期结果成功!执行结果:" + result);
+ LogUtil.APP.info("用例:{} 第{}步,正则匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
- LogUtil.APP.warn("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result);
+ LogUtil.APP.warn("用例:{} 第{}步,正则匹配预期结果失败!预期结果:{},测试结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),expect.substring(REGULAR_MATCHING_SIGN.length()),result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "正则匹配预期结果失败!预期结果:" + expect.substring(REGULAR_MATCHING_SIGN.length()) + ",测试结果:" + result, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
// 精确匹配预期结果模式
else {
if (expect.equals(result)) {
- LogUtil.APP.info("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,精确匹配预期结果成功!执行结果:" + result);
+ LogUtil.APP.info("用例:{} 第{}步,精确匹配预期结果成功!执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果成功!", "info", String.valueOf(step.getStepSerialNumber()), "");
} else {
casenote = "第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!";
setresult = 1;
BaseWebDrive.webScreenShot(driver, imagname);
- LogUtil.APP.warn("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】");
+ LogUtil.APP.warn("用例:{} 第{}步,精确匹配预期结果失败!预期结果是:【{}】 执行结果:【{}】",testcase.getCaseSign(),step.getStepSerialNumber(),expect,result);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "精确匹配预期结果失败!预期结果是:【"+expect+"】 执行结果:【"+ result+"】", "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
}
@@ -313,7 +312,7 @@ public class WebCaseExecution extends TestCaseExecution {
casenote = (null != result) ? result : "";
setresult = 2;
BaseWebDrive.webScreenShot(driver, imagname);
- LogUtil.APP.warn("用例:" + testcase.getCaseSign() + " 第" + step.getStepSerialNumber() + "步,执行结果:" + casenote);
+ LogUtil.APP.warn("用例:{} 第{}步,执行结果:{}",testcase.getCaseSign(),step.getStepSerialNumber(),casenote);
caselog.insertTaskCaseLog(taskid, testcase.getCaseId(), "当前步骤在执行过程中解析|定位元素|操作对象失败!" + casenote, "error", String.valueOf(step.getStepSerialNumber()), imagname);
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java
index ce86a4d..0cf86a0 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebDriverAnalyticCase.java
@@ -46,7 +46,7 @@ public class WebDriverAnalyticCase {
params.put("property", property.trim().toLowerCase());
//set属性值
params.put("property_value", propertyValue.trim());
- LogUtil.APP.info("对象属性解析结果:property:"+property.trim()+"; property_value:"+propertyValue.trim());
+ LogUtil.APP.info("对象属性解析结果:property:{}; property_value:{}",property.trim(),propertyValue.trim());
}
//set操作方法
params.put("operation", step.getStepOperation().toLowerCase());
@@ -54,7 +54,7 @@ public class WebDriverAnalyticCase {
//set属性值
params.put("operation_value", step.getStepParameters());
}
- LogUtil.APP.info("对象操作解析结果:operation:"+step.getStepOperation().toLowerCase()+"; operation_value:"+step.getStepParameters());
+ LogUtil.APP.info("对象操作解析结果:operation:{}; operation_value:{}",step.getStepOperation().toLowerCase(),step.getStepParameters());
//获取预期结果字符串
resultstr = step.getExpectedResult();
@@ -71,15 +71,15 @@ public class WebDriverAnalyticCase {
params.put("checkproperty_value", expectedResults.substring(expectedResults.indexOf("=")+1, expectedResults.lastIndexOf(")")));
}
params.put("ExpectedResults", expectedResults);
- LogUtil.APP.info("预期结果解析:ExpectedResults:"+expectedResults);
+ LogUtil.APP.info("预期结果解析:ExpectedResults:{}",expectedResults);
}
- LogUtil.APP.info("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!");
+ LogUtil.APP.info("用例编号:{} 第{}步,解析自动化用例步骤脚本完成!",projectcase.getCaseSign(),step.getStepSerialNumber());
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本完成!","info",String.valueOf(step.getStepSerialNumber()),"");
}
}catch(Exception e) {
- LogUtil.APP.error("用例编号:"+projectcase.getCaseSign()+" 步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!",e);
+ LogUtil.APP.error("用例编号:{} 第{}步,解析自动化用例步骤脚本出现异常!",projectcase.getCaseSign(),step.getStepSerialNumber(),e);
if(null!=caselog){
caselog.insertTaskCaseLog(taskid, projectcase.getCaseId(),"步骤编号:"+step.getStepSerialNumber()+" 解析自动化用例步骤脚本出错!","error",String.valueOf(step.getStepSerialNumber()),"");
}
diff --git a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebOneCaseExecute.java b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebOneCaseExecute.java
index e7512e4..5399f7e 100644
--- a/src/main/java/luckyclient/caserun/exwebdriver/ex/WebOneCaseExecute.java
+++ b/src/main/java/luckyclient/caserun/exwebdriver/ex/WebOneCaseExecute.java
@@ -38,7 +38,6 @@ public class WebOneCaseExecute{
wd = WebDriverInitialization.setWebDriverForTask(drivertype);
} catch (IOException e1) {
LogUtil.APP.error("初始化WebDriver出错!", e1);
- e1.printStackTrace();
}
LogOperation caselog = new LogOperation();
ProjectCase testcase = GetServerAPI.cGetCaseByCaseId(caseId);
@@ -46,14 +45,13 @@ public class WebOneCaseExecute{
LogOperation.deleteTaskCaseLog(testcase.getCaseId(), taskid);
List pcplist=GetServerAPI.cgetParamsByProjectid(String.valueOf(testcase.getProjectId()));
- LogUtil.APP.info("开始执行用例:【"+testcase.getCaseSign()+"】......");
+ LogUtil.APP.info("开始执行用例:【{}】......",testcase.getCaseSign());
try {
List steps=GetServerAPI.getStepsbycaseid(testcase.getCaseId());
WebCaseExecution.caseExcution(testcase, steps, taskid,wd,caselog,pcplist);
- LogUtil.APP.info("当前用例:【"+testcase.getCaseSign()+"】执行完成......进入下一条");
+ LogUtil.APP.info("当前用例:【{}】执行完成......进入下一条",testcase.getCaseSign());
} catch (InterruptedException e) {
LogUtil.APP.error("用户执行过程中抛出异常!", e);
- e.printStackTrace();
}
LogOperation.updateTaskExecuteData(taskid, 0);
//关闭浏览器
diff --git a/src/main/java/luckyclient/caserun/publicdispose/ChangString.java b/src/main/java/luckyclient/caserun/publicdispose/ChangString.java
index 96cf310..794a8ec 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/ChangString.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/ChangString.java
@@ -51,7 +51,7 @@ public class ChangString {
// 如果存在传参,进行处理
if (varcount > 0) {
- LogUtil.APP.info("在" + changname + "【" + str + "】中找到" + varcount + "个可替换参数");
+ LogUtil.APP.info("在{}【{}】中找到{}个可替换参数",changname,str,varcount);
int changcount = 0;
// 准备将HASHMAP换成LINKMAP,对KEY进行排序,解决要先替换最长KEY的问题
@@ -82,15 +82,14 @@ public class ChangString {
// "\\\\'"));
int viewcount = counter(str, "@" + entry.getKey());
str = str.replace("@" + entry.getKey(), entry.getValue());
- LogUtil.APP
- .info("将" + changname + "引用变量【@" + entry.getKey() + "】替换成值【" + entry.getValue() + "】");
+ LogUtil.APP.info("将{}引用变量【@{}】替换成值【{}】",changname,entry.getKey(),entry.getValue());
str = str.replace("////CHANG////", "@@" + entry.getKey());
changcount = changcount + viewcount;
}
}
if (varcount != changcount) {
- LogUtil.APP.warn(changname + "有引用变量未在参数列中找到,请检查!处理结果【" + str + "】");
+ LogUtil.APP.warn(changname + "有引用变量未在参数列中找到,请检查!处理结果【{}】",str);
}
}
str = str.replace("@@", "@");
@@ -98,7 +97,7 @@ public class ChangString {
str=ParamsManageForSteps.paramsManage(str);
return str;
} catch (Exception e) {
- e.printStackTrace();
+ LogUtil.APP.error("替换参数过程中出现异常,请检查!",e);
return "";
}
}
@@ -220,10 +219,10 @@ public class ChangString {
if(entry.getValue() instanceof List){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始String值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始String值:【{}】",entry.getValue());
JSONArray jsonarr = JSONArray.parseArray(value);
entry.setValue(jsonarr);
- LogUtil.APP.info("对象替换后String值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后String值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -238,10 +237,10 @@ public class ChangString {
}catch(JSONException jsone){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始List值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始List值:【{}】",entry.getValue());
JSONArray jsonarr = JSONArray.parseArray(value);
entry.setValue(jsonarr);
- LogUtil.APP.info("对象替换后List值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后List值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -255,9 +254,9 @@ public class ChangString {
if(entry.getValue() instanceof String){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始String值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始String值:【{}】",entry.getValue());
entry.setValue(value);
- LogUtil.APP.info("对象替换后String值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后String值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -267,9 +266,9 @@ public class ChangString {
if(entry.getValue() instanceof Integer){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始Integer值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始Integer值:【{}】",entry.getValue());
entry.setValue(Integer.valueOf(value));
- LogUtil.APP.info("对象替换后Integer值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后Integer值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -279,9 +278,9 @@ public class ChangString {
if(entry.getValue() instanceof Long){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始Long值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始Long值:【{}】",entry.getValue());
entry.setValue(Long.valueOf(value));
- LogUtil.APP.info("对象替换后Long值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后Long值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -291,10 +290,10 @@ public class ChangString {
if(entry.getValue() instanceof BigDecimal){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始BigDecimal值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始BigDecimal值:【{}】",entry.getValue());
BigDecimal bd = new BigDecimal(value);
entry.setValue(bd);
- LogUtil.APP.info("对象替换后BigDecimal值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后BigDecimal值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -304,9 +303,9 @@ public class ChangString {
if(entry.getValue() instanceof Boolean){
if(key.equals(entry.getKey())){
if(keyindex==COUNTER){
- LogUtil.APP.info("对象原始Boolean值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象原始Boolean值:【{}】",entry.getValue());
entry.setValue(Boolean.valueOf(value));
- LogUtil.APP.info("对象替换后Boolean值:【"+entry.getValue()+"】");
+ LogUtil.APP.info("对象替换后Boolean值:【{}】",entry.getValue());
BCHANG=true;
}
COUNTER++;
@@ -326,10 +325,7 @@ public class ChangString {
*/
public static Map changjson(String json, String key, String value,int index) {
json=json.trim();
- LogUtil.APP.info("原始JSON:【"+json+"】");
- LogUtil.APP.info("待替换JSON KEY:【"+key+"】");
- LogUtil.APP.info("待替换JSON VALUE:【"+value+"】");
- LogUtil.APP.info("待替换JSON KEY序号:【"+index+"】");
+ LogUtil.APP.info("原始JSON:【{}】,待替换JSON KEY:【{}】,待替换JSON VALUE:【{}】,待替换JSON KEY序号:【{}】",json,key,value,index);
Map map = new HashMap(0);
map.put("json", json);
map.put("boolean", BCHANG.toString().toLowerCase());
@@ -339,12 +335,11 @@ public class ChangString {
JSONObject jsonStr = JSONObject.parseObject(json);
jsonStr=parseJsonString(json,key,value,index);
if (BCHANG) {
- LogUtil.APP
- .info("JSON字符串替换成功,新JSON:【" + jsonStr.toJSONString() + "】");
+ LogUtil.APP.info("JSON字符串替换成功,新JSON:【{}】",jsonStr.toJSONString());
}
map.put("json", jsonStr.toJSONString());
} catch (Exception e) {
- LogUtil.APP.error("格式化成JSON异常,请检查参数:" + json, e);
+ LogUtil.APP.error("格式化成JSON异常,请检查参数:{}",json, e);
return map;
}
} else if (json.startsWith("[") && json.endsWith("]")) {
@@ -356,15 +351,14 @@ public class ChangString {
jsonStr=parseJsonString(jsonStr.toJSONString(),key,value,index);
if(BCHANG){
jsonarr.set(i, jsonStr);
- LogUtil.APP.info(
- "JSONARRAY字符串替换成功,新JSONARRAY:【" + jsonarr.toJSONString() + "】");
+ LogUtil.APP.info("JSONARRAY字符串替换成功,新JSONARRAY:【{}】",jsonarr.toJSONString());
break;
}
}
map.put("json", jsonarr.toJSONString());
} catch (Exception e) {
- LogUtil.APP.error("格式化成JSONArray异常,请检查参数:" + json, e);
+ LogUtil.APP.error("格式化成JSONArray异常,请检查参数:{}",json, e);
return map;
}
}
diff --git a/src/main/java/luckyclient/caserun/publicdispose/ParamsManageForSteps.java b/src/main/java/luckyclient/caserun/publicdispose/ParamsManageForSteps.java
index af57075..43ae4bd 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/ParamsManageForSteps.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/ParamsManageForSteps.java
@@ -55,15 +55,15 @@ public class ParamsManageForSteps {
Random random = new Random();
String replacement = String.valueOf(random.nextInt(endnum - startnum + 1) + startnum);
params = m.replaceFirst(replacement);
- LogUtil.APP.info("Params(" + matcherstr + "):替换成随机数后,字符串:" + params);
+ LogUtil.APP.info("Params({}):替换成随机数后,字符串:{}",matcherstr,params);
m = pattern.matcher(params);
}
return params;
} catch (IllegalArgumentException iae) {
- LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查数字区间是否正常!");
+ LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查数字区间是否正常!",iae);
return params;
} catch (Exception e) {
- LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
+ LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",e);
return params;
}
}
@@ -92,18 +92,18 @@ public class ParamsManageForSteps {
matcherstr=df.format(new Date());
}
} catch (IllegalArgumentException iae) {
- LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
+ LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",iae);
df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
matcherstr=df.format(new Date());
} finally {
params = m.replaceFirst(matcherstr);
- LogUtil.APP.info("Params(" + matcherstr + "):替换成随机数后,字符串:" + params);
+ LogUtil.APP.info("Params({}):替换成随机数后,字符串:{}",matcherstr,params);
m = pattern.matcher(params);
}
}
return params;
} catch (Exception e) {
- LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!");
+ LogUtil.APP.error("处理随机数字参数过程中出现异常,请检查你的格式是否正确!",e);
return params;
}
}
diff --git a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/GetJsonActionParser.java b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/GetJsonActionParser.java
index 686e6d6..38c144b 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/GetJsonActionParser.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/GetJsonActionParser.java
@@ -29,7 +29,7 @@ public class GetJsonActionParser implements ActionKeyWordParser {
key=actionParams;
testResult=SubString.getJsonValue(testResult, key, index);
}
- LogUtil.APP.info("Action(getJV):获取JSON字符串指定Key的值是:"+testResult);
+ LogUtil.APP.info("Action(getJV):获取JSON字符串指定Key的值是:{}",testResult);
return testResult;
}
}
diff --git a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/HeaderParser.java b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/HeaderParser.java
index 1469518..57dcec2 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/HeaderParser.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/HeaderParser.java
@@ -3,6 +3,8 @@ package luckyclient.caserun.publicdispose.actionkeyword;
import com.alibaba.fastjson.JSONObject;
+import luckyclient.publicclass.LogUtil;
+
/**
* 动作关键字的处理接口的实现类:从响应header中取出某个header值
* @author: sunshaoyan
@@ -19,7 +21,9 @@ public class HeaderParser implements ActionKeyWordParser {
public String parse(String actionParams, String testResult) {
String pre = "RESPONSE_HEAD:【";
String headerStr = testResult.substring(testResult.indexOf(pre) + pre.length(), testResult.indexOf("】 RESPONSE_CODE"));
- return JSONObject.parseObject(headerStr).getJSONArray(actionParams).getString(0);
+ String getHeader = JSONObject.parseObject(headerStr).getJSONArray(actionParams).getString(0);
+ LogUtil.APP.info("Action(header):从响应header中取出指定header值是:{}",getHeader);
+ return getHeader;
}
}
diff --git a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentreNumActionParser.java b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentreNumActionParser.java
index 4410ad6..6494597 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentreNumActionParser.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentreNumActionParser.java
@@ -24,7 +24,7 @@ public class SubCentreNumActionParser implements ActionKeyWordParser {
String startnum=actionParams.substring(actionParams.indexOf("[")+1, actionParams.indexOf("]"));
String endnum=actionParams.substring(actionParams.lastIndexOf("[")+1, actionParams.lastIndexOf("]"));
testResult= SubString.subCentreNum(testResult, startnum, endnum);
- LogUtil.APP.info("Action(subCentreNum):截取测试结果指定开始及结束位置字符串:"+testResult);
+ LogUtil.APP.info("Action(subCentreNum):截取测试结果指定开始及结束位置字符串:{}",testResult);
}else{
testResult="步骤动作:subCentreNum 必须是[\"开始字符\"][\"结束字符\"]#subCentreNum 格式,请检查您的步骤动作参数:"+actionParams;
LogUtil.APP.warn("步骤动作:subCentreNum 必须是[\"开始位置(整数)\"][\"结束位置(整数)\"]#subCentreNum 格式,请检查您的步骤动作参数:{}",actionParams);
diff --git a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentresStrActionParser.java b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentresStrActionParser.java
index ebb768e..4e0be18 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentresStrActionParser.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubCentresStrActionParser.java
@@ -25,7 +25,7 @@ public class SubCentresStrActionParser implements ActionKeyWordParser {
startstr=actionParams.substring(actionParams.indexOf("[")+1, actionParams.indexOf("]"));
endstr=actionParams.substring(actionParams.lastIndexOf("[")+1, actionParams.lastIndexOf("]"));
testResult= SubString.subCentreStr(testResult, startstr, endstr);
- LogUtil.APP.info("Action(subCentreStr):截取测试结果指定开始及结束位置字符串:"+testResult);
+ LogUtil.APP.info("Action(subCentreStr):截取测试结果指定开始及结束位置字符串:{}",testResult);
}else{
testResult="步骤动作:subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作参数:"+actionParams;
LogUtil.APP.warn("步骤动作:subCentreStr 必须是[\"开始字符\"][\"结束字符\"]#subCentreStr 格式,请检查您的步骤动作参数:{}",actionParams);
diff --git a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubStrRegxActionParser.java b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubStrRegxActionParser.java
index cc8b606..7e2acdb 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubStrRegxActionParser.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/SubStrRegxActionParser.java
@@ -29,7 +29,7 @@ public class SubStrRegxActionParser implements ActionKeyWordParser {
key=actionParams;
testResult= SubString.subStrRgex(testResult, key, index);
}
- LogUtil.APP.info("Action(subStrRgex):获取JSON字符串指定Key的值是:"+testResult);
+ LogUtil.APP.info("Action(subStrRgex):获取JSON字符串指定Key的值是:{}",testResult);
return testResult;
}
}
diff --git a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/ThreadWaitAction.java b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/ThreadWaitAction.java
index ffc8fdb..c6c70bc 100644
--- a/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/ThreadWaitAction.java
+++ b/src/main/java/luckyclient/caserun/publicdispose/actionkeyword/ThreadWaitAction.java
@@ -23,7 +23,7 @@ public class ThreadWaitAction implements ActionKeyWordParser {
// 获取步骤间等待时间
int time=Integer.parseInt(actionParams);
if (time > 0) {
- LogUtil.APP.info("Action(Wait):线程等待"+time+"秒...");
+ LogUtil.APP.info("Action(Wait):线程等待【{}】秒...",time);
Thread.sleep(time * 1000);
}
} catch (InterruptedException e) {
diff --git a/src/main/java/luckyclient/dblog/LogOperation.java b/src/main/java/luckyclient/dblog/LogOperation.java
index 15f05bb..8e91912 100644
--- a/src/main/java/luckyclient/dblog/LogOperation.java
+++ b/src/main/java/luckyclient/dblog/LogOperation.java
@@ -50,8 +50,7 @@ public class LogOperation {
String imgname) {
if (0 == exetype) {
if (logDetail.length()>5000) {
- LogUtil.APP.info("日志明细超过5000字符,无法进入数据库存储,进行日志明细打印...");
- LogUtil.APP.info("第"+logStep+"步,日志级别"+logGrade+",日志明细【"+logGrade+"】...");
+ LogUtil.APP.info("第{}步,日志级别{},日志明细【{}】...日志明细超过5000字符,无法进入数据库存储,进行日志明细打印...",logStep,logGrade,logDetail);
logDetail="日志明细超过5000字符无法存入数据库,已在LOG4J日志中打印,请前往查看...";
}
@@ -137,7 +136,7 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("获取邮件收件人地址出现异常,请检查!",e);
return address;
}
return address;
@@ -170,7 +169,7 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("获取构建地址出现异常,请检查!",e);
return buildname;
}
return buildname;
@@ -207,7 +206,7 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("获取远程shell地址出现异常,请检查!",e);
return command;
}
return command;
@@ -235,7 +234,7 @@ public class LogOperation {
}
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("获取任务测试时长出现异常,请检查!",e);
return desTime;
}
return desTime;
@@ -252,14 +251,10 @@ public class LogOperation {
driverType = taskScheduling.getBrowserType();
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ LogUtil.APP.error("获取浏览器类型出现异常,请检查!",e);
return driverType;
}
return driverType;
}
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- }
-
}
diff --git a/src/main/java/luckyclient/driven/SubString.java b/src/main/java/luckyclient/driven/SubString.java
index 2c52b4b..59cdd08 100644
--- a/src/main/java/luckyclient/driven/SubString.java
+++ b/src/main/java/luckyclient/driven/SubString.java
@@ -14,6 +14,8 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
+import luckyclient.publicclass.LogUtil;
+
/**
* 公用驱动
* =================================================================
@@ -45,6 +47,7 @@ public class SubString {
String getstr = str.substring(startnum,endnum);
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subCentreStr截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -61,6 +64,7 @@ public class SubString {
String getstr = str.substring(str.indexOf(startstr) + startstr.length());
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subStartStr截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -77,6 +81,7 @@ public class SubString {
String getstr = str.substring(0, str.indexOf(endstr));
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subEndStr截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -116,6 +121,7 @@ public class SubString {
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subCentreNum截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -145,6 +151,7 @@ public class SubString {
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subStartNum截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -174,6 +181,7 @@ public class SubString {
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subEndNum截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -206,6 +214,7 @@ public class SubString {
}
return getstr;
}catch(Exception e){
+ LogUtil.APP.error("subStrRgex截取字符串出现异常,请检查参数!",e);
return "截取字符串出现异常,请检查参数!";
}
}
@@ -351,9 +360,4 @@ public class SubString {
return result;
}
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
-
}
diff --git a/src/main/java/luckyclient/jenkinsapi/BuildingInitialization.java b/src/main/java/luckyclient/jenkinsapi/BuildingInitialization.java
index 2e044b4..7649434 100644
--- a/src/main/java/luckyclient/jenkinsapi/BuildingInitialization.java
+++ b/src/main/java/luckyclient/jenkinsapi/BuildingInitialization.java
@@ -25,7 +25,7 @@ public class BuildingInitialization {
String result = JenkinsBuilding.buildingResult(buildname[i]);
if(result.indexOf("alt=\"Failed\"")>-1){
buildresult = "项目"+buildname[i]+"构建失败,自动化测试退出!";
- LogUtil.APP.warn("项目"+buildname[i]+"构建失败,自动化测试退出!");
+ LogUtil.APP.warn("项目【{}】构建失败,自动化测试退出!",buildname[i]);
break;
}else if(result.indexOf("alt=\"Success\"")>-1){
k++;
@@ -34,7 +34,7 @@ public class BuildingInitialization {
if(buildresult.indexOf("Status:true")<=-1){
break;
}
- LogUtil.APP.info("正在检查构建中的项目(每6秒检查一次)。。。需要构建项目"+buildname.length+"个,目前成功"+k+"个");
+ LogUtil.APP.info("正在检查构建中的项目(每6秒检查一次)。。。需要构建项目【{}】个,目前成功【{}】个",buildname.length,k);
if(k==buildname.length){
break;
}
@@ -67,10 +67,5 @@ public class BuildingInitialization {
return result;
}
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
}
diff --git a/src/main/java/luckyclient/jenkinsapi/JenkinsBuilding.java b/src/main/java/luckyclient/jenkinsapi/JenkinsBuilding.java
index d97de94..9377d61 100644
--- a/src/main/java/luckyclient/jenkinsapi/JenkinsBuilding.java
+++ b/src/main/java/luckyclient/jenkinsapi/JenkinsBuilding.java
@@ -48,7 +48,7 @@ public class JenkinsBuilding {
Map> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
- LogUtil.APP.info(key + "--->" + map.get(key));
+ LogUtil.APP.info("{}--->{}",key,map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
@@ -68,7 +68,7 @@ public class JenkinsBuilding {
in.close();
}
} catch (Exception e2) {
- e2.printStackTrace();
+ LogUtil.APP.error("使用finally块来关闭输入流时出现异常!", e2);
}
}
return result;
@@ -104,7 +104,7 @@ public class JenkinsBuilding {
Map> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
- LogUtil.APP.info(key + "--->" + map.get(key));
+ LogUtil.APP.info("{}--->{}",key,map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
diff --git a/src/main/java/luckyclient/jenkinsapi/RestartServerInitialization.java b/src/main/java/luckyclient/jenkinsapi/RestartServerInitialization.java
index ac86738..8160137 100644
--- a/src/main/java/luckyclient/jenkinsapi/RestartServerInitialization.java
+++ b/src/main/java/luckyclient/jenkinsapi/RestartServerInitialization.java
@@ -21,10 +21,9 @@ public class RestartServerInitialization {
try{
String[] command = LogOperation.getRestartComm(tastid);
if(command!=null){
- LogUtil.APP.info("准备重启指定的TOMCAT!请稍等。。。参数个数:"+command.length);
+ LogUtil.APP.info("准备重启指定的TOMCAT!请稍等。。。参数个数:{}",command.length);
if(command.length==5){
- LogUtil.APP.info("开始调用重启TOMCAT方法。。。参数0:"+command[0]+" 参数1:"+command[1]
- +" 参数2:"+command[2]+" 参数3:"+command[3]+" 参数4:"+command[4]);
+ LogUtil.APP.info("开始调用重启TOMCAT方法。。。参数0:{} 参数1:{} 参数2:{} 参数3:{} 参数4:{}",command[0],command[1],command[2],command[3],command[4]);
result = RmtShellExecutor.sshShell(command[0], command[1], command[2], Integer.valueOf(command[3]), command[4]);
}else{
LogUtil.APP.warn("重启TOMCAT命令行参数出现异常,请检查配置信息!");
@@ -42,9 +41,5 @@ public class RestartServerInitialization {
return result;
}
-
- public static void main(String[] args) {
-
- }
}
diff --git a/src/main/java/luckyclient/jenkinsapi/RmtShellExecutor.java b/src/main/java/luckyclient/jenkinsapi/RmtShellExecutor.java
index 8802c03..ca7efe6 100644
--- a/src/main/java/luckyclient/jenkinsapi/RmtShellExecutor.java
+++ b/src/main/java/luckyclient/jenkinsapi/RmtShellExecutor.java
@@ -33,7 +33,7 @@ public class RmtShellExecutor {
String result = "Status:true"+" 重启命令执行成功!";
try {
JSch jsch = new JSch();
- LogUtil.APP.info("进入到重启TOMCAT方法。。。");
+ LogUtil.APP.info("进入到重启TOMCAT方法...");
//设置密钥和密码
if (privateKey != null && !"".equals(privateKey)) {
if (passphrase != null && "".equals(passphrase)) {
@@ -47,11 +47,11 @@ public class RmtShellExecutor {
if(port <=0){
//连接服务器,采用默认端口
- LogUtil.APP.info("设置重启TOMCAT服务器IP及默认端口。。。");
+ LogUtil.APP.info("设置重启TOMCAT服务器IP及默认端口...");
session = jsch.getSession(user, ip);
}else{
//采用指定的端口连接服务器
- LogUtil.APP.info("设置重启TOMCAT服务器IP及端口。。。");
+ LogUtil.APP.info("设置重启TOMCAT服务器IP及端口...");
session = jsch.getSession(user, ip ,port);
LogUtil.APP.info("设置重启TOMCAT服务器IP及端口完成!");
}
@@ -96,13 +96,13 @@ public class RmtShellExecutor {
//转换输出结果并打印出来
String temp = new String(data, 0, nLen,"iso8859-1");
- LogUtil.APP.info("开始打印重启TOMCAT命令执行结果"+temp);
+ LogUtil.APP.info("开始打印重启TOMCAT命令执行结果...",temp);
}
outstream.close();
instream.close();
} catch (Exception e) {
result = "重启TOMCAT过程中,出现异常!";
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("重启TOMCAT过程中,出现异常!", e);
return result;
} finally {
if(null!=session){
diff --git a/src/main/java/luckyclient/mail/FreemarkerEmailTemplate.java b/src/main/java/luckyclient/mail/FreemarkerEmailTemplate.java
index 52cbbb5..7b5b8d1 100644
--- a/src/main/java/luckyclient/mail/FreemarkerEmailTemplate.java
+++ b/src/main/java/luckyclient/mail/FreemarkerEmailTemplate.java
@@ -8,6 +8,7 @@ import java.util.Properties;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
+import luckyclient.publicclass.LogUtil;
import luckyclient.publicclass.SysConfig;
/**
@@ -58,6 +59,7 @@ public class FreemarkerEmailTemplate {
template.process(parameters, stringWriter);
return stringWriter.toString();
} catch (Exception e) {
+ LogUtil.APP.error("获取邮件模板引擎配置出现异常",e);
throw new RuntimeException(e);
}
}
diff --git a/src/main/java/luckyclient/mail/HtmlMail.java b/src/main/java/luckyclient/mail/HtmlMail.java
index 06cc7fe..aaff524 100644
--- a/src/main/java/luckyclient/mail/HtmlMail.java
+++ b/src/main/java/luckyclient/mail/HtmlMail.java
@@ -38,7 +38,7 @@ public class HtmlMail {
Map headmsg = new HashMap<>(0);
Properties properties = SysConfig.getConfiguration();
if ("true".equals(properties.getProperty("task.push.switch").toLowerCase())) {
- LogUtil.APP.info("开始向第三方平台推送任务执行情况....");
+ LogUtil.APP.info("开始向第三方平台推送任务执行情况...");
Map pushparameters = new HashMap<>(0);
pushparameters.put("buildstatus", buildstatus);
pushparameters.put("restartstatus", restartstatus);
@@ -59,7 +59,6 @@ public class HtmlMail {
}
} catch (Exception e) {
LogUtil.APP.error("向第三方平台推送任务执行情况出现异常,请检查!", e);
- e.printStackTrace();
return fet.getText("task-body", parameters);
}
return fet.getText("task-body", parameters);
diff --git a/src/main/java/luckyclient/mail/MailSendInitialization.java b/src/main/java/luckyclient/mail/MailSendInitialization.java
index 709edd5..e736d5c 100644
--- a/src/main/java/luckyclient/mail/MailSendInitialization.java
+++ b/src/main/java/luckyclient/mail/MailSendInitialization.java
@@ -51,7 +51,7 @@ public class MailSendInitialization {
String[] addresses = LogOperation.getEmailAddress(taskid);
Properties properties = SysConfig.getConfiguration();
if (addresses != null) {
- LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等。。。。");
+ LogUtil.APP.info("准备将测试结果发送邮件通知!请稍等...");
//这个类主要是设置邮件
MailSenderInfo mailInfo = new MailSenderInfo();
//这个类主要来发送邮件
@@ -77,17 +77,13 @@ public class MailSendInitialization {
}
String addressesmail = stringBuilder.toString();
if (sms.sendHtmlMail(mailInfo)) {
- LogUtil.APP.info("给" + addressesmail + "的测试结果通知邮件发送完成!");
+ LogUtil.APP.info("给{}的测试结果通知邮件发送完成!",addressesmail);
} else {
- LogUtil.APP.warn("给" + addressesmail + "的测试结果通知邮件发送失败!");
+ LogUtil.APP.warn("给{}的测试结果通知邮件发送失败!",addressesmail);
}
} else {
LogUtil.APP.info("当前任务不需要发送邮件通知!");
}
}
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- }
-
}
diff --git a/src/main/java/luckyclient/mail/MailSenderInfo.java b/src/main/java/luckyclient/mail/MailSenderInfo.java
index a5e8552..91ddf43 100644
--- a/src/main/java/luckyclient/mail/MailSenderInfo.java
+++ b/src/main/java/luckyclient/mail/MailSenderInfo.java
@@ -78,7 +78,7 @@ public class MailSenderInfo {
p.put("mail.smtp.ssl.socketFactory", sf);
}
} catch (GeneralSecurityException e) {
- LogUtil.APP.error("获得邮件会话属性失败或异常: " + e.getMessage());
+ LogUtil.APP.error("获得邮件会话属性失败或异常: ",e);
return null;
}
return p;
diff --git a/src/main/java/luckyclient/publicclass/AppiumConfig.java b/src/main/java/luckyclient/publicclass/AppiumConfig.java
index 3c6b74d..5590b2d 100644
--- a/src/main/java/luckyclient/publicclass/AppiumConfig.java
+++ b/src/main/java/luckyclient/publicclass/AppiumConfig.java
@@ -19,7 +19,7 @@ public class AppiumConfig {
InputStream in = new BufferedInputStream(AppiumConfig.class.getResourceAsStream(SYS_CONFIG_FILE));
SYS_CONFIG.load(new InputStreamReader(in, "UTF-8"));
} catch (IOException e) {
- e.printStackTrace();
+ LogUtil.APP.error("读取移动端appium_config.properties配置文件出现异常,请检查!", e);
}
}
private AppiumConfig(){}
diff --git a/src/main/java/luckyclient/publicclass/InvokeMethod.java b/src/main/java/luckyclient/publicclass/InvokeMethod.java
index e072dae..798df64 100644
--- a/src/main/java/luckyclient/publicclass/InvokeMethod.java
+++ b/src/main/java/luckyclient/publicclass/InvokeMethod.java
@@ -83,7 +83,7 @@ public class InvokeMethod {
}
String templateidstr = extend.substring(1, extend.indexOf("】"));
String templatenamestr = extend.substring(extend.indexOf("】") + 1);
- LogUtil.APP.info("即将使用模板【" + templatenamestr + "】,ID:【" + templateidstr + "】发送HTTP请求!");
+ LogUtil.APP.info("即将使用模板【{}】,ID:【{}】发送HTTP请求!",templatenamestr,templateidstr);
ProjectProtocolTemplate ppt = GetServerAPI.clientGetProjectProtocolTemplateByTemplateId(Integer.valueOf(templateidstr));
if (null == ppt) {
@@ -134,7 +134,7 @@ public class InvokeMethod {
if (key.contains("[") && key.endsWith("]")) {
index = Integer.valueOf(key.substring(key.lastIndexOf("[") + 1, key.lastIndexOf("]")));
key = key.substring(0, key.lastIndexOf("["));
- LogUtil.APP.info("准备替换JSON对象中的参数值,替换指定第" + index + "个参数...");
+ LogUtil.APP.info("准备替换JSON对象中的参数值,替换指定第{}个参数...",index);
} else {
LogUtil.APP.info("准备替换JSON对象中的参数值,未检测到指定参数名序号,默认替换第1个参数...");
}
@@ -145,14 +145,14 @@ public class InvokeMethod {
ptp.setParamValue(map.get("json"));
paramslist.set(i, ptp);
replaceflag=1;
- LogUtil.APP.info("替换参数"+key+"完成...");
+ LogUtil.APP.info("替换参数【{}】完成...",key);
break;
}
}else if(ptp.getParamValue().contains(key)){
ptp.setParamValue(ptp.getParamValue().replace(key, value));
paramslist.set(i, ptp);
replaceflag=1;
- LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParamValue()+"】中直接把【"+key+"】替换成【"+value+"】...");
+ LogUtil.APP.info("检查当前文本不属于JSON,在字符串【{}】中直接把【{}】替换成【{}】...",ptp.getParamValue(),key,value);
break;
}else{
LogUtil.APP.warn("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
@@ -162,14 +162,14 @@ public class InvokeMethod {
ptp.setParamValue(value);
paramslist.set(i, ptp);
replaceflag=1;
- LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"】");
+ LogUtil.APP.info("把模板中参数【{}】的值设置成【{}】",key,value);
break;
}
}
}
if(replaceflag==0){
- LogUtil.APP.warn("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
- + "设置请求参数失败,请检查协议模板中此参数是否存在。");
+ LogUtil.APP.warn("步骤参数【{}】没有在模板中找到可替换的参数对应默认值,"
+ + "设置请求参数失败,请检查协议模板中此参数是否存在。",key);
}
}else{
LogUtil.APP.warn("替换模板或是头域参数失败,原因是因为没有检测到#,"
@@ -191,26 +191,26 @@ public class InvokeMethod {
if (ptp.getParamType() == 1) {
JSONObject json = JSONObject.parseObject(tempparam);
params.put(ptp.getParamName().replace(""", "\""), json);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONObject类型参数值:【" + json.toString() + "】");
+ LogUtil.APP.info("模板参数【{}】 JSONObject类型参数值:【{}】",ptp.getParamName(),json.toString());
} else if (ptp.getParamType() == 2) {
JSONArray jarr = JSONArray.parseArray(tempparam);
params.put(ptp.getParamName().replace(""", "\""), jarr);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONArray类型参数值:【" + jarr.toString() + "】");
+ LogUtil.APP.info("模板参数【{}】 JSONArray类型参数值:【{}】",ptp.getParamName(),jarr.toString());
} else if (ptp.getParamType() == 3) {
File file = new File(tempparam);
params.put(ptp.getParamName().replace(""", "\""), file);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 File类型参数值:【" + file.getAbsolutePath() + "】");
+ LogUtil.APP.info("模板参数【{}】 File类型参数值:【{}】",ptp.getParamName(),file.getAbsolutePath());
} else if (ptp.getParamType() == 4) {
Double dp = Double.valueOf(tempparam);
params.put(ptp.getParamName().replace(""", "\""), dp);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 数字类型参数值:【" + tempparam + "】");
+ LogUtil.APP.info("模板参数【{}】 数字类型参数值:【{}】",ptp.getParamName(),tempparam);
} else if (ptp.getParamType() == 5) {
Boolean bn = Boolean.valueOf(tempparam);
params.put(ptp.getParamName().replace(""", "\""), bn);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 Boolean类型参数值:【" + bn + "】");
+ LogUtil.APP.info("模板参数【{}】 Boolean类型参数值:【{}】",ptp.getParamName(),bn);
} else {
params.put(ptp.getParamName().replace(""", "\""), ptp.getParamValue().replace(""", "\""));
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 String类型参数值:【" + ptp.getParamValue().replace(""", "\"") + "】");
+ LogUtil.APP.info("模板参数【{}】 String类型参数值:【{}】",ptp.getParamName(),ptp.getParamValue().replace(""", "\""));
}
}
@@ -240,13 +240,13 @@ public class InvokeMethod {
} else if (functionname.toLowerCase().equals("httpclientget")) {
result = HttpClientHelper.httpClientGet(packagename, params, headmsg, ppt);
} else {
- LogUtil.APP.warn("您的HTTP操作方法异常,检测到的操作方法是:" + functionname);
+ LogUtil.APP.warn("您的HTTP操作方法异常,检测到的操作方法是:{}",functionname);
result = "调用异常,请查看错误日志!";
}
} else if (steptype == 4) {
String templateidstr = extend.substring(1, extend.indexOf("】"));
String templatenamestr = extend.substring(extend.indexOf("】") + 1);
- LogUtil.APP.info("即将使用模板【" + templatenamestr + "】,ID:【" + templateidstr + "】 发送SOCKET请求!");
+ LogUtil.APP.info("即将使用模板【{}】,ID:【{}】 发送SOCKET请求!",templatenamestr,templateidstr);
ProjectProtocolTemplate ppt = GetServerAPI.clientGetProjectProtocolTemplateByTemplateId(Integer.valueOf(templateidstr));
if (null == ppt) {
@@ -297,7 +297,7 @@ public class InvokeMethod {
key = key.substring(0, key.lastIndexOf("["));
LogUtil.APP.info("准备替换JSON对象中的参数值,未检测到指定参数名序号,默认替换第1个参数...");
} else {
- LogUtil.APP.info("准备替换JSON对象中的参数值,替换指定第" + index + "个参数...");
+ LogUtil.APP.info("准备替换JSON对象中的参数值,替换指定第【{}】个参数...",index);
}
Map map=ChangString.changjson(ptp.getParamValue(), key, value,index);
@@ -305,14 +305,14 @@ public class InvokeMethod {
ptp.setParamValue(map.get("json"));
paramslist.set(i, ptp);
replaceflag=1;
- LogUtil.APP.info("替换参数"+key+"完成...");
+ LogUtil.APP.info("替换参数【{}】完成...",key);
break;
}
}else if(ptp.getParamValue().indexOf(key)>=0){
ptp.setParamValue(ptp.getParamValue().replace(key, value));
paramslist.set(i, ptp);
replaceflag=1;
- LogUtil.APP.info("检查当前文本不属于JSON,在字符串【"+ptp.getParamValue()+"】中直接把【"+key+"】替换成【"+value+"】...");
+ LogUtil.APP.info("检查当前文本不属于JSON,在字符串【{}】中直接把【{}】替换成【{}】...",ptp.getParamValue(),key,value);
break;
}else{
LogUtil.APP.warn("请检查您的纯文本模板是否是正常的JSON格式或是文本中是否存在需替换的关键字。");
@@ -322,14 +322,14 @@ public class InvokeMethod {
ptp.setParamValue(value);
paramslist.set(i, ptp);
replaceflag=1;
- LogUtil.APP.info("把模板中参数【"+key+"】的值设置成【"+value+"】");
+ LogUtil.APP.info("把模板中参数【{}】的值设置成【{}】",key,value);
break;
}
}
}
if(replaceflag==0){
- LogUtil.APP.warn("步骤参数【"+key+"】没有在模板中找到可替换的参数对应默认值,"
- + "设置请求参数失败,请检查协议模板中此参数是否存在。");
+ LogUtil.APP.warn("步骤参数【{}】没有在模板中找到可替换的参数对应默认值,"
+ + "设置请求参数失败,请检查协议模板中此参数是否存在。",key);
}
}else{
LogUtil.APP.warn("替换模板或是头域参数失败,原因是因为没有检测到#,"
@@ -349,26 +349,26 @@ public class InvokeMethod {
if (ptp.getParamType() == 1) {
JSONObject json = JSONObject.parseObject(tempparam);
params.put(ptp.getParamName().replace(""", "\""), json);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONObject类型参数值:【" + json.toString() + "】");
+ LogUtil.APP.info("模板参数【{}】 JSONObject类型参数值:【{}】",ptp.getParamName(),json.toString());
} else if (ptp.getParamType() == 2) {
JSONArray jarr = JSONArray.parseArray(tempparam);
params.put(ptp.getParamName().replace(""", "\""), jarr);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 JSONArray类型参数值:【" + jarr.toString() + "】");
+ LogUtil.APP.info("模板参数【{}】 JSONArray类型参数值:【{}】",ptp.getParamName(),jarr.toString());
} else if (ptp.getParamType() == 3) {
File file = new File(tempparam);
params.put(ptp.getParamName().replace(""", "\""), file);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 File类型参数值:【" + file.getAbsolutePath() + "】");
+ LogUtil.APP.info("模板参数【{}】 File类型参数值:【{}】",ptp.getParamName(),file.getAbsolutePath());
} else if (ptp.getParamType() == 4) {
Double dp = Double.valueOf(tempparam);
params.put(ptp.getParamName().replace(""", "\""), dp);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 数字类型参数值:【" + tempparam + "】");
+ LogUtil.APP.info("模板参数【{}】 数字类型参数值:【{}】",ptp.getParamName(),tempparam);
} else if (ptp.getParamType() == 5) {
Boolean bn = Boolean.valueOf(tempparam);
params.put(ptp.getParamName().replace(""", "\""), bn);
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 Boolean类型参数值:【" + bn + "】");
+ LogUtil.APP.info("模板参数【{}】 Boolean类型参数值:【{}】",ptp.getParamName(),bn);
} else {
params.put(ptp.getParamName().replace(""", "\""), ptp.getParamValue().replace(""", "\""));
- LogUtil.APP.info("模板参数【" + ptp.getParamName() + "】 String类型参数值:【" + ptp.getParamValue().replace(""", "\"") + "】");
+ LogUtil.APP.info("模板参数【{}】 String类型参数值:【{}】",ptp.getParamName(),ptp.getParamValue().replace(""", "\""));
}
}
@@ -378,12 +378,12 @@ public class InvokeMethod {
} else if (functionname.toLowerCase().equals("socketget")) {
result = HttpClientHelper.sendSocketGet(packagename, params, ppt.getEncoding().toLowerCase(), headmsg);
} else {
- LogUtil.APP.warn("您的SOCKET操作方法异常,检测到的操作方法是:" + functionname);
+ LogUtil.APP.warn("您的SOCKET操作方法异常,检测到的操作方法是:{}",functionname);
result = "调用异常,请查看错误日志!";
}
}
} catch (Throwable e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("调用异常,请查看错误日志!", e);
return "调用异常,请查看错误日志!";
}
return result;
@@ -457,7 +457,7 @@ public class InvokeMethod {
args[1]=packagename+File.separator+functionname;
//args[1]="E:\\PycharmProjects\\untitled\\venv\\testaaa.py";
}
- LogUtil.APP.info("调用Python脚本路径:"+args[1]);
+ LogUtil.APP.info("调用Python脚本路径:{}",args[1]);
for(int i=0;i < params;i++){
args[2+i]=getParameterValues[i].toString();
}
@@ -479,29 +479,24 @@ public class InvokeMethod {
// 打印流信息
if(outerrStream.toString().equals("")){
result = outStream.toString().trim();
- LogUtil.APP.info("成功调用Python脚本,返回结果:"+result);
+ LogUtil.APP.info("成功调用Python脚本,返回结果:{}",result);
}else{
result = outerrStream.toString().trim();
if(result.indexOf("ModuleNotFoundError")>-1){
LogUtil.APP.warn("调用Python脚本出现异常,有相关Python模块未引用到,请在Python脚本中注意设置系统环境路径(例: sys.path.append(\"E:\\PycharmProjects\\untitled\\venv\\Lib\\site-packages\")),"
- + "详细错误信息:"+result);
+ + "详细错误信息:{}",result);
}else if(result.indexOf("No such file or directory")>-1){
- LogUtil.APP.warn("调用Python脚本出现异常,在指定路径下未找到Python脚本,原因有可能是Python脚本路径错误或是传入Python指定参数个数不一致,详细错误信息:"+result);
+ LogUtil.APP.warn("调用Python脚本出现异常,在指定路径下未找到Python脚本,原因有可能是Python脚本路径错误或是传入Python指定参数个数不一致,详细错误信息:{}",result);
}else{
- LogUtil.APP.warn("调用Python脚本出现异常,错误信息:"+result);
+ LogUtil.APP.warn("调用Python脚本出现异常,错误信息:{}",result);
}
}
}
catch (Exception e) {
- e.printStackTrace();
+ LogUtil.APP.error("调用Python脚本出现异常,请检查!",e);
return result;
}
return result;
}
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
}
diff --git a/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java b/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java
index 44d76ab..d161e09 100644
--- a/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java
+++ b/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java
@@ -87,7 +87,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
@@ -100,7 +100,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置HTTPURLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"】");
+ LogUtil.APP.info("设置HTTPURLPost参数信息...key:【{}】 value:【{}】",e.getKey(),e.getValue());
}
}
}
@@ -121,11 +121,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTPURLPost头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTPURLPost头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@@ -161,14 +161,14 @@ public class HttpClientHelper {
resultBuffer.append("Content-Length=0");
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送post请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送post请求后关闭流出现异常,请检查!", e);
osw = null;
throw new RuntimeException(e);
} finally {
@@ -182,7 +182,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送post请求后关闭流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
} finally {
@@ -214,7 +214,7 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&¶ms.containsKey("_forTextJson")){
@@ -226,7 +226,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置URLPost参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"】");
+ LogUtil.APP.info("设置URLPost参数信息...key:【{}】 value:【{}】",e.getKey(),e.getValue());
}
}
}
@@ -246,11 +246,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换URLPost头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换URLPost头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@@ -293,14 +293,14 @@ public class HttpClientHelper {
resultBuffer.append("Content-Length=0");
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用URLConnection发送post请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用URLConnection发送post请求后关闭osw流出现异常,请检查!", e);
osw = null;
throw new RuntimeException(e);
}
@@ -309,7 +309,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用URLConnection发送post请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -328,7 +328,7 @@ public class HttpClientHelper {
*/
public static String sendGetAndSaveFile(String urlParam, Map params, String fileSavePath, Map headmsg,ProjectProtocolTemplate ppt) {
// 构建请求参数
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
int timeout=ppt.getTimeout();
int responsehead=ppt.getIsResponseHead();
int responsecode=ppt.getIsResponseCode();
@@ -343,7 +343,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置HTTPSaveFile参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"】");
+ LogUtil.APP.info("设置HTTPSaveFile参数信息...key:【{}】 value:【{}】",entry.getKey(),entry.getValue());
}
}
}
@@ -363,11 +363,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTPSaveFile头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTPSaveFile头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@@ -395,14 +395,14 @@ public class HttpClientHelper {
os.flush();
return resultBuffer.toString()+"下载文件成功,请前往客户端路径:" + fileSavePath + " 查看附件。";
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("发送get请求保存下载文件出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("发送get请求保存下载文件后关闭OS流出现异常,请检查!", e);
os = null;
throw new RuntimeException(e);
} finally {
@@ -416,7 +416,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("发送get请求保存下载文件后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
} finally {
@@ -446,7 +446,7 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&¶ms.containsKey("_forTextJson")){
@@ -458,7 +458,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置HTTPURLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"】");
+ LogUtil.APP.info("设置HTTPURLGet参数信息...key:【{}】 value:【{}】",entry.getKey(),entry.getValue());
}
}
}
@@ -477,11 +477,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTPURLGet头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTPURLGet头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@@ -507,14 +507,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常!响应码:"+con.getResponseCode());
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送get请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送get请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
} finally {
@@ -545,7 +545,7 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&¶ms.containsKey("_forTextJson")){
@@ -557,7 +557,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置URLGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"】");
+ LogUtil.APP.info("设置URLGet参数信息...key:【{}】 value:【{}】",entry.getKey(),entry.getValue());
}
}
@@ -580,11 +580,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换URLGet头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换URLGet头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
con.setRequestProperty(key, value);
}else{
con.setRequestProperty(key, value);
@@ -611,14 +611,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常!");
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用URLConnection发送get请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用URLConnection发送get请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -646,7 +646,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPost httpPost = new HttpPost(urlParam);
httpPost.setHeader("Content-Type", "application/json");
@@ -659,11 +659,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTPPostJson头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTPPostJson头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@@ -674,12 +674,12 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&¶ms.containsKey("_forTextJson")){
- LogUtil.APP.info("参数类型:TEXT,设置HTTPPostJson参数信息...【"+params.get("_forTextJson").toString()+"】");
+ 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);
- LogUtil.APP.info("参数类型:FORM,设置HTTPPostJson参数信息...【"+jsonString+"】");
+ LogUtil.APP.info("参数类型:FORM,设置HTTPPostJson参数信息...【{}】",jsonString);
StringEntity entity = new StringEntity(jsonString,charset);
httpPost.setEntity(entity);
}
@@ -708,14 +708,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient以JSON格式发送post请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient以JSON格式发送post请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -744,7 +744,7 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
HttpPost httpPost = new HttpPost(urlParam);
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(timeout)
@@ -755,11 +755,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTPClientPost头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTPClientPost头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@@ -777,7 +777,7 @@ public class HttpClientHelper {
List nvps = new ArrayList ();
for (Map.Entry m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
- LogUtil.APP.info("设置HTTPClientPost参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"】");
+ LogUtil.APP.info("设置HTTPClientPost参数信息...key:【{}】 value:【{}】",m.getKey(),m.getValue());
}
httpPost.setEntity(new UrlEncodedFormEntity(nvps,charset));
}
@@ -806,14 +806,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常,响应码:"+response.getStatusLine().getStatusCode());
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送post请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送post请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -842,7 +842,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPost httpPost = new HttpPost(urlParam);
RequestConfig requestConfig = RequestConfig.custom()
@@ -854,11 +854,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换httpClientUploadFile头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换httpClientUploadFile头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
httpPost.setHeader(key, value);
}else{
httpPost.setHeader(key, value);
@@ -880,10 +880,10 @@ public class HttpClientHelper {
for (Map.Entry m :params.entrySet()) {
if (m.getValue() instanceof File) {
entityBuilder.addBinaryBody(m.getKey(), (File)m.getValue());
- LogUtil.APP.info("设置httpClientUploadFile 上传文件参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"】");
+ LogUtil.APP.info("设置httpClientUploadFile 上传文件参数信息...key:【{}】 value:【{}】",m.getKey(),m.getValue());
}else{
entityBuilder.addTextBody(m.getKey(), m.getValue().toString());
- LogUtil.APP.info("设置httpClientUploadFile参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"】");
+ LogUtil.APP.info("设置httpClientUploadFile参数信息...key:【{}】 value:【{}】",m.getKey(),m.getValue());
}
}
HttpEntity reqEntity =entityBuilder.build();
@@ -914,14 +914,14 @@ public class HttpClientHelper {
resultBuffer.append("读取服务器响应数据异常,响应码:"+response.getStatusLine().getStatusCode());
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient上传文件出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient上传文件后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -949,7 +949,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
BufferedReader br = null;
// 构建请求参数
@@ -965,11 +965,11 @@ public class HttpClientHelper {
try {
sbParams.append(URLEncoder.encode(String.valueOf(entry.getValue()), charset));
} catch (UnsupportedEncodingException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送get请求拼接URL时出现异常,请检查!", e);
throw new RuntimeException(e);
}
sbParams.append("&");
- LogUtil.APP.info("设置HTTPClientGet参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"】");
+ LogUtil.APP.info("设置HTTPClientGet参数信息...key:【{}】 value:【{}】",entry.getKey(),entry.getValue());
}
}
@@ -987,11 +987,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTPClientGet头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTPClientGet头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
httpGet.setHeader(key, value);
}else{
httpGet.setHeader(key, value);
@@ -1019,14 +1019,14 @@ public class HttpClientHelper {
resultBuffer.append(temp);
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送get请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送get请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -1046,7 +1046,7 @@ public class HttpClientHelper {
public static String sendSocketPost(String urlParam, Map params, String charset,
Map headmsg) {
String result = "";
- LogUtil.APP.info("设置Socket请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置Socket请求地址:【{}】",urlParam);
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
@@ -1059,7 +1059,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"】");
+ LogUtil.APP.info("设置SocketPost参数信息...key:【{}】 value:【{}】",entry.getKey(),entry.getValue());
}
}
}
@@ -1084,11 +1084,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换Socket头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换Socket头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
sb.append(key+": "+value+" \r\n");
}else{
sb.append(key+": "+value+" \r\n");
@@ -1119,14 +1119,14 @@ public class HttpClientHelper {
// 读取出响应体数据(就是你要的数据)
result = readLine(is, contentLength, charset);
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送post请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送post请求后关闭osw流出现异常,请检查!", e);
osw = null;
throw new RuntimeException(e);
} finally {
@@ -1134,7 +1134,7 @@ public class HttpClientHelper {
try {
socket.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送post请求后关闭socket出现异常,请检查!", e);
socket = null;
throw new RuntimeException(e);
}
@@ -1145,7 +1145,7 @@ public class HttpClientHelper {
try {
is.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送post请求后关闭socket is对象出现异常,请检查!", e);
is = null;
throw new RuntimeException(e);
} finally {
@@ -1154,7 +1154,7 @@ public class HttpClientHelper {
socket.close();
} catch (IOException e) {
socket = null;
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送post请求后关闭socket出现异常,请检查!", e);
throw new RuntimeException(e);
}
}
@@ -1174,7 +1174,7 @@ public class HttpClientHelper {
*/
public static String sendSocketGet(String urlParam, Map params, String charset,Map headmsg) {
String result = "";
- LogUtil.APP.info("设置Socket请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置Socket请求地址:【{}】",urlParam);
// 构建请求参数
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
@@ -1187,7 +1187,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(entry.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置SocketPost参数信息...key:【"+entry.getKey()+"】 value:【"+entry.getValue()+"】");
+ LogUtil.APP.info("设置SocketPost参数信息...key:【{}】 value:【{}】",entry.getKey(),entry.getValue());
}
}
@@ -1213,11 +1213,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换Socket头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换Socket头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
sb.append(key+": "+value+" \r\n");
}else{
sb.append(key+": "+value+" \r\n");
@@ -1248,14 +1248,14 @@ public class HttpClientHelper {
// 读取出响应体数据(就是你要的数据)
result = readLine(is, contentLength, charset);
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送get请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送get请求后关闭osw流出现异常,请检查!", e);
osw = null;
throw new RuntimeException(e);
} finally {
@@ -1263,7 +1263,7 @@ public class HttpClientHelper {
try {
socket.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送get请求后关闭socket出现异常,请检查!", e);
socket = null;
throw new RuntimeException(e);
}
@@ -1274,7 +1274,7 @@ public class HttpClientHelper {
try {
is.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送get请求后关闭socket is对象出现异常,请检查!", e);
is = null;
throw new RuntimeException(e);
} finally {
@@ -1282,7 +1282,7 @@ public class HttpClientHelper {
try {
socket.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用socket发送get请求后关闭socket对象出现异常,请检查!", e);
socket = null;
throw new RuntimeException(e);
}
@@ -1344,7 +1344,7 @@ public class HttpClientHelper {
StringBuffer resultBuffer = null;
// 构建请求参数
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
StringBuffer sbParams = new StringBuffer();
if (params != null && params.size() > 0) {
if(1==params.size()&¶ms.containsKey("_forTextJson")){
@@ -1356,7 +1356,7 @@ public class HttpClientHelper {
sbParams.append("=");
sbParams.append(e.getValue());
sbParams.append("&");
- LogUtil.APP.info("设置HttpURLDel参数信息...key:【"+e.getKey()+"】 value:【"+e.getValue()+"】");
+ LogUtil.APP.info("设置HttpURLDel参数信息...key:【{}】 value:【{}】",e.getKey(),e.getValue());
}
}
}
@@ -1376,11 +1376,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
con.setRequestProperty(key,value);
}else{
con.setRequestProperty(key,value);
@@ -1413,14 +1413,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送delete请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送delete请求后关闭osw流出现异常,请检查!", e);
osw = null;
throw new RuntimeException(e);
} finally {
@@ -1434,7 +1434,7 @@ public class HttpClientHelper {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpURLConnection发送delete请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
} finally {
@@ -1469,7 +1469,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPut httpput = new HttpPut(urlParam);
httpput.setHeader("Content-Type", "application/json");
@@ -1482,11 +1482,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
httpput.setHeader(key,value);
}else{
httpput.setHeader(key,value);
@@ -1497,12 +1497,12 @@ public class HttpClientHelper {
try {
if(params.size()>0){
if(1==params.size()&¶ms.containsKey("_forTextJson")){
- LogUtil.APP.info("参数类型:TEXT,设置HTTPClientPutJson参数信息...【"+params.get("_forTextJson").toString()+"】");
+ 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);
- LogUtil.APP.info("参数类型:FORM,设置HTTPClientPutJson参数信息...【"+jsonString+"】");
+ LogUtil.APP.info("参数类型:FORM,设置HTTPClientPutJson参数信息...【{}】",jsonString);
StringEntity entity = new StringEntity(jsonString,charset);
httpput.setEntity(entity);
}
@@ -1532,14 +1532,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送put请求(参数JSON格式)出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送put请求(参数JSON格式)后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -1567,7 +1567,7 @@ public class HttpClientHelper {
int responsecode=ppt.getIsResponseCode();
StringBuffer resultBuffer = null;
- LogUtil.APP.info("设置HTTP请求地址:【"+urlParam+"】");
+ LogUtil.APP.info("设置HTTP请求地址:【{}】",urlParam);
CloseableHttpClient httpclient=iniHttpClient(urlParam,cerpath);
HttpPut httpput = new HttpPut(urlParam);
RequestConfig requestConfig = RequestConfig.custom()
@@ -1579,11 +1579,11 @@ public class HttpClientHelper {
for (Map.Entry m :headmsg.entrySet()) {
String key=m.getKey();
String value=m.getValue();
- LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【"+key+"】 value:【"+value+"】");
+ LogUtil.APP.info("开始设置|替换HTTP头域信息...key:【{}】 value:【{}】",key,value);
if(null!=value&&value.indexOf("Base64(")==0){
String valuesub=value.substring(value.indexOf("Base64(")+7,value.lastIndexOf(")"));
value="Basic " + DatatypeConverter.printBase64Binary((valuesub).getBytes());
- LogUtil.APP.info("将头域【"+key+"】的值【"+value+"】FORMAT成BASE64格式...");
+ LogUtil.APP.info("将头域【{}】的值【{}】FORMAT成BASE64格式...",key,value);
httpput.setHeader(key,value);
}else{
httpput.setHeader(key,value);
@@ -1601,7 +1601,7 @@ public class HttpClientHelper {
List nvps = new ArrayList ();
for (Map.Entry m :params.entrySet()) {
nvps.add(new BasicNameValuePair(m.getKey(), m.getValue().toString()));
- LogUtil.APP.info("开始设置HTTPClientPut参数信息...key:【"+m.getKey()+"】 value:【"+m.getValue()+"】");
+ LogUtil.APP.info("开始设置HTTPClientPut参数信息...key:【{}】 value:【{}】",m.getKey(),m.getValue());
}
httpput.setEntity(new UrlEncodedFormEntity(nvps,charset));
}
@@ -1631,14 +1631,14 @@ public class HttpClientHelper {
}
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送put请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("使用HttpClient发送put请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -1657,7 +1657,7 @@ public class HttpClientHelper {
SSLContext sslContext = null;
FileInputStream instream = null;
KeyStore trustStore = null;
- LogUtil.APP.info("证书路径:"+keyStorePath+" 密钥:"+keyStorepass);
+ LogUtil.APP.info("证书路径:{} 密钥:{}",keyStorePath,keyStorepass);
try {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
LogUtil.APP.info("开始读取证书文件流...");
@@ -1674,12 +1674,12 @@ public class HttpClientHelper {
sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tms, new java.security.SecureRandom());
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("设置信任自签名证书出现异常,请检查!", e);
} finally {
try {
instream.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("设置信任自签名证书后关闭instream流出现异常,请检查!", e);
}
}
return sslContext;
diff --git a/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java b/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java
index fa08478..328ac5d 100644
--- a/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java
+++ b/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java
@@ -62,14 +62,14 @@ public class HttpRequest {
resultBuffer.append(temp);
}
} catch (Exception e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("loadJSON发送请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
- LogUtil.APP.error(e.getMessage(), e);
+ LogUtil.APP.error("loadJSON发送请求后关闭br流出现异常,请检查!", e);
br = null;
throw new RuntimeException(e);
}
@@ -116,8 +116,7 @@ public class HttpRequest {
result += line;
}
} catch (Exception e) {
- System.out.println("发送 POST 请求出现异常!"+e);
- e.printStackTrace();
+ LogUtil.APP.error("向指定URL发送POST方法的请求出现异常,请检查!", e);
}
//使用finally块来关闭输出流、输入流
finally{
@@ -130,7 +129,7 @@ public class HttpRequest {
}
}
catch(IOException ex){
- ex.printStackTrace();
+ LogUtil.APP.error("向指定URL发送POST方法的请求后关闭流出现异常,请检查!", ex);
}
}
return result;
@@ -175,6 +174,7 @@ public class HttpRequest {
}
}
} catch (Exception e) {
+ LogUtil.APP.error("使用HttpClient以JSON格式发送post请求出现异常,请检查!", e);
throw new RuntimeException(e);
} finally {
if (br != null) {
@@ -182,16 +182,12 @@ public class HttpRequest {
br.close();
} catch (IOException e) {
br = null;
+ LogUtil.APP.error("使用HttpClient以JSON格式发送post请求后关闭br流出现异常,请检查!", e);
throw new RuntimeException(e);
}
}
}
return resultBuffer.toString();
}
-
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
- }
}