ResponseEntity正在两个Web服务调用之间丢失

问题描述 投票:1回答:1

我有一个webservice调用另一个WS并返回第二个WS的响应。它看起来像这样:

// MyController
public ResponseEntity<Foo> requestFooController(@RequestBody @Valid Bar request) {
     return this.myService.requestFooService(request);
}

//MyService
ResponseEntity<Foo> requestFooService(Bar request) {
  Buzz improvedRequest = ...
  return this.secondWS.secondRequestFoo(improvedRequest);
}

当我通过邮递员调用API时,我收到一个空状态的HTTP OK响应。然而,当我处于调试模式时,我可以看到该服务正在返回带有正文的ResponseEntity。但是标题不会丢失。

我改变了我的代码,它工作正常:

// MyController
public ResponseEntity<Foo> requestFooController(@RequestBody @Valid Bar request) {
     ResponseEntity<Foo> tmp = this.myService.requestFooService(request);
     return ResponseEntity.status(tmp.getStatusCode()).body(tmp.getBody());
}

现在通过Postman我确实有预期的身体。但是,我不明白这种行为。我想也许这可能是因为身体是某种流,可以读取一次或类似的东西。但是从阅读源代码我没有看到任何可以解释这种行为的东西。

我正在使用Netflix-stack(因此两个WS之间的HTTP调用是通过Feign客户端完成的)。

知道为什么我得到这个结果吗?

编辑:关于我的任务的更多细节:Spring Boot 1.5.3.RELEASE Feign 2.0.5

java spring spring-boot spring-cloud-feign
1个回答
0
投票

有一个错误会导致HTTP MultiPart POST的命名主体失败。这种情况的症状是您使用正文发出POST请求,并且Spring-Boot无法将其与端点匹配。我看到的例外是:

2019-01-23 15:22:45.046 DEBUG 1639 --- [io-8080-exec-10] .w.s.m.m.a.ServletInvocableHandlerMethod : Failed to resolve argument 3 of type 'org.springframework.web.multipart.MultipartFile'
    org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present

Zuul正在对请求进行缓存,以便多次重试。在此过程中,它无法保留二进制体的命名字段。如果您使用zuul作为请求前言,您可能会发现它有效。因此,而不是http://myserver.com/myservice/endpoint在路径中使用zuul:http://myserver.com/zuul/myservice/endpoint

这将有效地避免保存请求和重试机制。

More details are available on this issue in Zuul's GitHub Bug List

© www.soinside.com 2019 - 2024. All rights reserved.