diff --git a/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/rest/AsyncRestProxy.java b/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/rest/AsyncRestProxy.java index 4ed01a73c3811..92a1ce1964ede 100644 --- a/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/rest/AsyncRestProxy.java +++ b/sdk/core/azure-core/src/main/java/com/azure/core/implementation/http/rest/AsyncRestProxy.java @@ -22,6 +22,7 @@ import com.azure.json.JsonSerializable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; import java.io.IOException; import java.io.InputStream; @@ -143,19 +144,32 @@ private Mono handleRestResponseReturnType(final HttpResponseDecoder.HttpDecod return response.getSourceResponse().getBody().ignoreElements() .then(Mono.fromCallable(() -> createResponse(response, entityType, null))); } else { - return handleBodyReturnType(response.getSourceResponse(), response::getDecodedBody, methodParser, - bodyType) + return handleBodyReturnType(response.getSourceResponse(), + decodeBytes(response), + methodParser, bodyType) .map(bodyAsObject -> createResponse(response, entityType, bodyAsObject)) .switchIfEmpty(Mono.fromCallable(() -> createResponse(response, entityType, null))); } } else { // For now, we're just throwing if the Maybe didn't emit a value. - return handleBodyReturnType(response.getSourceResponse(), response::getDecodedBody, methodParser, - entityType); + return handleBodyReturnType(response.getSourceResponse(), decodeBytes(response), methodParser, entityType); } } - static Mono handleBodyReturnType(HttpResponse sourceResponse, Function getDecodedBody, + private static Function> decodeBytes(HttpResponseDecoder.HttpDecodedResponse response) { + return bytes -> Mono.fromCallable(() -> response.getDecodedBody(bytes)) + .publishOn(Schedulers.boundedElastic()) + .handle((object, sink) -> { + if (object == null) { + sink.complete(); + } else { + sink.next(object); + sink.complete(); + } + }); + } + + static Mono handleBodyReturnType(HttpResponse sourceResponse, Function> getDecodedBody, SwaggerMethodParser methodParser, Type entityType) { final int responseStatusCode = sourceResponse.getStatusCode(); final HttpMethod httpMethod = methodParser.getHttpMethod(); @@ -197,7 +211,7 @@ static Mono handleBodyReturnType(HttpResponse sourceResponse, Function or Mono> - asyncResult = sourceResponse.getBodyAsByteArray().mapNotNull(getDecodedBody); + asyncResult = sourceResponse.getBodyAsByteArray().flatMap(getDecodedBody); } return asyncResult; } diff --git a/sdk/core/azure-core/src/main/resources/META-INF/native-image/com.azure/azure-core/native-image.properties b/sdk/core/azure-core/src/main/resources/META-INF/native-image/com.azure/azure-core/native-image.properties index a622dffccc7d8..29dfdd52b5f81 100644 --- a/sdk/core/azure-core/src/main/resources/META-INF/native-image/com.azure/azure-core/native-image.properties +++ b/sdk/core/azure-core/src/main/resources/META-INF/native-image/com.azure/azure-core/native-image.properties @@ -7,6 +7,7 @@ Args=\ ch.qos.logback.classic.Logger,\ ch.qos.logback.classic.PatternLayout,\ ch.qos.logback.core.CoreConstants,\ + ch.qos.logback.core.pattern.parser.Parser,\ ch.qos.logback.core.spi.AppenderAttachableImpl,\ ch.qos.logback.core.status.InfoStatus,\ ch.qos.logback.core.status.StatusBase,\