Source:
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (logger.isLoggable(Level.FINEST)) { if (responseContext.getHeaderString(HttpHeaders.WWW_AUTHENTICATE) != null) { logger.log(Level.FINEST, "Server Response: {0} {1}", new Object[]{responseContext.getStatus(), responseContext.getHeaderString(HttpHeaders.WWW_AUTHENTICATE)}); } } if (Response.Status.fromStatusCode(responseContext.getStatus()) == Status.UNAUTHORIZED && !authorizationPhase) { HashMap<String, String> map = parseHeaders(responseContext.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE)); if (map == null) { return; } digest_realm = map.get("realm"); digest_nonce = map.get("nonce"); digest_opaque = map.get("opaque"); digest_algorithm = ALGORITHM.parse(map.get("algorithm")); digest_qop = QOP.parse(map.get("qop")); String staleStr = map.get("stale"); boolean stale = (staleStr != null) && staleStr.toLowerCase().equals("true"); if (stale || !authorizationPhase) { authorizationPhase = true; Client client = requestContext.getClient(); String method = requestContext.getMethod(); MediaType mediaType = requestContext.getMediaType(); URI luri = requestContext.getUri(); WebTarget wt = client.target(luri); Builder builder = wt.request(mediaType); builder.headers(origHeaderMap); Response serverResponse2 = null; if (method.equals("GET")) { serverResponse2 = builder.get(); } else if (method.equals("POST")) { serverResponse2 = builder.post((Entity) requestContext.getEntity()); } else { throw new IOException("Method not implemented: " + method); } if (serverResponse2 == null) { return; } if (serverResponse2.hasEntity()) { String entity = serverResponse2.readEntity(String.class); responseContext.setEntityStream(new ByteArrayInputStream(entity.getBytes(CHARACTER_SET))); } MultivaluedMap<String, String> headers = responseContext.getHeaders(); headers.clear(); headers.putAll(serverResponse2.getStringHeaders()); responseContext.setStatus(serverResponse2.getStatus()); } } }

Target:
public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException { if (logger.isLoggable(Level.FINEST)) { if (responseContext.getHeaderString(HttpHeaders.WWW_AUTHENTICATE) != null) { logger.log(Level.FINEST, "Server Response: {0} {1}", new Object[]{responseContext.getStatus(), responseContext.getHeaderString(HttpHeaders.WWW_AUTHENTICATE)}); } } if (Response.Status.fromStatusCode(responseContext.getStatus()) == Status.UNAUTHORIZED) { DigestScheme digestScheme = parseAuthHeaders(responseContext.getHeaders().get(HttpHeaders.WWW_AUTHENTICATE)); if (digestScheme == null) { return; } if (digestScheme.isStale() || !digestCache.containsKey(requestContext.getUri())) { digestCache.put(requestContext.getUri(), digestScheme); Client client = requestContext.getClient(); String method = requestContext.getMethod(); MediaType mediaType = requestContext.getMediaType(); URI luri = requestContext.getUri(); WebTarget resourceTarget = client.target(luri); Invocation.Builder builder = resourceTarget.request(mediaType); builder.headers(requestContext.getHeaders()); Invocation invocation = builder.build(method); Response nextResponse = invocation.invoke(); if (nextResponse == null) { return; } if (nextResponse.hasEntity()) { String entity = nextResponse.readEntity(String.class); responseContext.setEntityStream(new ByteArrayInputStream(entity.getBytes(CHARACTER_SET))); } MultivaluedMap<String, String> headers = responseContext.getHeaders(); headers.clear(); headers.putAll(nextResponse.getStringHeaders()); responseContext.setStatus(nextResponse.getStatus()); } } }