com.netflix.feign 响应中出现 NullPointerException class
com.netflix.feign NullPointerException in Response class
我对 Feign Clients 有疑问。我有三个模块,它们使用 feign 相互通信。它看起来像这样:
moduleA <---feign---> moduleB <----feign---->moduleC
我的问题发生在 moduleC 向 moduleB 发送成功响应时。我分析了 feign-core classes 并找到了原因。
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
}
}
在 feign-core class 响应中,当方法 checkNotNull(reason, "reason") 被触发时,即使响应状态为 200,也会出现 NullPointerException。我该如何解决?
编辑:我的 feign 版本是 8.1.1
EDIT2:我的 tomcat 版本是 8.5.20
我找到了答案。问题是由 tomcat 引起的。版本 8.0.* 在响应中禁用了原因短语,因此我不得不启用它(幸运的是它仍然是可能的,因为在 9 以上的版本中它不是)。我必须编辑 server.xml 文件并附加到连接器 sendReasonPhrase 属性。现在看起来像这样:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
sendReasonPhrase="true"
redirectPort="8443" />
我对 Feign Clients 有疑问。我有三个模块,它们使用 feign 相互通信。它看起来像这样:
moduleA <---feign---> moduleB <----feign---->moduleC
我的问题发生在 moduleC 向 moduleB 发送成功响应时。我分析了 feign-core classes 并找到了原因。
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
}
}
在 feign-core class 响应中,当方法 checkNotNull(reason, "reason") 被触发时,即使响应状态为 200,也会出现 NullPointerException。我该如何解决?
编辑:我的 feign 版本是 8.1.1
EDIT2:我的 tomcat 版本是 8.5.20
我找到了答案。问题是由 tomcat 引起的。版本 8.0.* 在响应中禁用了原因短语,因此我不得不启用它(幸运的是它仍然是可能的,因为在 9 以上的版本中它不是)。我必须编辑 server.xml 文件并附加到连接器 sendReasonPhrase 属性。现在看起来像这样:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
sendReasonPhrase="true"
redirectPort="8443" />