diff options
author | 2019-03-27 11:53:45 +0100 | |
---|---|---|
committer | 2019-03-27 11:53:45 +0100 | |
commit | 4dcef4e7da04caf4b98ce9553c600e3821b91922 (patch) | |
tree | a6176b3d1ad650566d846233aeead36e6da1f808 /rest-services/common-dependency/src/main/java/org/onap | |
parent | 51d3ae2b08dd49029cd9c86bfe8d95d1eef14326 (diff) |
DMaaP consumer more generic
Added logging to Cloud Http Client
Change-Id: I443163b3ec292370c39cd10229c3479e36f6c9c1
Issue-ID: DCAEGEN2-1310
Signed-off-by: mmigdal <marcin.migdal@nokia.com>
Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
Diffstat (limited to 'rest-services/common-dependency/src/main/java/org/onap')
-rw-r--r-- | rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java | 85 |
1 files changed, 47 insertions, 38 deletions
diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java index 8e317f8b..132d3d83 100644 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/CloudHttpClient.java @@ -28,8 +28,9 @@ import java.util.Map; import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel; import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import reactor.core.publisher.Mono; -import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.HttpClientResponse; @@ -40,6 +41,7 @@ import reactor.netty.http.client.HttpClientResponse; @Deprecated public class CloudHttpClient { + private static final Logger LOGGER = LoggerFactory.getLogger(CloudHttpClient.class); private final Gson gson = new Gson(); private final RxHttpClient httpClient; @@ -64,38 +66,38 @@ public class CloudHttpClient { } public <T> Mono<T> get( - String url, - RequestDiagnosticContext context, - Map<String, String> customHeaders, - Class<T> bodyClass) { + String url, + RequestDiagnosticContext context, + Map<String, String> customHeaders, + Class<T> bodyClass) { return httpClient.call( - ImmutableHttpRequest.builder() - .method(HttpMethod.GET) - .url(url) - .customHeaders(HashMap.ofAll(customHeaders)) - .diagnosticContext(context) - .build()) - .doOnNext(HttpResponse::throwIfUnsuccessful) - .map(HttpResponse::bodyAsString) - .map(body -> gson.fromJson(body, bodyClass)); + ImmutableHttpRequest.builder() + .method(HttpMethod.GET) + .url(url) + .customHeaders(HashMap.ofAll(customHeaders)) + .diagnosticContext(context) + .build()) + .doOnNext(HttpResponse::throwIfUnsuccessful) + .map(HttpResponse::bodyAsString) + .map(body -> gson.fromJson(body, bodyClass)); } public Mono<HttpClientResponse> post( - String url, - RequestDiagnosticContext context, - Map<String, String> customHeaders, - JsonBodyBuilder jsonBodyBuilder, - ClientModel clientModel) { + String url, + RequestDiagnosticContext context, + Map<String, String> customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel) { return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.POST); } public Mono<HttpClientResponse> patch( - String url, - RequestDiagnosticContext context, - Map<String, String> customHeaders, - JsonBodyBuilder jsonBodyBuilder, - ClientModel clientModel) { + String url, + RequestDiagnosticContext context, + Map<String, String> customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel) { return callForRawResponse(url, context, customHeaders, jsonBodyBuilder, clientModel, HttpMethod.PATCH); } @@ -109,22 +111,29 @@ public class CloudHttpClient { } private Mono<HttpClientResponse> callForRawResponse( - String url, - RequestDiagnosticContext context, - Map<String, String> customHeaders, - JsonBodyBuilder jsonBodyBuilder, - ClientModel clientModel, - HttpMethod method) { + String url, + RequestDiagnosticContext context, + Map<String, String> customHeaders, + JsonBodyBuilder jsonBodyBuilder, + ClientModel clientModel, + HttpMethod method) { + + String jsonBody = jsonBodyBuilder.createJsonBody(clientModel); + LOGGER.debug("CloudHttpClient JSon body:: {}", jsonBody); + LOGGER.debug("CloudHttpClient url: {}", url); + LOGGER.debug("CloudHttpClient customHeaders: {}", customHeaders); + return httpClient.prepareRequest( - ImmutableHttpRequest.builder() - .url(url) - .customHeaders(HashMap.ofAll(customHeaders)) - .diagnosticContext(context) - .body(RequestBody.fromString(jsonBodyBuilder.createJsonBody(clientModel))) - .method(method) - .build()) - .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse)); + ImmutableHttpRequest.builder() + .url(url) + .customHeaders(HashMap.ofAll(customHeaders)) + .diagnosticContext(context) + .body(RequestBody.fromString(jsonBody)) + .method(method) + .build()) + .responseSingle((httpClientResponse, byteBufMono) -> Mono.just(httpClientResponse)); } + } |