*/
package org.oransc.policyagent.clients;
+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
public class AsyncRestClient {
private final WebClient client;
+ private static class AsyncRestClientException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ public AsyncRestClientException(String message) {
+ super(message);
+ }
+ }
+
public AsyncRestClient(String baseUrl) {
this.client = WebClient.create(baseUrl);
}
.contentType(MediaType.APPLICATION_JSON) //
.syncBody(body) //
.retrieve() //
+ .onStatus(HttpStatus::isError,
+ response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) //
.bodyToMono(String.class);
}
return client.get() //
.uri(uri) //
.retrieve() //
+ .onStatus(HttpStatus::isError,
+ response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) //
.bodyToMono(String.class);
}
return client.delete() //
.uri(uri) //
.retrieve() //
+ .onStatus(HttpStatus::isError,
+ response -> Mono.error(new AsyncRestClientException(response.statusCode().toString()))) //
.bodyToMono(Void.class);
}
}