【问题标题】:com.netflix.feign NullPointerException in Response class响应类中的 com.netflix.feign NullPointerException
【发布时间】:2017-10-02 12:12:12
【问题描述】:

我遇到了 Feign Clients 的问题。我有三个使用 feign 相互通信的模块。它看起来像这样:
moduleA moduleB moduleC
我的问题发生在 moduleCmoduleB 发送成功响应时。我分析了 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 &gt;= 200
  • @bish 这不是我的代码,而是 feign-core api 代码。而 checkState() 方法是一个棘手的问题,因为它在 status >= 200 为 false 时触发异常

标签: java spring netflix-feign


【解决方案1】:

我找到了答案。问题是由tomcat引起的。版本 8.0.* 作为响应禁用了原因短语,因此我不得不启用它(幸运的是它仍然是可能的,因为在 9 以上的版本中它不是)。我必须编辑 server.xml 文件并附加到连接器 sendReasonPhrase 属性。现在看起来像这样:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           sendReasonPhrase="true"
           redirectPort="8443" />

Here 更多关于问题,here 更多关于连接器属性

【讨论】:

    猜你喜欢
    • 2020-06-02
    • 1970-01-01
    • 2015-05-03
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多