1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 ******************************************************************************/
21 package com.wipro.www.sonhms.restclient;
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;
28 import java.util.UUID;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class PolicyRestClient {
33 private static Logger log = LoggerFactory.getLogger(PolicyRestClient.class);
35 private PolicyRestClient() {
40 * Fetches configuration from policy.
42 public static String fetchConfigFromPolicy() {
43 log.debug("inside fetconfig from policy");
45 Configuration configuration = Configuration.getInstance();
47 String configName = configuration.getConfigName();
48 String policyName = configuration.getPolicyName();
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();
59 requestBody = mapper.writeValueAsString(policyRequestBody);
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);
67 } catch (JsonProcessingException e) {
68 log.debug("exception", e);