【发布时间】:2017-10-02 12:12:12
【问题描述】:
我遇到了 Feign Clients 的问题。我有三个使用 feign 相互通信的模块。它看起来像这样:
moduleA moduleB moduleC
我的问题发生在 moduleC 向 moduleB 发送成功响应时。我分析了 feign-core 类并找到了原因。
package feign;
public final class Response {
private final int status;
private final String reason;
private final Map<String, Collection<String>> headers;
private final Body body;
private Response(int status, String reason, Map<String, Collection<String>> headers, Body body) {
checkState(status >= 200, "Invalid status code: %s", status); //my status is 200
this.status = status;
this.reason = checkNotNull(reason, "reason"); // my reason is unfortunatelly null
LinkedHashMap<String, Collection<String>>
copyOf =
new LinkedHashMap<String, Collection<String>>();
copyOf.putAll(checkNotNull(headers, "headers"));
this.headers = Collections.unmodifiableMap(copyOf);
this.body = body; //nullable
}
}
在触发方法 checkNotNull(reason, "reason") 的 feign-core 类响应中,即使响应状态为 200,也会出现 NullPointerException。我该如何解决?
编辑:我的假装版本是 8.1.1
EDIT2:我的 tomcat 版本是 8.5.20
【问题讨论】:
-
200应该是无效状态对吗? (你比较
status >= 200) -
@bish 这不是我的代码,而是 feign-core api 代码。而 checkState() 方法是一个棘手的问题,因为它在 status >= 200 为 false 时触发异常
标签: java spring netflix-feign