HTTP/S Modifications
[holmes/rule-management.git] / rulemgt / src / main / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineService.java
index 15af38d..cc20cab 100644 (file)
@@ -31,22 +31,22 @@ import org.onap.holmes.common.utils.HttpsUtils;
 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
 import org.onap.holmes.rulemgt.constant.RuleMgtConstant;\r
-import org.onap.holmes.common.config.MicroServiceConfig;\r
 \r
 @Slf4j\r
 @Service\r
 public class EngineService {\r
 \r
-    private static final String PREFIX = "https://";\r
+    private static final String HTTPS = "https://";\r
+    private static final String HTTP = "http://";\r
     private static final String PORT = ":9102";\r
 \r
     protected HttpResponse delete(String packageName, String ip) throws Exception {\r
         HashMap headers = createHeaders();\r
-        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
+        String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH + "/" + packageName;\r
         CloseableHttpClient httpClient = null;\r
         HttpDelete httpDelete = new HttpDelete(url);\r
         try {\r
-            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
             return HttpsUtils.delete(httpDelete, headers, httpClient);\r
         } finally {\r
             httpDelete.releaseConnection();\r
@@ -58,11 +58,11 @@ public class EngineService {
             throws Exception {\r
         String content = GsonUtil.beanToJson(correlationCheckRule4Engine);\r
         HashMap headers = createHeaders();\r
-        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+        String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
         CloseableHttpClient httpClient = null;\r
         HttpPost httpPost = new HttpPost(url);\r
         try {\r
-            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
             return HttpsUtils.post(httpPost, headers, new HashMap<>(), new StringEntity(content), httpClient);\r
         } finally {\r
             httpPost.releaseConnection();\r
@@ -73,11 +73,11 @@ public class EngineService {
     protected HttpResponse deploy(CorrelationDeployRule4Engine correlationDeployRule4Engine, String ip) throws Exception {\r
         String content = GsonUtil.beanToJson(correlationDeployRule4Engine);\r
         HashMap headers = createHeaders();\r
-        String url = PREFIX + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
+        String url = getRequestPref() + ip + PORT + RuleMgtConstant.ENGINE_PATH;\r
         CloseableHttpClient httpClient = null;\r
         HttpPut httpPut = new HttpPut(url);\r
         try {\r
-            httpClient = HttpsUtils.getHttpClient(HttpsUtils.DEFUALT_TIMEOUT);\r
+            httpClient = HttpsUtils.getConditionalHttpsClient(HttpsUtils.DEFUALT_TIMEOUT);\r
             return HttpsUtils.put(httpPut, headers, new HashMap<>(), new StringEntity(content),httpClient);\r
         } finally {\r
             closeHttpClient(httpClient);\r
@@ -100,4 +100,8 @@ public class EngineService {
         headers.put("Accept", MediaType.APPLICATION_JSON);\r
         return headers;\r
     }\r
+\r
+    private String getRequestPref(){\r
+        return HttpsUtils.isHttpsEnabled() ? HTTPS : HTTP;\r
+    }\r
 }\r