Skip to content

Commit

Permalink
use library constants
Browse files Browse the repository at this point in the history
Signed-off-by: Maciej Mierzwa <[email protected]>
  • Loading branch information
MaciejMierzwa committed Jan 4, 2024
1 parent 7488f91 commit 9a049bf
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Check warning on line 96 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L95-L96

Added lines #L95 - L96 were not covered by tests
Expand All @@ -100,9 +101,9 @@ protected byte[] fetchMetadata() throws ResolverException {
throw new HttpException(errMsg);

Check warning on line 101 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L99-L101

Added lines #L99 - L101 were not covered by tests
}

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

Check warning on line 109 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L107-L109

Added lines #L107 - L109 were not covered by tests
Expand All @@ -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);

Check warning on line 123 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L123

Added line #L123 was not covered by tests
}
if (cachedMetadataLastModified != null) {
getMethod.setHeader("If-Modified-Since", cachedMetadataLastModified);
getMethod.setHeader(HttpHeaders.IF_MODIFIED_SINCE, cachedMetadataLastModified);

Check warning on line 126 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L126

Added line #L126 was not covered by tests
}

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

Check warning on line 135 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L135

Added line #L135 was not covered by tests
}

httpHeader = response.getFirstHeader("Last-Modified");
httpHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED);
if (httpHeader != null) {
cachedMetadataLastModified = httpHeader.getValue();

Check warning on line 140 in src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/com/amazon/dlic/auth/http/saml/HTTPMetadataResolver.java#L140

Added line #L140 was not covered by tests
}
Expand Down

0 comments on commit 9a049bf

Please sign in to comment.