Configurator extends ClientEndpointConfig.Configurator { @Override public void beforeRequest(Map<String, List<String>> headers) { if (username != null && password != null) { String creds = "Basic " + getEncoder().encodeToString((username + ":" + password).getBytes(UTF_8)); headers.put("Authorization", singletonList(creds)); } List<String> cookie = cookieHolder.get(); if (cookie != null) { headers.put("Cookie", cookie); } Token token = MavenUserAgent.token(OfframpClient.class, "com.hotels.road", "road-offramp-v2-client"); String userAgent = UserAgent.create().add(token).toString(); headers.put("User-Agent", singletonList(userAgent)); }  @Override void beforeRequest(Map<String, List<String>> headers); @Override void afterResponse(HandshakeResponse response);  }
@Test public void auth() throws Exception { Map<String, List<String>> headers = new HashMap<>(); underTest.beforeRequest(headers); assertThat(headers.get("Authorization"), is(singletonList("Basic dXNlcm5hbWU6cGFzc3dvcmQ="))); }
@Test public void userAgent() throws Exception { Map<String, List<String>> headers = new HashMap<>(); underTest.beforeRequest(headers); assertThat(headers.get("User-Agent").get(0), startsWith("road-offramp-v2-client/")); }