X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fclients%2FAsyncRestClient.java;h=12c07453a0c5db28e4c3e0892af042b8e4b97fa8;hb=1346500fa3aa1fd1ebe77c80f34df8d09324d5d2;hp=b10cf2791d3d9a3ca378a3db6e8760c732865bd0;hpb=b7f8d2ce1b48969eb0ad1048d83a9105f90d0c17;p=nonrtric.git diff --git a/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java b/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java index b10cf279..12c07453 100644 --- a/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java +++ b/policy-agent/src/main/java/org/oransc/policyagent/clients/AsyncRestClient.java @@ -17,6 +17,7 @@ * limitations under the License. * ========================LICENSE_END=================================== */ + package org.oransc.policyagent.clients; import java.lang.invoke.MethodHandles; @@ -31,8 +32,9 @@ import reactor.core.publisher.Mono; public class AsyncRestClient { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final WebClient client; + private final String baseUrl; - private static class AsyncRestClientException extends Exception { + public class AsyncRestClientException extends Exception { private static final long serialVersionUID = 1L; @@ -43,9 +45,11 @@ public class AsyncRestClient { public AsyncRestClient(String baseUrl) { this.client = WebClient.create(baseUrl); + this.baseUrl = baseUrl; } public Mono post(String uri, String body) { + logger.debug("POST uri = '{}{}''", baseUrl, uri); return client.post() // .uri(uri) // .contentType(MediaType.APPLICATION_JSON) // @@ -53,10 +57,12 @@ public class AsyncRestClient { .retrieve() // .onStatus(HttpStatus::isError, response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // - .bodyToMono(String.class); + .bodyToMono(String.class) // + .defaultIfEmpty(""); } public Mono postWithAuthHeader(String uri, String body, String username, String password) { + logger.debug("POST (auth) uri = '{}{}''", baseUrl, uri); return client.post() // .uri(uri) // .headers(headers -> headers.setBasicAuth(username, password)) // @@ -65,11 +71,12 @@ public class AsyncRestClient { .retrieve() // .onStatus(HttpStatus::isError, response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // - .bodyToMono(String.class); + .bodyToMono(String.class) // + .defaultIfEmpty(""); } public Mono put(String uri, String body) { - logger.debug("PUT uri = '{}''", uri); + logger.debug("PUT uri = '{}{}''", baseUrl, uri); return client.put() // .uri(uri) // .contentType(MediaType.APPLICATION_JSON) // @@ -77,26 +84,29 @@ public class AsyncRestClient { .retrieve() // .onStatus(HttpStatus::isError, response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // - .bodyToMono(String.class); + .bodyToMono(String.class) // + .defaultIfEmpty(""); } public Mono get(String uri) { - logger.debug("GET uri = '{}''", uri); + logger.debug("GET uri = '{}{}''", baseUrl, uri); return client.get() // .uri(uri) // .retrieve() // .onStatus(HttpStatus::isError, response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // - .bodyToMono(String.class); + .bodyToMono(String.class) // + .defaultIfEmpty(""); } public Mono delete(String uri) { - logger.debug("DELETE uri = '{}''", uri); + logger.debug("DELETE uri = '{}{}''", baseUrl, uri); return client.delete() // .uri(uri) // .retrieve() // .onStatus(HttpStatus::isError, response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // - .bodyToMono(String.class); + .bodyToMono(String.class) // + .defaultIfEmpty(""); } }