Skip to content

Commit

Permalink
Add support for "Authorization" header in OAI-PMH -- against standard!
Browse files Browse the repository at this point in the history
  • Loading branch information
uschindler committed May 3, 2021
1 parent b3aebe7 commit 57f2e8c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/de/pangaea/metadataportal/harvester/OAIHarvesterBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public abstract class OAIHarvesterBase extends Harvester {
public static final int DEFAULT_RETRY_COUNT = 5;
public static final int DEFAULT_TIMEOUT = 180; // seconds

public static final String USER_AGENT = new StringBuilder("Java/")
.append(System.getProperty("java.version")).append(" (")
.append(de.pangaea.metadataportal.Package.getProductName()).append('/')
.append(de.pangaea.metadataportal.Package.getVersion())
.append("; OAI downloader)").toString();

/** the used metadata prefix from the configuration */
protected final String metadataPrefix;

Expand All @@ -85,8 +91,8 @@ public abstract class OAIHarvesterBase extends Harvester {

/** the sets to harvest from the configuration, <code>null</code> to harvest all */
protected final Set<String> sets;
/** the retryCount from configuration */

/** the retryCount from configuration */
protected final int retryCount;

/** the retryTime from configuration */
Expand All @@ -95,6 +101,9 @@ public abstract class OAIHarvesterBase extends Harvester {
/** the timeout from configuration */
protected final int timeout;

/** the authorizationHeader from configuration */
protected final String authorizationHeader;

/** If enabled, does full harvesting, while ignoring all datestamps (default is {@code false}). They are saved, but ignored, if invalid. */
protected final boolean ignoreDatestamps;

Expand Down Expand Up @@ -126,6 +135,7 @@ public OAIHarvesterBase(HarvesterConfig iconfig) {
retryCount = Integer.parseInt(iconfig.properties.getProperty("retryCount", Integer.toString(DEFAULT_RETRY_COUNT)));
retryTime = Integer.parseInt(iconfig.properties.getProperty("retryAfterSeconds", Integer.toString(DEFAULT_RETRY_TIME)));
timeout = Integer.parseInt(iconfig.properties.getProperty("timeoutAfterSeconds", Integer.toString(DEFAULT_TIMEOUT)));
authorizationHeader = iconfig.properties.getProperty("authorizationHeader");
metadataPrefix = iconfig.properties.getProperty("metadataPrefix");
if (metadataPrefix == null) {
throw new NullPointerException("No metadataPrefix for the OAI repository was given!");
Expand Down Expand Up @@ -299,13 +309,10 @@ protected InputSource getInputSource(URL url,
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(timeout * 1000);
conn.setReadTimeout(timeout * 1000);

StringBuilder ua = new StringBuilder("Java/")
.append(System.getProperty("java.version")).append(" (")
.append(de.pangaea.metadataportal.Package.getProductName()).append('/')
.append(de.pangaea.metadataportal.Package.getVersion())
.append("; OAI downloader)");
conn.setRequestProperty("User-Agent", ua.toString());
conn.setRequestProperty("User-Agent", USER_AGENT);
if (authorizationHeader != null) {
conn.setRequestProperty("Authorization", authorizationHeader);
}

conn.setRequestProperty("Accept-Encoding",
"gzip, deflate, identity;q=0.3, *;q=0");
Expand Down Expand Up @@ -421,7 +428,8 @@ protected void enumerateValidHarvesterPropertyNames(Set<String> props) {
super.enumerateValidHarvesterPropertyNames(props);
props.addAll(Arrays.asList("setSpec", "retryCount",
"retryAfterSeconds", "timeoutAfterSeconds", "metadataPrefix",
"identifierPrefix", "ignoreDatestamps", "deleteMissingDocuments"));
"identifierPrefix", "ignoreDatestamps", "deleteMissingDocuments",
"authorizationHeader"));
}

}

0 comments on commit 57f2e8c

Please sign in to comment.