Add SDNR A1 client in policy-agent
[nonrtric.git] / policy-agent / src / main / java / org / oransc / policyagent / clients / AsyncRestClient.java
index 3fd16d0..b10cf27 100644 (file)
@@ -56,6 +56,18 @@ public class AsyncRestClient {
             .bodyToMono(String.class);
     }
 
+    public Mono<String> 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<String> put(String uri, String body) {
         logger.debug("PUT uri = '{}''", uri);
         return client.put() //