diff --git a/src/main/java/luckyclient/planapi/api/GetServerAPI.java b/src/main/java/luckyclient/planapi/api/GetServerAPI.java index 3e5ad11..0d33084 100644 --- a/src/main/java/luckyclient/planapi/api/GetServerAPI.java +++ b/src/main/java/luckyclient/planapi/api/GetServerAPI.java @@ -25,6 +25,11 @@ import net.sf.json.JsonConfig; */ public class GetServerAPI { + /** + * 通过计划ID获取测试用例对象集 + * @param planid + * @return + */ @SuppressWarnings("unchecked") public static List getCasesbyplanid(int planid) { String result = HttpRequest.loadJSON("/projectPlanCase/cgetcasebyplanid.do?planid=" + planid); @@ -34,6 +39,11 @@ public class GetServerAPI { return list; } + /** + * 通过计划名称获取测试用例对象集 + * @param name + * @return + */ @SuppressWarnings("unchecked") public static List getCasesbyplanname(String name) { String result = HttpRequest.loadJSON("/projectPlanCase/cgetcasebyplanname.do?name=" + name); @@ -43,6 +53,11 @@ public class GetServerAPI { return list; } + /** + * 通过用例ID获取下面的步骤对象 + * @param caseid + * @return + */ @SuppressWarnings("unchecked") public static List getStepsbycaseid(int caseid) { String result = HttpRequest.loadJSON("/projectCasesteps/cgetStepsByCase.do?caseid=" + caseid); @@ -52,6 +67,11 @@ public class GetServerAPI { return list; } + /** + * 通过taskid获取对象 + * @param taskid + * @return + */ public static TestTaskexcute cgetTaskbyid(int taskid) { String result = HttpRequest.loadJSON("/tastExecute/cgettaskbyid.do?taskid=" + taskid); JSONObject jsonObject = JSONObject.fromObject(result.toString()); @@ -59,6 +79,11 @@ public class GetServerAPI { return task; } + /** + * 通过用例编号获取对象 + * @param sign + * @return + */ public static ProjectCase cgetCaseBysign(String sign) { String result = HttpRequest.loadJSON("/projectCase/cgetcasebysign.do?sign=" + sign); JSONObject jsonObject = JSONObject.fromObject(result.toString()); @@ -66,6 +91,11 @@ public class GetServerAPI { return pc; } + /** + * 获取项目下的所有公共参数 + * @param projectid + * @return + */ public static List cgetParamsByProjectid(String projectid) { String result = HttpRequest.loadJSON("/publicCaseParams/cgetParamsByProjectid.do?projectid="+projectid); JSONObject jsonObject = JSONObject.fromObject(result.toString()); @@ -75,6 +105,13 @@ public class GetServerAPI { return list; } + /** + * put web界面的数据到服务端 + * @param sign + * @param executor + * @param loglevel + * @param detail + */ public static void cPostDebugLog(String sign, String executor, String loglevel, String detail){ sign = sign.replace("%","BBFFHH"); sign = sign.replace("=","DHDHDH"); @@ -93,8 +130,19 @@ public class GetServerAPI { System.out.println("已经成功写入临时日志库,ID:" + logid); } + /** + * 供其他系统远程调用调度任务,启动执行 + * @param jobid + * @return + * @throws UnsupportedEncodingException + */ + public static String cRunJobForId(String jobid) throws UnsupportedEncodingException { + String result = HttpRequest.loadJSON("/testJobs/runJobForInterface.do?jobid=" + jobid); + return new String(result.getBytes("GBK"), "UTF-8"); + } + public static void main(String[] args) throws UnsupportedEncodingException { - + getCasesbyplanid(79); } } diff --git a/src/main/java/luckyclient/publicclass/InvokeMethod.java b/src/main/java/luckyclient/publicclass/InvokeMethod.java index be95a4b..3f53d65 100644 --- a/src/main/java/luckyclient/publicclass/InvokeMethod.java +++ b/src/main/java/luckyclient/publicclass/InvokeMethod.java @@ -64,7 +64,7 @@ public class InvokeMethod { String templateidstr = action.substring(1, action.indexOf("】")); String templatenamestr = action.substring(action.indexOf("】") + 1); luckyclient.publicclass.LogUtil.APP - .info("即将使用模板" + templatenamestr + " ID:" + templateidstr + " 发送HTTP请求!"); + .info("即将使用模板【" + templatenamestr + "】 ID:【" + templateidstr + "】 发送HTTP请求!"); String httpppt = HttpRequest .loadJSON("/projectprotocolTemplate/cgetPTemplateById.do?templateid=" + templateidstr); @@ -194,7 +194,7 @@ public class InvokeMethod { String templateidstr = action.substring(1, action.indexOf("】")); String templatenamestr = action.substring(action.indexOf("】") + 1); luckyclient.publicclass.LogUtil.APP - .info("即将使用模板" + templatenamestr + " ID:" + templateidstr + " 发送SOCKET请求!"); + .info("即将使用模板【" + templatenamestr + "】 ID:【" + templateidstr + "】 发送SOCKET请求!"); String httpppt = HttpRequest .loadJSON("/projectprotocolTemplate/cgetPTemplateById.do?templateid=" + templateidstr); diff --git a/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java b/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java index 1872c7f..d7b77aa 100644 --- a/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java +++ b/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java @@ -13,6 +13,7 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -1051,11 +1052,13 @@ public class HttpClientHelper { org.apache.http.StatusLine statusLine = response.getStatusLine(); //从状态行中获取状态码 responsecode = String.valueOf(statusLine.getStatusCode()); - br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset)); - String temp; - while ((temp = br.readLine()) != null) { - resultBuffer.append(temp); - } + if(null!=response.getEntity()){ + br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset)); + String temp; + while ((temp = br.readLine()) != null) { + resultBuffer.append(temp); + } + } } catch (Exception e) { luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e); throw new RuntimeException(e); @@ -1116,11 +1119,13 @@ public class HttpClientHelper { org.apache.http.StatusLine statusLine = response.getStatusLine(); //从状态行中获取状态码 responsecode = String.valueOf(statusLine.getStatusCode()); - br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset)); - String temp; - while ((temp = br.readLine()) != null) { - resultBuffer.append(temp); - } + if(null!=response.getEntity()){ + br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset)); + String temp; + while ((temp = br.readLine()) != null) { + resultBuffer.append(temp); + } + } } catch (Exception e) { luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e); throw new RuntimeException(e); @@ -1140,5 +1145,9 @@ public class HttpClientHelper { public static void main(String[] args) { // TODO Auto-generated method stub + Map params = new HashMap(0); + Map headmsg = new HashMap(0); + String a=httpClientPut("http://tmsclub.gugud.com/aggregation/courses/48/start", params, "UTF-8",headmsg); + System.out.println(a); } }