X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sdnc-a1-controller%2Foam%2Fconfigbackuprestore%2Fvnfconfigbackupservice%2Fsrc%2Fmain%2Fjava%2Fcom%2Fonap%2Fsdnc%2Fvnfbackupservice%2Fscheduler%2FVnfRestClient.java;fp=sdnc-a1-controller%2Foam%2Fconfigbackuprestore%2Fvnfconfigbackupservice%2Fsrc%2Fmain%2Fjava%2Fcom%2Fonap%2Fsdnc%2Fvnfbackupservice%2Fscheduler%2FVnfRestClient.java;h=2af4e0842401433908c04c719ec006754a31d126;hb=b6fe5a1bbad372357f6b441e1657dd8bbe48dc1a;hp=0000000000000000000000000000000000000000;hpb=4e0c72d8a2570e256911eab7cc34f770a1aa327a;p=nonrtric.git diff --git a/sdnc-a1-controller/oam/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java b/sdnc-a1-controller/oam/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java new file mode 100644 index 00000000..2af4e084 --- /dev/null +++ b/sdnc-a1-controller/oam/configbackuprestore/vnfconfigbackupservice/src/main/java/com/onap/sdnc/vnfbackupservice/scheduler/VnfRestClient.java @@ -0,0 +1,58 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ +package com.onap.sdnc.vnfbackupservice.scheduler; + + +import java.util.Arrays; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + + +@Service +public class VnfRestClient { + + @Autowired + private RestTemplate restTemplate; + + public String vnfRestClient(String url, String userName, String password) { + restTemplate = new RestTemplate(); + HttpHeaders headers = new HttpHeaders(); + HttpEntity entity = new HttpEntity(generateHeaders(headers, userName, password)); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class); + String result = response.getBody(); + return result; + } + + public HttpHeaders generateHeaders(HttpHeaders headers, String userName, String password) { + headers.setAccept(Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON })); + headers.setContentType(MediaType.APPLICATION_JSON); + String base64Username = userName + ":" + password; + byte[] message = base64Username.getBytes(); + headers.set("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString(message)); + return headers; + } +}