From 9a049bfc4308819ced635181a1ee81c8ddd34d05 Mon Sep 17 00:00:00 2001 From: Maciej Mierzwa Date: Thu, 4 Jan 2024 16:53:05 +0100 Subject: [PATCH] use library constants Signed-off-by: Maciej Mierzwa --- .../auth/http/saml/HTTPMetadataResolver.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java b/src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java index 47c491ab59..5097e24f44 100644 --- a/src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java +++ b/src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java @@ -20,6 +20,7 @@ import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpException; +import org.apache.hc.core5.http.HttpHeaders; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.http.HttpStatus; @@ -88,8 +89,8 @@ protected byte[] fetchMetadata() throws ResolverException { try { log.debug("{} Attempting to fetch metadata document from '{}'", getLogPrefix(), metadataURI); - return httpClient.execute(httpGet, context, response1 -> { - final int httpStatusCode = response1.getCode(); + return httpClient.execute(httpGet, context, response -> { + final int httpStatusCode = response.getCode(); if (httpStatusCode == HttpStatus.SC_NOT_MODIFIED) { log.debug("{} Metadata document from '{}' has not changed since last retrieval", getLogPrefix(), getMetadataURI()); return null; @@ -100,9 +101,9 @@ protected byte[] fetchMetadata() throws ResolverException { throw new HttpException(errMsg); } - processConditionalRetrievalHeaders(response1); + processConditionalRetrievalHeaders(response); try { - return getMetadataBytesFromResponse(response1); + return getMetadataBytesFromResponse(response); } catch (ResolverException e) { final String errMsg = "Error retrieving metadata from " + metadataURI; throw new HttpException(errMsg, e); @@ -119,22 +120,22 @@ protected HttpGet buildHttpGet() { final HttpGet getMethod = new HttpGet(getMetadataURI()); if (cachedMetadataETag != null) { - getMethod.setHeader("If-None-Match", cachedMetadataETag); + getMethod.setHeader(HttpHeaders.IF_NONE_MATCH, cachedMetadataETag); } if (cachedMetadataLastModified != null) { - getMethod.setHeader("If-Modified-Since", cachedMetadataLastModified); + getMethod.setHeader(HttpHeaders.IF_MODIFIED_SINCE, cachedMetadataLastModified); } return getMethod; } protected void processConditionalRetrievalHeaders(final ClassicHttpResponse response) { - Header httpHeader = response.getFirstHeader("ETag"); + Header httpHeader = response.getFirstHeader(HttpHeaders.ETAG); if (httpHeader != null) { cachedMetadataETag = httpHeader.getValue(); } - httpHeader = response.getFirstHeader("Last-Modified"); + httpHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED); if (httpHeader != null) { cachedMetadataLastModified = httpHeader.getValue(); }