httpcxfjax-rscxfrs

Apache CXF WebClient multiple requests with www-authenticate header


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);
}

Solution

  • This has been fixed in the latest versions of CXF:

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