Critical Bug fixes wfenginemgrservice
[vfc/nfvo/wfengine.git] / wfenginemgrservice / src / main / java / org / onap / workflow / common / RestClient.java
index 5dcef70..f38fe11 100644 (file)
@@ -21,7 +21,6 @@ import org.apache.http.HttpEntity;
 import org.apache.http.HttpHost;\r
 import org.apache.http.HttpRequest;\r
 import org.apache.http.HttpResponse;\r
-import org.apache.http.client.ClientProtocolException;\r
 import org.apache.http.client.ResponseHandler;\r
 import org.apache.http.client.methods.CloseableHttpResponse;\r
 import org.apache.http.client.methods.HttpDelete;\r
@@ -45,6 +44,8 @@ import com.google.gson.Gson;
 public class RestClient {\r
   private static final String HTTP = "http";\r
   private static final Logger logger = LoggerFactory.getLogger(RestClient.class);\r
+\r
+  //PublicExposureUsedInTest\r
   public static boolean isTest = false;\r
 \r
   public enum HttpMethod {\r
@@ -63,7 +64,7 @@ public class RestClient {
    * @throws IOException\r
    */\r
   public static RestResponse executeHttp(HttpMethod method, String ip, Integer port, String url,\r
-      HttpEntity body) throws ClientProtocolException, IOException {\r
+      HttpEntity body) throws IOException {\r
     if (isTest) {\r
       return new RestResponse();\r
     }\r
@@ -82,7 +83,8 @@ public class RestClient {
       HttpHost target = new HttpHost(ip, port, HTTP);\r
       HttpRequest request = getRequest(method, url, body);\r
       logger.info("deployfile method send ip" + ip);\r
-      request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());\r
+      if(null != request)\r
+       request.addHeader(Constants.AUTHORIZATION, ToolUtil.getHeader());\r
 \r
       httpResponse = httpclient.execute(target, request);\r
       HttpEntity entity = httpResponse.getEntity();\r
@@ -147,7 +149,7 @@ public class RestClient {
    * @throws IOException\r
    */\r
   public static RestResponse post(String ip, int port, String url, HttpEntity requestBody)\r
-      throws ClientProtocolException, IOException {\r
+      throws IOException {\r
     return executeHttp(HttpMethod.POST, ip, port, url, requestBody);\r
   }\r
 \r
@@ -165,7 +167,7 @@ public class RestClient {
    * @throws IOException\r
    */\r
   public static RestResponse executeHttpDeleteDeploy(HttpMethod method, String ip, Integer port,\r
-      String url) throws ClientProtocolException, IOException {\r
+      String url) throws IOException {\r
     if (isTest) {\r
       return new RestResponse();\r
     }\r
@@ -176,9 +178,7 @@ public class RestClient {
       port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();\r
     }\r
     RestResponse result = new RestResponse();\r
-    CloseableHttpClient httpClient = HttpClients.createDefault();\r
-    try {\r
-      httpClient = HttpClients.createDefault();\r
+    try(CloseableHttpClient httpClient = HttpClients.createDefault()){\r
       // "http://localhost:8080/activiti-rest/service/repository/deployments/167501"\r
     /*  String deleteUrl =\r
           Constants.HTTP_HEADER + ip + Constants.COLON + port + url + "?cascade=true";*/\r
@@ -201,11 +201,8 @@ public class RestClient {
       }\r
       // result.setResult(EntityUtils.toString(httpResonse.getEntity()));\r
     } catch (Exception e) {\r
-      e.printStackTrace();\r
-    } finally {\r
-      closeHttpClient(httpClient);\r
-    }\r
-\r
+       logger.error("executeHttpDeleteDeploy ",e);\r
+    } \r
     return result;\r
   }\r
 \r
@@ -221,16 +218,15 @@ public class RestClient {
    * @throws IOException\r
    */\r
   public static RestResponse executeHttpStartIntance(HttpMethod method, String ip, Integer port,\r
-      String url, ActivitiStartProcessRequest object) throws ClientProtocolException, IOException {\r
+      String url, ActivitiStartProcessRequest object) throws IOException {\r
     if (isTest) {\r
       return new RestResponse();\r
     }\r
     String returnValue = "";\r
     RestResponse result = new RestResponse();\r
-    CloseableHttpClient httpClient = HttpClients.createDefault();\r
     ResponseHandler<String> responseHandler = new BasicResponseHandler();\r
-    try {\r
-      httpClient = HttpClients.createDefault();\r
+    try (\r
+      CloseableHttpClient httpClient = HttpClients.createDefault()){\r
       if (ip == null) {\r
         ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();\r
       }\r
@@ -254,12 +250,9 @@ public class RestClient {
         result.setResult(returnValue);\r
       }\r
     } catch (Exception e) {\r
-      e.printStackTrace();\r
-    }\r
-\r
-    finally {\r
-      closeHttpClient(httpClient);\r
+       logger.error("executeHttpStartIntance :",e);\r
     }\r
+    \r
 \r
     return result;\r
   }\r
@@ -275,7 +268,7 @@ public class RestClient {
    * @throws IOException\r
    */\r
   public static RestResponse post(String ip, Integer port, String url,\r
-      ActivitiStartProcessRequest requestBody) throws ClientProtocolException, IOException {\r
+      ActivitiStartProcessRequest requestBody) throws IOException {\r
     return executeHttpStartIntance(HttpMethod.POST, ip, port, url, requestBody);\r
   }\r
 \r
@@ -290,7 +283,7 @@ public class RestClient {
    * @throws IOException\r
    */\r
   public static RestResponse post(String ip, Integer port, String url)\r
-      throws ClientProtocolException, IOException {\r
+      throws IOException {\r
     return executeHttpDeleteDeploy(HttpMethod.DELETE, ip, port, url);\r
   }\r
 \r