diff --git a/src/main/java/luckyclient/planapi/api/GetServerAPI.java b/src/main/java/luckyclient/planapi/api/GetServerAPI.java index 0d33084..98527d5 100644 --- a/src/main/java/luckyclient/planapi/api/GetServerAPI.java +++ b/src/main/java/luckyclient/planapi/api/GetServerAPI.java @@ -142,7 +142,7 @@ public class GetServerAPI { } 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 e02e58a..e2bb80f 100644 --- a/src/main/java/luckyclient/publicclass/InvokeMethod.java +++ b/src/main/java/luckyclient/publicclass/InvokeMethod.java @@ -72,6 +72,10 @@ public class InvokeMethod { JSONObject jsonpptObject = JSONObject.fromObject(httpppt.toString()); ProjectProtocolTemplate ppt = (ProjectProtocolTemplate) JSONObject.toBean(jsonpptObject, ProjectProtocolTemplate.class); + if(null==ppt){ + luckyclient.publicclass.LogUtil.APP.error("协议模板为空,请检查用例使用的协议模板是否已经删除!"); + return "协议模板为空,请确认用例使用的模板是否已经删除!"; + } String httpptp = HttpRequest .loadJSON("/projectTemplateParams/cgetParamsByTemplate.do?templateid=" + templateidstr); @@ -350,6 +354,7 @@ public class InvokeMethod { 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 1d94a44..dcb5592 100644 --- a/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java +++ b/src/main/java/luckyclient/publicclass/remoterinterface/HttpClientHelper.java @@ -512,14 +512,13 @@ public class HttpClientHelper { String responsecode = String.valueOf(statusLine.getStatusCode()); // 读取服务器响应数据 resultBuffer = new StringBuffer(); - - br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset)); - String temp; - while ((temp = br.readLine()) != null) { - resultBuffer.append(temp); - } - if(resultBuffer.length()==0){ - resultBuffer.append("读取服务器响应数据异常,响应码:"+responsecode); + resultBuffer.append("响应码:"+responsecode+" "); + 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); diff --git a/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java b/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java index b8e7194..d97945a 100644 --- a/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java +++ b/src/main/java/luckyclient/publicclass/remoterinterface/HttpRequest.java @@ -4,11 +4,15 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.Properties; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; + /** * ================================================================= * 这是一个受限制的自由软件!您不能在任何未经允许的前提下对程序代码进行修改和用于商业用途;也不允许对程序代码修改后以任何形式任何目的的再发布。 @@ -32,24 +36,35 @@ public class HttpRequest { * @return */ public static String loadJSON(String repath) { - StringBuilder json = new StringBuilder(); - URL url=null; + StringBuffer resultBuffer = null; + CloseableHttpClient httpclient = HttpClients.createDefault(); + BufferedReader br = null; + // 构建请求参数 + HttpGet httpGet = new HttpGet(WEB_URL+repath); try { - url = new URL(WEB_URL+repath); - URLConnection yc = url.openConnection(); - BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); - String inputLine = null; - while ((inputLine = in.readLine()) != null) { - json.append(inputLine); + HttpResponse response = httpclient.execute(httpGet); + // 读取服务器响应数据 + br = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "GBK")); + String temp; + resultBuffer = new StringBuffer(); + while ((temp = br.readLine()) != null) { + resultBuffer.append(temp); + } + } catch (Exception e) { + luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e); + throw new RuntimeException(e); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + luckyclient.publicclass.LogUtil.APP.error(e.getMessage(), e); + br = null; + throw new RuntimeException(e); + } } - in.close(); - } catch (MalformedURLException e) { - e.printStackTrace(); - luckyclient.publicclass.LogUtil.APP.error("链接服务器失败!URL:"+url); - } catch (IOException e) { - e.printStackTrace(); } - return json.toString(); + return resultBuffer.toString(); } /**