[java-opensaml COMMIT] /trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynam...
noreply at shibboleth.net
noreply at shibboleth.net
Wed Oct 29 17:19:03 EDT 2014
Author: putmanb
Date: Wed Oct 29 17:19:01 2014
New Revision: 4120
URL: http://svn.shibboleth.net/view/java-opensaml?rev=4120&view=rev
Log:
Refactor abstract HTTP dynamic resolver to use an HttpClient ResponseHandler.
Modified:
trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java
Modified: trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java
URL: http://svn.shibboleth.net/view/java-opensaml/trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java?rev=4120&r1=4119&r2=4120&view=diff
==============================================================================
--- trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java (original)
+++ trunk/opensaml-saml-impl/src/main/java/org/opensaml/saml/metadata/resolver/impl/AbstractDynamicHTTPMetadataResolver.java Wed Oct 29 17:19:01 2014
@@ -19,7 +19,6 @@
import java.io.IOException;
import java.io.InputStream;
-import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -41,8 +40,9 @@
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
+import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.opensaml.core.xml.XMLObject;
@@ -75,6 +75,9 @@
/** Generated Accept request header value. */
private String supportedContentTypesValue;
+ /** HttpClient ResponseHandler instance to use. */
+ private ResponseHandler<XMLObject> responseHandler;
+
/**
* Constructor.
*
@@ -95,6 +98,9 @@
super(backgroundTaskTimer);
httpClient = Constraint.isNotNull(client, "HttpClient may not be null");
+
+ // The default handler
+ responseHandler = new BasicMetadataResponseHandler();
}
/**
@@ -157,9 +163,8 @@
return null;
}
- HttpResponse response = httpClient.execute(request);
-
- return processResponse(response, request.getURI());
+ //TODO HttpContext
+ return httpClient.execute(request, responseHandler);
}
/**
@@ -197,33 +202,29 @@
@Nullable protected abstract String buildRequestURL(@Nonnull final CriteriaSet criteria);
/**
- * Process the received HTTP response, including validating the response, unmarshalling the received metadata,
- * and storing the metadata in the backing store.
- *
- * @param response the received response
- * @param requestURI the original request URI
- *
- * @return the resolved metadata document root, or null if there was a fatal error
- */
- @Nullable protected XMLObject processResponse(@Nonnull final HttpResponse response, @Nonnull final URI requestURI) {
-
- int httpStatusCode = response.getStatusLine().getStatusCode();
-
- // TODO should we be seeing/doing this? Probably not if we don't do conditional GET.
- // But we will if we do pre-emptive refreshing of metadata in background thread.
- if (httpStatusCode == HttpStatus.SC_NOT_MODIFIED) {
- log.debug("Metadata document from '{}' has not changed since last retrieval", requestURI);
- return null;
- }
-
- if (httpStatusCode != HttpStatus.SC_OK) {
- log.warn("Non-ok status code '{}' returned from remote metadata source: {}", httpStatusCode, requestURI);
- return null;
- }
-
- try {
+ * Basic HttpClient response handler for processing metadata fetch requests.
+ */
+ public class BasicMetadataResponseHandler implements ResponseHandler<XMLObject> {
+
+ /** {@inheritDoc} */
+ public XMLObject handleResponse(@Nonnull final HttpResponse response) throws ClientProtocolException, IOException {
+
+ int httpStatusCode = response.getStatusLine().getStatusCode();
+
+ // TODO should we be seeing/doing this? Probably not if we don't do conditional GET.
+ // But we will if we do pre-emptive refreshing of metadata in background thread.
+ if (httpStatusCode == HttpStatus.SC_NOT_MODIFIED) {
+ log.debug("Metadata document from '{}' has not changed since last retrieval" );
+ return null;
+ }
+
+ if (httpStatusCode != HttpStatus.SC_OK) {
+ log.warn("Non-ok status code '{}' returned from remote metadata source: {}", httpStatusCode);
+ return null;
+ }
+
try {
- validateHttpResponse(response, requestURI);
[... 76 lines stripped ...]
More information about the commits
mailing list