我有简单的JAX-RS资源,我使用Apache CXF WebClient作为客户端。我正在使用HTTP基本身份验证。当它在服务器上失败时,典型的401 UNAUTHORIZED响应与WWW-Authenticate头一起发送。
当收到此(WWW-Auhenticate)标头时,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);
}
答案 0 :(得分:1)
我在CXF 3.1中发现了相同的问题。
对于我所有的异步http休息请求,如果响应到达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 = -1
和processRetransmit()
返回true,则线程进入无限循环。
因此,为解决此问题,我们在HttpConduit.getClient()
中将maxRetransmitValue传递为0。
希望其他人会
答案 1 :(得分:0)
最新版本的CXF已修复此问题: