修复模板参数带[""]的问题

This commit is contained in:
seagull 2017-12-27 19:23:11 +08:00
parent a8d8f24940
commit 22b0d7be2b
4 changed files with 44 additions and 25 deletions

View File

@ -142,7 +142,7 @@ public class GetServerAPI {
}
public static void main(String[] args) throws UnsupportedEncodingException {
getCasesbyplanid(79);
}
}

View File

@ -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
}
}

View File

@ -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);

View File

@ -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();
}
/**