From 91d17acfab525c96aee50ad14191c78f7e833376 Mon Sep 17 00:00:00 2001 From: tkogut Date: Tue, 29 Dec 2020 15:13:22 +0100 Subject: Add timeout for Publisher(dmaap-client) Issue-ID: DCAEGEN2-1483 Signed-off-by: tkogut Change-Id: Ia5b7320bc3e491548a1fa1dba2d95843a98f01ae --- .../services/sdk/rest/services/adapters/http/HttpRequest.java | 6 +++++- .../services/sdk/rest/services/adapters/http/RxHttpClient.java | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'rest-services/http-client/src/main/java') diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/HttpRequest.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/HttpRequest.java index 33060c9f..9d2d1ee5 100644 --- a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/HttpRequest.java +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/HttpRequest.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================== * DCAEGEN2-SERVICES-SDK * ========================================================= - * Copyright (C) 2019 Nokia. All rights reserved. + * Copyright (C) 2019-2020 Nokia. All rights reserved. * ========================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ import org.immutables.value.Value; import org.jetbrains.annotations.Nullable; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; +import java.time.Duration; + /** * @author Piotr Jaszczyk * @since March 2019 @@ -37,6 +39,8 @@ public interface HttpRequest { HttpMethod method(); + @Nullable Duration timeout(); + @Nullable RequestBody body(); @Value.Default diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RxHttpClient.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RxHttpClient.java index 7ac02bf6..77b842d7 100644 --- a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RxHttpClient.java +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RxHttpClient.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================== * DCAEGEN2-SERVICES-SDK * ========================================================= - * Copyright (C) 2019 Nokia. All rights reserved. + * Copyright (C) 2019-2020 Nokia. All rights reserved. * ========================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.adapters.http; import io.vavr.collection.Stream; +import io.vavr.control.Option; import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,11 +53,15 @@ public class RxHttpClient { } ResponseReceiver prepareRequest(HttpRequest request) { - final HttpClient theClient = httpClient + final HttpClient simpleClient = httpClient .doOnRequest((req, conn) -> logRequest(request.diagnosticContext(), req)) .doOnResponse((rsp, conn) -> logResponse(request.diagnosticContext(), rsp)) .headers(hdrs -> request.headers().forEach(hdr -> hdrs.set(hdr._1, hdr._2))); + final HttpClient theClient = Option.of(request.timeout()) + .map(simpleClient::responseTimeout) + .getOrElse(simpleClient); + return prepareBody(request, theClient); } -- cgit 1.2.3-korg