diff options
author | tkogut <tomasz.kogut@nokia.com> | 2021-01-25 17:56:56 +0100 |
---|---|---|
committer | tkogut <tomasz.kogut@nokia.com> | 2021-01-25 17:56:56 +0100 |
commit | 214d24db845fe1485f91b03971c40640601881ca (patch) | |
tree | d96311161b6c8c41ea1f08a472124e85713b3e53 /rest-services/http-client | |
parent | 9b309b5e3905cb25d5d661c4428cc9d4ad0402a6 (diff) |
Fix problem with resource releases when retry more than twice
Issue-ID: DCAEGEN2-1483
Signed-off-by: tkogut <tomasz.kogut@nokia.com>
Change-Id: I8fc58e035226c7c2d499b23f0f31df7bbdb147d4
Diffstat (limited to 'rest-services/http-client')
2 files changed, 6 insertions, 9 deletions
diff --git a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RequestBody.java b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RequestBody.java index d427ee5e..46f9431b 100644 --- a/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RequestBody.java +++ b/rest-services/http-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/adapters/http/RequestBody.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================== * DCAEGEN2-SERVICES-SDK * ========================================================= - * Copyright (C) 2019 Nokia. All rights reserved. + * Copyright (C) 2019-2021 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. @@ -30,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import reactor.netty.ByteBufFlux; +import reactor.netty.ByteBufMono; /** * @author <a href="mailto:piotr.jaszczyk@nokia.com">Piotr Jaszczyk</a> @@ -58,12 +59,9 @@ public interface RequestBody { } static RequestBody fromString(String contents, Charset charset) { - ByteBuf encodedContents = ByteBufAllocator.DEFAULT.buffer(); - encodedContents.writeCharSequence(contents, charset); - return ImmutableRequestBody.builder() - .length(encodedContents.readableBytes()) - .contents(Mono.just(encodedContents.retain())) + .length(contents.length()) + .contents(ByteBufMono.fromString(Mono.just(contents), charset, ByteBufAllocator.DEFAULT)) .build(); } 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 d0bdf414..76bde27e 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 @@ -28,7 +28,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.config.RetryCo import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.HttpClient.ResponseReceiver; @@ -113,7 +112,7 @@ public class RxHttpClient { return theClient .headers(hdrs -> hdrs.set(HttpHeaders.TRANSFER_ENCODING_TYPE, HttpHeaders.CHUNKED)) .request(request.method().asNetty()) - .send(Flux.from(request.body().contents())) + .send(request.body().contents()) .uri(request.url()); } @@ -121,7 +120,7 @@ public class RxHttpClient { return theClient .headers(hdrs -> hdrs.set(HttpHeaders.CONTENT_LENGTH, request.body().length().toString())) .request(request.method().asNetty()) - .send(Flux.from(request.body().contents())) + .send(request.body().contents()) .uri(request.url()); } |