Serg3nt3
Serg3nt3

Reputation: 1

Spring boot/Spring WebClient - The underlying HTTP client completed without emitting a response

from a Spring Boot 3.3.3 microservice - JDK 22, I am trying to contact a Spring Boot 3.1.6 microservice - JDK 18, which in turn makes asynchronous calls to a third microservice. The connection between the first microservice and the second one works correctly, but when the second microservice tries to asynchronously contact the third, I receive the error: "The underlying HTTP client completed without emitting a response."

Below is the first call (non-asynchronous) to the second microservice:

       return mercurioDocumentApiClient.getWebClient().post()
                .uri(UriComponentsBuilder.fromUriString(mercurioDocumentApiClient.getBasePath())
                        .path("/documents/upload")
                        .build()
                        .toUri()
                )
                .header("idSession", idSession)
                .contentType(MediaType.MULTIPART_FORM_DATA)
                .body(BodyInserters.fromMultipartData(multipartBodyBuilder.build()))
                .retrieve()
                .bodyToMono(Document.class)
                .flatMap(document -> {
                    AllegaDocumentoDocumentaleOutputData allegaDocumentoDocumentaleOutputData = new AllegaDocumentoDocumentaleOutputData();
                    allegaDocumentoDocumentaleOutputData.setIdDocumento(BigDecimal.valueOf(Objects.requireNonNull(document.getId())));
                    allegaDocumentoDocumentaleOutputData.setRiferimentoDoc(null);
                    allegaDocumentoDocumentaleOutputData.setDocumentIdClient(document.getDocumentCode());
                    allegaDocumentoDocumentaleOutputData.setContentId(Long.valueOf(Objects.requireNonNull(document.getContentCode())));
                    return Mono.just(allegaDocumentoDocumentaleOutputData);
                })
                .block();

The other calls originating from the second microservice:

        return filePartMono.flatMap(filePart -> {
            // Check document id client
            if (Objects.isNull(documentIdClientFormFieldPart) || StringUtils.isEmpty(documentIdClientFormFieldPart.value())) {
                return webClient.flatMap(client -> {
                    DocumentCreateForm documentCreateForm = new DocumentCreateForm();
                    documentCreateForm.setTitle(filePart.filename());
                    documentCreateForm.path(String.valueOf(LocalDate.now().getYear()));

                    // Create new document
                    return client
                            .post()
                            .uri(uriBuilder -> uriBuilder.pathSegment("mercurio-contents", "api", "v1", "documents", mercurioProperties.getDomainCode(), mercurioProperties.getApplicationCode(), mercurioProperties.getContextCode(), "create").build())
                            .contentType(MediaType.APPLICATION_JSON)
                            .body(BodyInserters.fromValue(documentCreateForm))
                            .retrieve()
                            .bodyToMono(DocumentResponse.class)
                            .flatMap(documentResponse -> {
                                if (Boolean.TRUE.equals(documentResponse.getSummary().getError())) {
                                    return Mono.error(() -> new IllegalStateException(Arrays.toString(ListUtils.emptyIfNull(documentResponse.getSummary().getMessages()).toArray())));
                                }

                                log.info("Document created {}", Objects.requireNonNull(documentResponse.getPayload()).getDocumentIdClient());

                                return uploadFile(filePart.content(), filePart.filename(), pages, documentResponse.getPayload().getDocumentIdClient(), Optional.ofNullable(acquisitionStatusFormFieldPart).map(FormFieldPart::value).orElse(StringUtils.EMPTY), principal.getName());
                            });
                });


This call triggers the error

return client
                            .post()
                            .uri(uriBuilder -> uriBuilder.pathSegment("mercurio-contents", "api", "v1", "documents", mercurioProperties.getDomainCode(), mercurioProperties.getApplicationCode(), mercurioProperties.getContextCode(), "create").build())
                            .contentType(MediaType.APPLICATION_JSON)
                            .body(BodyInserters.fromValue(documentCreateForm))
                            .retrieve()
                            .bodyToMono(DocumentResponse.class)
                            .flatMap(documentResponse -> {
                                if (Boolean.TRUE.equals(documentResponse.getSummary().getError())) {
                                    return Mono.error(() -> new IllegalStateException(Arrays.toString(ListUtils.emptyIfNull(documentResponse.getSummary().getMessages()).toArray())));
                                }

                                log.info("Document created {}", Objects.requireNonNull(documentResponse.getPayload()).getDocumentIdClient());

                                return uploadFile(filePart.content(), filePart.filename(), pages, documentResponse.getPayload().getDocumentIdClient(), Optional.ofNullable(acquisitionStatusFormFieldPart).map(FormFieldPart::value).orElse(StringUtils.EMPTY), principal.getName());
                            });


Upvotes: 0

Views: 150

Answers (0)

Related Questions