0

I got simple JAX-RS resource and I'm using Apache CXF WebClient as a client. I'm using HTTP basic authentication. When it fails on server, typical 401 UNAUTHORIZED response is sent along with WWW-Authenticate header.

The strange behavior happens with WebClient when this (WWW-Auhenticate) header is received. The WebClient (internally) repeats the same request multiple times (20 times) and than fails.

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);
}
zdenda.online
  • 2,451
  • 3
  • 23
  • 45

2 Answers2

1

I found the same problem in CXF 3.1.

In my case for all async http rest request if response came 401/407, then thread is going in infinite loop and printing WWW-Authenticate is not set in response.

What I analysed the code I found that : In case of Asynchronous call Control flow from HttpConduit.handleRetransmits-> processRetransmit-> AsyncHTTPConduit.authorizationRetransmit which return true and in HttpConduit the code is

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

If maxRetransmits = -1 and processRetransmit() return true then thread going in infinite loop.

So to overcome this issue we pass maxRetransmitValue as 0 in HttpConduit.getClient().

Hope it will others.

Alien
  • 15,141
  • 6
  • 37
  • 57
0

This has been fixed in the latest versions of CXF:

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

Daniel Kulp
  • 14,447
  • 4
  • 45
  • 37
  • Thanks a lot Daniel. I'm running on lastest TomEE that sadly has older versions... Hope that guys from TomEE will udpate libs soon (I cannot do so, because I only supply the WARs, not AS) – zdenda.online May 25 '13 at 21:07