X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sdnc-a1-controller%2Fnorthbound%2Fnonrt-ric-api%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fo_ran_sc%2Fnonrtric%2Fsdnc_a1%2Fnorthbound%2Frestadapter%2FRestAdapterImpl.java;fp=sdnc-a1-controller%2Fnorthbound%2Fnonrt-ric-api%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fo_ran_sc%2Fnonrtric%2Fsdnc_a1%2Fnorthbound%2Frestadapter%2FRestAdapterImpl.java;h=65809836ed18a58692262b8140118b42cc7f3adc;hb=348cb8528bdf879354de640b3249bc40db934505;hp=0000000000000000000000000000000000000000;hpb=672fe20c9ed06da97ee530d76f1492ab5aa7bad9;p=nonrtric.git diff --git a/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/o_ran_sc/nonrtric/sdnc_a1/northbound/restadapter/RestAdapterImpl.java b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/o_ran_sc/nonrtric/sdnc_a1/northbound/restadapter/RestAdapterImpl.java new file mode 100644 index 00000000..65809836 --- /dev/null +++ b/sdnc-a1-controller/northbound/nonrt-ric-api/provider/src/main/java/org/o_ran_sc/nonrtric/sdnc_a1/northbound/restadapter/RestAdapterImpl.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.o_ran_sc.nonrtric.sdnc_a1.northbound.restadapter; + +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.web.client.RestTemplate; + +/** + * This class provides the Generic Rest Adapter interface to the RestTemplate + * + * @author lathishbabu.ganesan@est.tech + * + */ + +public class RestAdapterImpl implements RestAdapter { + + private RestTemplate restTemplate; + + public RestAdapterImpl() { + restTemplate = new RestTemplate(); + } + + private HttpEntity getHttpEntity(final Object object) { + return new HttpEntity<>(object); + } + + @Override + public ResponseEntity get(String uri, Class clazz) { + HttpEntity entity = getHttpEntity(null); + return invokeHttpRequest(uri, HttpMethod.GET, clazz, entity); + } + + @Override + public ResponseEntity put(String uri, String body, Class clazz) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity<>(body, headers); + return invokeHttpRequest(uri, HttpMethod.PUT, clazz, entity); + } + + @Override + public ResponseEntity delete(String uri) { + HttpEntity entity = getHttpEntity(null); + return invokeHttpRequest(uri, HttpMethod.DELETE, null, entity); + } + + @SuppressWarnings("unchecked") + private ResponseEntity invokeHttpRequest(String uri, HttpMethod httpMethod, Class clazz, + HttpEntity entity) { + return (ResponseEntity) restTemplate.exchange(uri, httpMethod, entity, clazz); + } +}