Version change for security fix
[dcaegen2/services/son-handler.git] / src / main / java / com / wipro / www / sonhms / restclient / PolicyRestClient.java
1 /*******************************************************************************
2  * ============LICENSE_START=======================================================
3  * pcims
4  *  ================================================================================
5  *  Copyright (C) 2018 Wipro Limited.
6  *  ==============================================================================
7  *   Licensed under the Apache License, Version 2.0 (the "License");
8  *   you may not use this file except in compliance with the License.
9  *   You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *   Unless required by applicable law or agreed to in writing, software
14  *   distributed under the License is distributed on an "AS IS" BASIS,
15  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *   See the License for the specific language governing permissions and
17  *   limitations under the License.
18  *   ============LICENSE_END=========================================================
19  ******************************************************************************/
20
21 package com.wipro.www.sonhms.restclient;
22
23 import com.fasterxml.jackson.core.JsonProcessingException;
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import com.wipro.www.sonhms.Configuration;
26 import com.wipro.www.sonhms.utils.HttpRequester;
27
28 import java.util.UUID;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class PolicyRestClient {
33     private static Logger log = LoggerFactory.getLogger(PolicyRestClient.class);
34
35     private PolicyRestClient() {
36
37     }
38
39     /**
40      * Fetches configuration from policy.
41      */
42     public static String fetchConfigFromPolicy() {
43         log.debug("inside fetconfig from policy");
44
45         Configuration configuration = Configuration.getInstance();
46         String response = "";
47         String configName = configuration.getConfigName();
48         String policyName = configuration.getPolicyName();
49
50         try {
51             PolicyRequestBody policyRequestBody = new PolicyRequestBody();
52             policyRequestBody.setConfigName(configName);
53             policyRequestBody.setPolicyName(policyName);
54             UUID requestUuid = UUID.randomUUID();
55             String requestId = requestUuid.toString();
56             policyRequestBody.setRequestId(requestId);
57             ObjectMapper mapper = new ObjectMapper();
58             String requestBody;
59             requestBody = mapper.writeValueAsString(policyRequestBody);
60
61             log.debug("policyRequestBody{}", requestBody);
62             String requestUrl = configuration.getPolicyService() + "/pdp/api/getConfig";
63             response = HttpRequester.sendPostToPolicy(requestUrl, requestBody);
64             log.debug("policy response{}", response);
65
66             return response;
67         } catch (JsonProcessingException e) {
68             log.debug("exception", e);
69         }
70         return response;
71
72     }
73
74 }