NONRTRIC - Implement DMaaP mediator producer service in Java
[nonrtric.git] / dmaap-adaptor-java / src / main / java / org / oran / dmaapadapter / clients / AsyncRestClient.java
index 6939026..746fdd7 100644 (file)
@@ -47,6 +47,7 @@ import reactor.netty.transport.ProxyProvider;
 /**
  * Generic reactive REST client.
  */
+@SuppressWarnings("java:S4449") // @Add Nullable to third party api
 public class AsyncRestClient {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -62,7 +63,8 @@ public class AsyncRestClient {
         this.httpProxyConfig = httpProxyConfig;
     }
 
-    public Mono<ResponseEntity<String>> postForEntity(String uri, @Nullable String body) {
+    public Mono<ResponseEntity<String>> postForEntity(String uri, @Nullable String body,
+            @Nullable MediaType contentType) {
         Object traceTag = createTraceTag();
         logger.debug("{} POST uri = '{}{}''", traceTag, baseUrl, uri);
         logger.trace("{} POST body: {}", traceTag, body);
@@ -71,17 +73,18 @@ public class AsyncRestClient {
         RequestHeadersSpec<?> request = getWebClient() //
                 .post() //
                 .uri(uri) //
-                .contentType(MediaType.APPLICATION_JSON) //
+                .contentType(contentType) //
                 .body(bodyProducer, String.class);
         return retrieve(traceTag, request);
     }
 
-    public Mono<String> post(String uri, @Nullable String body) {
-        return postForEntity(uri, body) //
+    public Mono<String> post(String uri, @Nullable String body, @Nullable MediaType contentType) {
+        return postForEntity(uri, body, contentType) //
                 .map(this::toBody);
     }
 
-    public Mono<String> postWithAuthHeader(String uri, String body, String username, String password) {
+    public Mono<String> postWithAuthHeader(String uri, String body, String username, String password,
+            @Nullable MediaType mediaType) {
         Object traceTag = createTraceTag();
         logger.debug("{} POST (auth) uri = '{}{}''", traceTag, baseUrl, uri);
         logger.trace("{} POST body: {}", traceTag, body);
@@ -90,7 +93,7 @@ public class AsyncRestClient {
                 .post() //
                 .uri(uri) //
                 .headers(headers -> headers.setBasicAuth(username, password)) //
-                .contentType(MediaType.APPLICATION_JSON) //
+                .contentType(mediaType) //
                 .bodyValue(body);
         return retrieve(traceTag, request) //
                 .map(this::toBody);
@@ -109,16 +112,6 @@ public class AsyncRestClient {
         return retrieve(traceTag, request);
     }
 
-    public Mono<ResponseEntity<String>> putForEntity(String uri) {
-        Object traceTag = createTraceTag();
-        logger.debug("{} PUT uri = '{}{}''", traceTag, baseUrl, uri);
-        logger.trace("{} PUT body: <empty>", traceTag);
-        RequestHeadersSpec<?> request = getWebClient() //
-                .put() //
-                .uri(uri);
-        return retrieve(traceTag, request);
-    }
-
     public Mono<String> put(String uri, String body) {
         return putForEntity(uri, body) //
                 .map(this::toBody);