mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-12 20:43:18 +00:00
[DURACOM-109] Minor fix
This commit is contained in:
@@ -27,10 +27,10 @@ import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.NoHttpResponseException;
|
||||
import org.apache.http.StatusLine;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
@@ -120,7 +120,7 @@ public class OpenaireRestConnector {
|
||||
params.add(new BasicNameValuePair("grant_type", "client_credentials"));
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
|
||||
|
||||
HttpClient httpClient = DSpaceHttpClientFactory.getInstance().build();
|
||||
try (CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().build()) {
|
||||
HttpResponse getResponse = httpClient.execute(httpPost);
|
||||
|
||||
JSONObject responseObject = null;
|
||||
@@ -141,12 +141,13 @@ public class OpenaireRestConnector {
|
||||
}
|
||||
}
|
||||
if (responseObject == null || !responseObject.has("access_token") || !responseObject.has("expires_in")) {
|
||||
throw new IOException("Unable to grab the access token using provided service url, client id and secret");
|
||||
throw new IOException("Unable to grab the access token using provided service url, " +
|
||||
"client id and secret");
|
||||
}
|
||||
|
||||
return new OpenaireRestToken(responseObject.get("access_token").toString(),
|
||||
Long.valueOf(responseObject.get("expires_in").toString()));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,7 +172,7 @@ public class OpenaireRestConnector {
|
||||
httpGet.addHeader("Authorization", "Bearer " + accessToken);
|
||||
}
|
||||
|
||||
HttpClient httpClient = DSpaceHttpClientFactory.getInstance().build();
|
||||
try (CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().build()) {
|
||||
getResponse = httpClient.execute(httpGet);
|
||||
|
||||
StatusLine status = getResponse.getStatusLine();
|
||||
@@ -192,8 +193,8 @@ public class OpenaireRestConnector {
|
||||
if (limitMax.length > 0) {
|
||||
limitMsg = limitMsg.concat(" of " + limitMax[0].getValue());
|
||||
}
|
||||
getGotError(
|
||||
new NoHttpResponseException(status.getReasonPhrase() + " with usage limit " + limitMsg),
|
||||
getGotError(new NoHttpResponseException(status.getReasonPhrase() + " with usage limit "
|
||||
+ limitMsg),
|
||||
url + '/' + file);
|
||||
} else {
|
||||
// 429 - Rate limit abuse
|
||||
@@ -207,6 +208,7 @@ public class OpenaireRestConnector {
|
||||
|
||||
// do not close this httpClient
|
||||
result = getResponse.getEntity().getContent();
|
||||
}
|
||||
} catch (MalformedURLException e1) {
|
||||
getGotError(e1, url + '/' + file);
|
||||
} catch (Exception e) {
|
||||
|
@@ -22,8 +22,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
@@ -87,7 +87,7 @@ public class OrcidV3AuthorDataProvider extends AbstractExternalDataProvider {
|
||||
httpPost.addHeader("Accept", "application/json");
|
||||
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
|
||||
HttpClient httpClient = DSpaceHttpClientFactory.getInstance().build();
|
||||
try (CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().build()) {
|
||||
HttpResponse getResponse = httpClient.execute(httpPost);
|
||||
|
||||
JSONObject responseObject = null;
|
||||
@@ -110,6 +110,7 @@ public class OrcidV3AuthorDataProvider extends AbstractExternalDataProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
||||
|
Reference in New Issue
Block a user