【问题标题】:Apache CXF WebClient multiple requests with www-authenticate header带有 www-authenticate 标头的 Apache CXF WebClient 多个请求
【发布时间】:2018-08-03 15:30:56
【问题描述】:

我得到了简单的 JAX-RS 资源,并且我使用 Apache CXF WebClient 作为客户端。我正在使用 HTTP 基本身份验证。当它在服务器上失败时,典型的 401 UNAUTHORIZED 响应与 WWW-Authenticate 标头一起发送。

当收到此 (WWW-Authenticate) 标头时,WebClient 会发生奇怪的行为。 WebClient(内部)多次(20 次)重复相同的请求并且失败。

WebClient webClient = WebClientFactory.newClient("http://myserver/auth");
try {
    webClient.get(SimpleResponse.class);
    // inside GET, 20 HTTP GET requests are invoked
} catch (ServerWebApplicationException ex) {
    // data are present when WWW-authenticate header is not sent from server
    // if header is present, unmarshalling fails
    AuthError err = ex.toErrorObject(webClient, AuthError.class);
}

【问题讨论】:

    标签: http cxf jax-rs cxfrs


    【解决方案1】:

    我在 CXF 3.1 中发现了同样的问题。

    在我的情况下,如果响应为 401/407,则线程将进入无限循环并打印 WWW-Authenticate 未在响应中设置 .

    我分析了我发现的代码: 如果是来自HttpConduit.handleRetransmits-> processRetransmit-> AsyncHTTPConduit.authorizationRetransmit 的异步调用控制流 返回 true 并且在 HttpConduit 中的代码是

    int maxRetransmits = getMaxRetransmits(); updateCookiesBeforeRetransmit(); int nretransmits = 0; while ((maxRetransmits < 0 || nretransmits < maxRetransmits) && processRetransmit()) { nretransmits++; }

    如果maxRetransmits = -1processRetransmit() 返回true,则线程进入无限循环。

    所以为了克服这个问题,我们在HttpConduit.getClient() 中将 maxRetransmitValue 传递为 0。

    希望其他人也一样。

    【讨论】:

      【解决方案2】:

      此问题已在最新版本的 CXF 中得到修复:

      https://issues.apache.org/jira/browse/CXF-4815

      【讨论】:

      • 非常感谢丹尼尔。我正在运行最新的 TomEE,遗憾的是它有旧版本......希望来自 TomEE 的人能尽快更新库(我不能这样做,因为我只提供 WAR,而不是 AS)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-04-10
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 2018-10-19
      • 1970-01-01
      • 2020-07-18
      相关资源
      最近更新 更多