0

When implementing following

ResponseEntity<InputStreamResource> resp = webClient.get()
                    .uri(UriComponentsBuilder.fromHttpUrl(x.getUrl() + x.getPath()).queryParam("key", keysList)
                    .build().toUriString())
                    .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM_VALUE)
                    .retrieve()
                    .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new ServiceException("Server error", clientResponse.rawStatusCode())))
                    .bodyToMono(new ParameterizedTypeReference<ResponseEntity<InputStreamResource>>() {});

an exception is thrown with


nested exception is org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/octet-stream' not supported for bodyType=org.springframework.http.ResponseEntity<org.springframework.core.io.InputStreamResource>

though the server send correctly the stream to the client with a content-dispostion (inline with filename) and content-size.

How to tackle this problem with webclient or register an appropiate HttpMessageHandler to webclients?

Otherwise if the ResponseEntity is taken out and only the data is downloaded , the filename is not apparently available, which is needed.

( works with eg.

byte [] byteStr = webClient.get()
                    .uri(UriComponentsBuilder.fromHttpUrl(x.getUrl() + x.getPath()).queryParam("key", keysList)
                    .build().toUriString())
                    .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_OCTET_STREAM_VALUE)
                    .retrieve()
                    .onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new ServiceException("Server error", clientResponse.rawStatusCode())))
                    .bodyToMono(byte[].class);

0 Answers0