X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=wfenginemgrservice%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fworkflow%2Fcommon%2FRestClient.java;h=f179fe6c781d6433e0cd12a9df2fe28cb7207d85;hb=26626fc79558f525b8c8f4c7bce808cccd3bb1d4;hp=f0377579c94df3c277ebe8721b281a6a86d8ca7d;hpb=ac53c536ace063133d91e8f5f6fce2a230aaf17f;p=vfc%2Fnfvo%2Fwfengine.git 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(); }