Critical Bug fixes wfenginemgrservice 09/38409/1
authorajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 26 Mar 2018 06:51:43 +0000 (12:21 +0530)
committerajay priyadarshi <ajay.priyadarshi@ril.com>
Mon, 26 Mar 2018 06:51:43 +0000 (12:21 +0530)
common/RestClient.java
file name:RestClient.java

Change-Id: Ia6f990c5ce3fd0b4c49bb09ed4a126d88e9b0dfb
Issue-ID: VFC-845
Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
wfenginemgrservice/src/main/java/org/onap/workflow/common/RestClient.java
wfenginemgrservice/src/main/java/org/onap/workflow/externalservice/service/activitiservice/ActivitiServiceConsumer.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
index 3af7f66..30835b9 100644 (file)
@@ -20,7 +20,6 @@ import java.io.InputStream;
 \r
 import javax.ws.rs.core.Response;\r
 \r
-import org.apache.http.client.ClientProtocolException;\r
 import org.onap.workflow.common.Config;\r
 import org.onap.workflow.common.EnumModuleUrl;\r
 import org.onap.workflow.common.RestClient;\r
@@ -58,6 +57,7 @@ public class ActivitiServiceConsumer {
     try {\r
       res = RestClient.post(null, null, Constants.DEPLOY_BPMNFILE_URL + "/" + deploymentId);\r
     } catch (Exception e) {\r
+       logger.error("Exception: ",e);\r
      return null;\r
     }\r
 \r
@@ -69,13 +69,14 @@ public class ActivitiServiceConsumer {
     try {\r
       res = RestClient.post(null, null, Constants.ACITIVI_START_INSTANCE_URL, request);\r
     } catch (Exception e) {\r
+       logger.error("Exception: ",e);\r
       return null;\r
     } \r
     return res;\r
   }\r
 \r
   public static ActivitiDeployResponse deploybpmnfile(InputStream ins, String filename)\r
-      throws ClientProtocolException, IOException {\r
+      throws IOException {\r
     try {\r
       return deployPackage2Activiti(ins, filename);\r
     } finally {\r
@@ -84,7 +85,7 @@ public class ActivitiServiceConsumer {
   }\r
 \r
   private static ActivitiDeployResponse deployPackage2Activiti(InputStream ins, String filename)\r
-      throws ClientProtocolException, IOException {\r
+      throws IOException {\r
     String ip = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrIp();\r
     int port = Config.getWorkflowAppConfig().getMsbClientConfig().getMsbSvrPort();\r
     RestResponse res = RestClient.post(ip, port, DEPLOY_BPMNFILE_URL,\r