From 390e82aa57f6a563d274fd0e3c26ca858c5abebc Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Thu, 29 Sep 2022 11:27:25 +0200 Subject: Minor logging improvement Debug logging of REST response body in case of error. Removed some irrelevant logs. Issue-ID: CCSDK-3766 Signed-off-by: PatrikBuhr Change-Id: I3c7b62acd1736f9447e3494c655d85372a4c521f --- .../a1policymanagementservice/clients/AsyncRestClient.java | 12 +++++++++++- .../controllers/v2/ErrorResponse.java | 6 ++++++ .../dmaap/DmaapMessageConsumer.java | 3 --- 3 files changed, 17 insertions(+), 4 deletions(-) (limited to 'a1-policy-management/src/main/java') diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java index c4afdb2f..e3d99426 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClient.java @@ -39,6 +39,7 @@ import org.springframework.web.reactive.function.client.ExchangeFilterFunction; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec; +import org.springframework.web.reactive.function.client.WebClientResponseException; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; @@ -138,7 +139,16 @@ public class AsyncRestClient { request.headers(h -> h.setBearerAuth(securityContext.getBearerAuthToken())); } return request.retrieve() // - .toEntity(String.class); + .toEntity(String.class) // + .doOnError(this::onError); + + } + + private void onError(Throwable t) { + if (t instanceof WebClientResponseException) { + WebClientResponseException e = (WebClientResponseException) t; + logger.debug("Response error: {}", e.getResponseBodyAsString()); + } } private static Object createTraceTag() { diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java index a6679e05..82a21ae2 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ErrorResponse.java @@ -26,7 +26,11 @@ import com.google.gson.annotations.SerializedName; import io.swagger.v3.oas.annotations.media.Schema; +import java.lang.invoke.MethodHandles; + import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -36,6 +40,7 @@ import reactor.core.publisher.Mono; public class ErrorResponse { private static Gson gson = new GsonBuilder() // .create(); // + private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); // Returned as body for all failed REST calls @Schema(name = "error_information", description = "Problem as defined in https://tools.ietf.org/html/rfc7807") @@ -90,6 +95,7 @@ public class ErrorResponse { } static ResponseEntity create(String text, HttpStatus code) { + logger.debug("Error response: {}, {}", code, text); ErrorInfo p = new ErrorInfo(text, code.value()); String json = gson.toJson(p); HttpHeaders headers = new HttpHeaders(); diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java index 1224d00b..47c73506 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumer.java @@ -95,14 +95,12 @@ public class DmaapMessageConsumer { } void onRequest(long no) { - logger.debug("InfiniteFlux.onRequest {}", no); for (long i = 0; i < no; ++i) { sink.next(counter++); } } void next(FluxSink sink) { - logger.debug("InfiniteFlux.next"); this.sink = sink; sink.next(counter++); } @@ -213,7 +211,6 @@ public class DmaapMessageConsumer { private Mono fetchFromDmaap() { if (!this.isDmaapConfigured()) { - logger.debug("fetchFromDmaap, no action DMAAP not configured"); return delay().flatMap(o -> Mono.empty()); } logger.debug("fetchFromDmaap"); -- cgit 1.2.3-korg