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=cea706088ac671afa38acdf32d2ff8f20fd2a604;hb=7d0bb60a0c1ad1f65c0e0a2b057e8663ef759ffd;hp=e2e5d64d1b18ff7ea4ed16346ffc1945d3e82900;hpb=e8c7fa0b02b0918b3b56a1fc162968a3eef282dc;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 e2e5d64d..cea70608 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 @@ -32,7 +32,7 @@ public class AsyncRestClient { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final WebClient client; - private static class AsyncRestClientException extends Exception { + public class AsyncRestClientException extends Exception { private static final long serialVersionUID = 1L; @@ -45,12 +45,35 @@ public class AsyncRestClient { this.client = WebClient.create(baseUrl); } + public Mono post(String uri, String body) { + return client.post() // + .uri(uri) // + .contentType(MediaType.APPLICATION_JSON) // + .bodyValue(body) // + .retrieve() // + .onStatus(HttpStatus::isError, + response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // + .bodyToMono(String.class); + } + + public Mono postWithAuthHeader(String uri, String body, String username, String password) { + return client.post() // + .uri(uri) // + .headers(headers -> headers.setBasicAuth(username, password)) // + .contentType(MediaType.APPLICATION_JSON) // + .bodyValue(body) // + .retrieve() // + .onStatus(HttpStatus::isError, + response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) // + .bodyToMono(String.class); + } + public Mono put(String uri, String body) { logger.debug("PUT uri = '{}''", uri); return client.put() // .uri(uri) // .contentType(MediaType.APPLICATION_JSON) // - .syncBody(body) // + .bodyValue(body) // .retrieve() // .onStatus(HttpStatus::isError, response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) //