admin管理员组文章数量:1122832
I m building a API with Springboot WebFlux. This method can downlaod file. This is the code:
public Mono<ServerResponse> downloadAttachment(final ServerRequest request) {
final var idPercorso = request.queryParam("idPercorso")
.map(Integer::parseInt).orElse(null);
}
Mono<ServerResponse> additionalCalcualtions(MapFile mapFile, ServerRequest request){
return Mono.zip(parseUserInfo(request), request.bodyToMono(ObjectNode.class))
.flatMap(t -> {
//var dto = t.getT2();
return silverMountainService(t.getT1()).downloadMappaPercorso(StorageType.parse(mapFile.storageType),mapFile.omniaClass, mapFile.getFileName()
)
.flatMap(fileResult -> ServerResponse.ok()
.headers(h -> h.setContentDisposition(
Optional.ofNullable(mapFile.getFileName())
.filter(StringUtils::isNotBlank)
.map(filename -> ContentDisposition.attachment().filename(mapFile.getFileName()).build())
.orElseGet(() -> ContentDisposition.inline().build() )
))
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.body(BodyInserters.fromValue(fileResult.getContent()))
);
})
.onErrorResume(CustomHttpException.class, assEx -> {
log.error("Error({}): {}", assEx.getErrorId(), assEx.getMessage());
return ServerResponse.status(assEx.getHttpStatus()).bodyValue(String.format("ErrorID: %s", assEx.getErrorId()));
})
.onErrorResume(Exception.class, ex -> {
var errId = UUID.randomUUID().toString();
log.error(String.format("Error(%s) %s", errId, ex.getMessage()), ex);
return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR).bodyValue(String.format("ErrorID: %s", errId));
});
}
To call this method, I m using the following link:
myUrl/downloadMappa?idPercorso=2
Now if I try to call my method with json body like this
{}
my method works correctly. If I try to call my method without json body the return me empty response.
How can I make to change my code to accept NULL as body?
本文标签: spring bootjava API GET with WebFluxStack Overflow
版权声明:本文标题:spring boot - java API GET with WebFlux - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736302938a1931711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论