summaryrefslogtreecommitdiffstats
path: root/wfenginemgrservice/src/main/java
diff options
context:
space:
mode:
authorZhaoxing <meng.zhaoxing1@zte.com.cn>2017-09-27 09:51:07 +0800
committerZhaoxing <meng.zhaoxing1@zte.com.cn>2017-09-27 09:51:07 +0800
commit26626fc79558f525b8c8f4c7bce808cccd3bb1d4 (patch)
tree6182abcd09ebb85d0cf665dffd7ae660f347806e /wfenginemgrservice/src/main/java
parentac53c536ace063133d91e8f5f6fce2a230aaf17f (diff)
Add unit test for vfc-nfvo-wfengine-mgrservice
Change-Id: I13dd12eabcfeddaf1c214ce11cee26912dc81fc7 Issue-id: VFC-454 Signed-off-by: Zhaoxing <meng.zhaoxing1@zte.com.cn>
Diffstat (limited to 'wfenginemgrservice/src/main/java')
-rw-r--r--wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java33
1 files changed, 20 insertions, 13 deletions
diff --git a/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java b/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
index f037757..f179fe6 100644
--- a/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
+++ b/wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
@@ -46,7 +46,7 @@ public class RestClient {
private static final String HTTP = "http";
private static final Logger logger = LoggerFactory.getLogger(RestClient.class);
- enum HttpMethod {
+ public enum HttpMethod {
GET, POST, PUT, DELETE
}
@@ -76,13 +76,13 @@ public class RestClient {
}
HttpHost target = new HttpHost(ip, port, HTTP);
HttpRequest request = getRequest(method, url, body);
- logger.info("deployfile method send ip"+ip);
+ logger.info("deployfile method send ip" + ip);
request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());
httpResponse = httpclient.execute(target, request);
HttpEntity entity = httpResponse.getEntity();
logger.info("deployfile method send");
- if (entity != null) {
+ if (entity != null && httpResponse.getStatusLine()!=null) {
result.setStatusCode(httpResponse.getStatusLine().getStatusCode());
logger.info("reply status code deploy"+httpResponse.getStatusLine().getStatusCode());
result.setResult(EntityUtils.toString(entity));
@@ -101,7 +101,7 @@ public class RestClient {
return result;
}
- private static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) {
+ public static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) {
HttpRequest request = null;
switch (method) {
case GET:
@@ -185,7 +185,9 @@ public class RestClient {
if (ip == null) {
ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
}
- port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ if(port==null) {
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ }
RestResponse result = new RestResponse();
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
@@ -204,8 +206,10 @@ public class RestClient {
httpDeteTest.setEntity(new StringEntity(jsonStr));
// returnValue = httpClient.execute(httpDeteTest, responseHandler); // 调接口获取返回值时,必须用此方法
CloseableHttpResponse httpResonse = httpClient.execute(httpDeteTest);
- int statusCode = httpResonse.getStatusLine().getStatusCode();
- result.setStatusCode(statusCode);
+ if(httpResonse!=null && httpResonse.getStatusLine()!=null) {
+ int statusCode = httpResonse.getStatusLine().getStatusCode();
+ result.setStatusCode(statusCode);
+ }
// result.setResult(EntityUtils.toString(httpResonse.getEntity()));
} catch (Exception e) {
e.printStackTrace();
@@ -245,8 +249,9 @@ public class RestClient {
if (ip == null) {
ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();
}
- port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
-
+ if(ip==null) {
+ port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();
+ }
HttpPost httpPost = new HttpPost(Constants.HTTP_HEADER + ip + ":" + port + url);
Gson gson = new Gson();
String jsonStr = gson.toJson(object, ActivitiStartProcessRequest.class);
@@ -257,10 +262,12 @@ public class RestClient {
httpPost.setEntity(requestEntity);
returnValue = httpClient.execute(httpPost, responseHandler); // 调接口获取返回值时,必须用此方法
CloseableHttpResponse httpResonse = httpClient.execute(httpPost);
- int statusCode = httpResonse.getStatusLine().getStatusCode();
- returnValue = EntityUtils.toString(httpResonse.getEntity(),"UTF-8");
- result.setStatusCode(statusCode);
- result.setResult(returnValue);
+ if(httpResonse!=null && httpResonse.getStatusLine()!=null) {
+ int statusCode = httpResonse.getStatusLine().getStatusCode();
+ returnValue = EntityUtils.toString(httpResonse.getEntity(), "UTF-8");
+ result.setStatusCode(statusCode);
+ result.setResult(returnValue);
+ }
} catch (Exception e) {
e.printStackTrace();
}