[英]Feign Client Get Request HttpStatus 200 but body is null when json is very long
I have an issue with my Feign client, I get the response as well when the json not containing lot of data.我的 Feign 客户端有问题,当 json 不包含大量数据时,我也会得到响应。 But when a json is very long I get 200 status inside Response Object but body is null:
但是当 json 很长时,我在响应Object 中获得 200 状态,但正文是 null:
@FeignClient(name = "processSvc", url = "${xxx}")
public interface ProcessClient {
@GetMapping(value = "/v1/process/{uid}", produces = "application/json")
Response readProcess(@PathVariable("uid") String uid);
}
Any proposition for resolve this issue?有解决这个问题的建议吗?
The issue was reading a response that is larger than the entire memory allocated to the current process.问题是读取的响应大于分配给当前进程的整个 memory。 So, streaming the response fixed the issue by getting the body as InputStream, then convert it to String via IOUtils.toString():
因此,流式传输响应通过将正文作为 InputStream 来解决问题,然后通过 IOUtils.toString() 将其转换为字符串:
Response response = null;
String json;
try {
response = processClient.readProcess(uid);
json = IOUtils.toString(response.body().asInputStream(), Charsets.UTF_8.name());
} catch (IOException e) {
throw new RuntimeException(e);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.