mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-13 13:03:11 +00:00
Replace deprecated org.apache.http.impl.client.DefaultHttpClient [#2956]
This commit is contained in:
@@ -15,9 +15,9 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpHead;
|
import org.apache.http.client.methods.HttpHead;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.util.dao.WebAppDAO;
|
import org.dspace.app.util.dao.WebAppDAO;
|
||||||
import org.dspace.app.util.service.WebAppService;
|
import org.dspace.app.util.service.WebAppService;
|
||||||
@@ -76,13 +76,13 @@ public class WebAppServiceImpl implements WebAppService {
|
|||||||
|
|
||||||
for (WebApp app : webApps) {
|
for (WebApp app : webApps) {
|
||||||
method = new HttpHead(app.getUrl());
|
method = new HttpHead(app.getUrl());
|
||||||
HttpClient client = new DefaultHttpClient();
|
int status;
|
||||||
|
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
|
||||||
HttpResponse response = client.execute(method);
|
HttpResponse response = client.execute(method);
|
||||||
int status = response.getStatusLine().getStatusCode();
|
status = response.getStatusLine().getStatusCode();
|
||||||
|
}
|
||||||
if (status != HttpStatus.SC_OK) {
|
if (status != HttpStatus.SC_OK) {
|
||||||
delete(context, app
|
delete(context, app);
|
||||||
|
|
||||||
);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -30,9 +30,9 @@ import javax.xml.xpath.XPathFactory;
|
|||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
@@ -150,15 +150,16 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
// field separator in result string
|
// field separator in result string
|
||||||
protected String fieldSeparator = null;
|
protected String fieldSeparator = null;
|
||||||
// optional XML namespace map
|
// optional XML namespace map
|
||||||
protected Map<String, String> nsMap = new HashMap<String, String>();
|
protected Map<String, String> nsMap = new HashMap<>();
|
||||||
// optional HTTP headers
|
// optional HTTP headers
|
||||||
protected Map<String, String> headers = new HashMap<String, String>();
|
protected Map<String, String> headers = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes task
|
* Initializes task
|
||||||
*
|
*
|
||||||
* @param curator Curator object performing this task
|
* @param curator Curator object performing this task
|
||||||
* @param taskId the configured local name of the task
|
* @param taskId the configured local name of the task
|
||||||
|
* @throws IOException if the parser could not be configured, or passed through.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void init(Curator curator, String taskId) throws IOException {
|
public void init(Curator curator, String taskId) throws IOException {
|
||||||
@@ -210,12 +211,6 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform the curation task upon passed DSO
|
|
||||||
*
|
|
||||||
* @param dso the DSpace object
|
|
||||||
* @throws IOException if IO error
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int perform(DSpaceObject dso) throws IOException {
|
public int perform(DSpaceObject dso) throws IOException {
|
||||||
|
|
||||||
@@ -254,7 +249,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
protected int callService(String value, Item item, StringBuilder resultSb) throws IOException {
|
protected int callService(String value, Item item, StringBuilder resultSb) throws IOException {
|
||||||
|
|
||||||
String callUrl = urlTemplate.replaceAll("\\{" + templateParam + "\\}", value);
|
String callUrl = urlTemplate.replaceAll("\\{" + templateParam + "\\}", value);
|
||||||
HttpClient client = new DefaultHttpClient();
|
CloseableHttpClient client = HttpClientBuilder.create().build();
|
||||||
HttpGet req = new HttpGet(callUrl);
|
HttpGet req = new HttpGet(callUrl);
|
||||||
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
for (Map.Entry<String, String> entry : headers.entrySet()) {
|
||||||
req.addHeader(entry.getKey(), entry.getValue());
|
req.addHeader(entry.getKey(), entry.getValue());
|
||||||
@@ -289,7 +284,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
// When HttpClient instance is no longer needed,
|
// When HttpClient instance is no longer needed,
|
||||||
// shut down the connection manager to ensure
|
// shut down the connection manager to ensure
|
||||||
// immediate deallocation of all system resources
|
// immediate deallocation of all system resources
|
||||||
client.getConnectionManager().shutdown();
|
client.close();
|
||||||
} else {
|
} else {
|
||||||
log.error(" obtained no valid service response");
|
log.error(" obtained no valid service response");
|
||||||
resultSb.append("no service response");
|
resultSb.append("no service response");
|
||||||
@@ -304,7 +299,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
protected int processResponse(Document doc, Item item, StringBuilder resultSb) throws IOException {
|
protected int processResponse(Document doc, Item item, StringBuilder resultSb) throws IOException {
|
||||||
boolean update = false;
|
boolean update = false;
|
||||||
int status = Curator.CURATE_ERROR;
|
int status = Curator.CURATE_ERROR;
|
||||||
List<String> values = new ArrayList<String>();
|
List<String> values = new ArrayList<>();
|
||||||
checkNamespaces(doc);
|
checkNamespaces(doc);
|
||||||
try {
|
try {
|
||||||
for (MetadataWebServiceDataInfo info : dataList) {
|
for (MetadataWebServiceDataInfo info : dataList) {
|
||||||
@@ -399,7 +394,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String[] tokenize(String text) {
|
protected String[] tokenize(String text) {
|
||||||
List<String> list = new ArrayList<String>();
|
List<String> list = new ArrayList<>();
|
||||||
Matcher m = ttPattern.matcher(text);
|
Matcher m = ttPattern.matcher(text);
|
||||||
while (m.find()) {
|
while (m.find()) {
|
||||||
if (m.group(1) != null) {
|
if (m.group(1) != null) {
|
||||||
@@ -491,7 +486,7 @@ public class MetadataWebService extends AbstractCurationTask implements Namespac
|
|||||||
} else {
|
} else {
|
||||||
int next = expr.indexOf("/", i);
|
int next = expr.indexOf("/", i);
|
||||||
String token = (next > 0) ? expr.substring(i, next) : expr.substring(i);
|
String token = (next > 0) ? expr.substring(i, next) : expr.substring(i);
|
||||||
if (!token.startsWith("@") && token.indexOf(":") < 0) {
|
if (!token.startsWith("@") && !token.contains(":")) {
|
||||||
sb.append(prefix).append(":");
|
sb.append(prefix).append(":");
|
||||||
}
|
}
|
||||||
sb.append(token);
|
sb.append(token);
|
||||||
|
@@ -13,9 +13,9 @@ import java.nio.charset.StandardCharsets;
|
|||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.services.ConfigurationService;
|
import org.dspace.services.ConfigurationService;
|
||||||
@@ -60,22 +60,22 @@ public class MicrosoftTranslator extends AbstractTranslator {
|
|||||||
String url = baseUrl + "?appId=" + apiKey;
|
String url = baseUrl + "?appId=" + apiKey;
|
||||||
url += "&to=" + to + "&from=" + from + "&text=" + text;
|
url += "&to=" + to + "&from=" + from + "&text=" + text;
|
||||||
|
|
||||||
HttpClient client = new DefaultHttpClient();
|
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
|
||||||
HttpGet hm = new HttpGet(url);
|
HttpGet hm = new HttpGet(url);
|
||||||
HttpResponse httpResponse = client.execute(hm);
|
HttpResponse httpResponse = client.execute(hm);
|
||||||
log.debug("Response code from API call is " + httpResponse);
|
log.debug("Response code from API call is " + httpResponse);
|
||||||
|
|
||||||
if (httpResponse.getStatusLine().getStatusCode() == 200) {
|
if (httpResponse.getStatusLine().getStatusCode() == 200) {
|
||||||
String response = IOUtils.toString(httpResponse.getEntity().getContent(), StandardCharsets.ISO_8859_1);
|
String response = IOUtils.toString(httpResponse.getEntity().getContent(),
|
||||||
|
StandardCharsets.ISO_8859_1);
|
||||||
response = response
|
response = response
|
||||||
.replaceAll("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
|
.replaceAll("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
|
||||||
response = response.replaceAll("</string>", "");
|
response = response.replaceAll("</string>", "");
|
||||||
translatedText = response;
|
translatedText = response;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return translatedText;
|
return translatedText;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,10 +21,10 @@ import javax.xml.parsers.SAXParserFactory;
|
|||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.content.DCPersonName;
|
import org.dspace.content.DCPersonName;
|
||||||
@@ -72,10 +72,12 @@ public class LCNameDataProvider implements ExternalDataProvider {
|
|||||||
protected static final String NS_MX = "http://www.loc.gov/MARC21/slim";
|
protected static final String NS_MX = "http://www.loc.gov/MARC21/slim";
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getSourceIdentifier() {
|
public String getSourceIdentifier() {
|
||||||
return sourceIdentifier;
|
return sourceIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
||||||
|
|
||||||
StringBuilder query = new StringBuilder();
|
StringBuilder query = new StringBuilder();
|
||||||
@@ -138,8 +140,7 @@ public class LCNameDataProvider implements ExternalDataProvider {
|
|||||||
|
|
||||||
HttpGet get = constructHttpGet(query, start, limit);
|
HttpGet get = constructHttpGet(query, start, limit);
|
||||||
// 2. web request
|
// 2. web request
|
||||||
try {
|
try (CloseableHttpClient hc = HttpClientBuilder.create().build()) {
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
SRUHandler handler = parseResponseToSRUHandler(response);
|
SRUHandler handler = parseResponseToSRUHandler(response);
|
||||||
@@ -166,6 +167,7 @@ public class LCNameDataProvider implements ExternalDataProvider {
|
|||||||
return Collections.EMPTY_LIST;
|
return Collections.EMPTY_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean supports(String source) {
|
public boolean supports(String source) {
|
||||||
return StringUtils.equalsIgnoreCase(sourceIdentifier, source);
|
return StringUtils.equalsIgnoreCase(sourceIdentifier, source);
|
||||||
}
|
}
|
||||||
@@ -208,8 +210,7 @@ public class LCNameDataProvider implements ExternalDataProvider {
|
|||||||
HttpGet get = constructHttpGet(queryStringBuilder, 0, 1);
|
HttpGet get = constructHttpGet(queryStringBuilder, 0, 1);
|
||||||
|
|
||||||
// 2. web request
|
// 2. web request
|
||||||
try {
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
SRUHandler handler = parseResponseToSRUHandler(response);
|
SRUHandler handler = parseResponseToSRUHandler(response);
|
||||||
@@ -253,8 +254,8 @@ public class LCNameDataProvider implements ExternalDataProvider {
|
|||||||
*/
|
*/
|
||||||
private static class SRUHandler
|
private static class SRUHandler
|
||||||
extends DefaultHandler {
|
extends DefaultHandler {
|
||||||
private String sourceIdentifier;
|
private final String sourceIdentifier;
|
||||||
private List<ExternalDataObject> result = new ArrayList<ExternalDataObject>();
|
private List<ExternalDataObject> result = new ArrayList<>();
|
||||||
private int hits = -1;
|
private int hits = -1;
|
||||||
private String textValue = null;
|
private String textValue = null;
|
||||||
private String name = null;
|
private String name = null;
|
||||||
|
@@ -18,13 +18,11 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -35,8 +33,8 @@ import org.dspace.external.model.ExternalDataObject;
|
|||||||
import org.dspace.external.provider.ExternalDataProvider;
|
import org.dspace.external.provider.ExternalDataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the implementation of the ExternalDataProvider interface that will deal with SherpaJournal External
|
* This class is the implementation of the ExternalDataProvider interface that
|
||||||
* data lookups
|
* will deal with SherpaJournal External data lookups.
|
||||||
*/
|
*/
|
||||||
public class SherpaJournalDataProvider implements ExternalDataProvider {
|
public class SherpaJournalDataProvider implements ExternalDataProvider {
|
||||||
|
|
||||||
@@ -138,8 +136,7 @@ public class SherpaJournalDataProvider implements ExternalDataProvider {
|
|||||||
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
||||||
// query args to add to SHERPA/RoMEO request URL
|
// query args to add to SHERPA/RoMEO request URL
|
||||||
HttpGet get = constructHttpGet(query);
|
HttpGet get = constructHttpGet(query);
|
||||||
try {
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
|
||||||
@@ -161,7 +158,7 @@ public class SherpaJournalDataProvider implements ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HttpGet constructHttpGet(String query) {
|
private HttpGet constructHttpGet(String query) {
|
||||||
List<BasicNameValuePair> args = new ArrayList<BasicNameValuePair>();
|
List<BasicNameValuePair> args = new ArrayList<>();
|
||||||
args.add(new BasicNameValuePair("jtitle", query));
|
args.add(new BasicNameValuePair("jtitle", query));
|
||||||
args.add(new BasicNameValuePair("qtype", "contains"));
|
args.add(new BasicNameValuePair("qtype", "contains"));
|
||||||
args.add(new BasicNameValuePair("ak", apiKey));
|
args.add(new BasicNameValuePair("ak", apiKey));
|
||||||
@@ -177,11 +174,9 @@ public class SherpaJournalDataProvider implements ExternalDataProvider {
|
|||||||
@Override
|
@Override
|
||||||
public int getNumberOfResults(String query) {
|
public int getNumberOfResults(String query) {
|
||||||
HttpGet get = constructHttpGet(query);
|
HttpGet get = constructHttpGet(query);
|
||||||
try {
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
|
||||||
SHERPAResponse sherpaResponse = new SHERPAResponse(response.getEntity().getContent());
|
SHERPAResponse sherpaResponse = new SHERPAResponse(response.getEntity().getContent());
|
||||||
return sherpaResponse.getNumHits();
|
return sherpaResponse.getNumHits();
|
||||||
}
|
}
|
||||||
|
@@ -16,10 +16,10 @@ import java.util.stream.Collectors;
|
|||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.HttpClient;
|
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.utils.URLEncodedUtils;
|
import org.apache.http.client.utils.URLEncodedUtils;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.sherpa.SHERPAPublisher;
|
import org.dspace.app.sherpa.SHERPAPublisher;
|
||||||
@@ -29,8 +29,8 @@ import org.dspace.external.model.ExternalDataObject;
|
|||||||
import org.dspace.external.provider.ExternalDataProvider;
|
import org.dspace.external.provider.ExternalDataProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the implementation of the ExternalDataProvider interface that will deal with SherpaPublisher External
|
* This class is the implementation of the ExternalDataProvider interface that
|
||||||
* data lookups
|
* will deal with SherpaPublisher External data lookups.
|
||||||
*/
|
*/
|
||||||
public class SherpaPublisherDataProvider implements ExternalDataProvider {
|
public class SherpaPublisherDataProvider implements ExternalDataProvider {
|
||||||
|
|
||||||
@@ -47,13 +47,12 @@ public class SherpaPublisherDataProvider implements ExternalDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
public Optional<ExternalDataObject> getExternalDataObject(String id) {
|
||||||
List<BasicNameValuePair> args = new ArrayList<BasicNameValuePair>();
|
List<BasicNameValuePair> args = new ArrayList<>();
|
||||||
args.add(new BasicNameValuePair("id", id));
|
args.add(new BasicNameValuePair("id", id));
|
||||||
args.add(new BasicNameValuePair("ak", apiKey));
|
args.add(new BasicNameValuePair("ak", apiKey));
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
String srUrl = url + "?" + URLEncodedUtils.format(args, "UTF8");
|
String srUrl = url + "?" + URLEncodedUtils.format(args, "UTF8");
|
||||||
HttpGet get = new HttpGet(srUrl);
|
HttpGet get = new HttpGet(srUrl);
|
||||||
try {
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
SHERPAResponse sherpaResponse = new SHERPAResponse(response.getEntity().getContent());
|
SHERPAResponse sherpaResponse = new SHERPAResponse(response.getEntity().getContent());
|
||||||
@@ -74,8 +73,7 @@ public class SherpaPublisherDataProvider implements ExternalDataProvider {
|
|||||||
@Override
|
@Override
|
||||||
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
public List<ExternalDataObject> searchExternalDataObjects(String query, int start, int limit) {
|
||||||
HttpGet get = constructHttpGet(query);
|
HttpGet get = constructHttpGet(query);
|
||||||
try {
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
SHERPAResponse sherpaResponse = new SHERPAResponse(response.getEntity().getContent());
|
SHERPAResponse sherpaResponse = new SHERPAResponse(response.getEntity().getContent());
|
||||||
@@ -97,7 +95,7 @@ public class SherpaPublisherDataProvider implements ExternalDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private HttpGet constructHttpGet(String query) {
|
private HttpGet constructHttpGet(String query) {
|
||||||
List<BasicNameValuePair> args = new ArrayList<BasicNameValuePair>();
|
List<BasicNameValuePair> args = new ArrayList<>();
|
||||||
args.add(new BasicNameValuePair("pub", query));
|
args.add(new BasicNameValuePair("pub", query));
|
||||||
args.add(new BasicNameValuePair("qtype", "all"));
|
args.add(new BasicNameValuePair("qtype", "all"));
|
||||||
args.add(new BasicNameValuePair("ak", apiKey));
|
args.add(new BasicNameValuePair("ak", apiKey));
|
||||||
@@ -135,8 +133,7 @@ public class SherpaPublisherDataProvider implements ExternalDataProvider {
|
|||||||
@Override
|
@Override
|
||||||
public int getNumberOfResults(String query) {
|
public int getNumberOfResults(String query) {
|
||||||
HttpGet get = constructHttpGet(query);
|
HttpGet get = constructHttpGet(query);
|
||||||
try {
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient hc = new DefaultHttpClient();
|
|
||||||
HttpResponse response = hc.execute(get);
|
HttpResponse response = hc.execute(get);
|
||||||
if (response.getStatusLine().getStatusCode() == 200) {
|
if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
|
||||||
|
@@ -20,14 +20,18 @@ import org.apache.http.HttpResponse;
|
|||||||
import org.apache.http.StatusLine;
|
import org.apache.http.StatusLine;
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.CredentialsProvider;
|
||||||
import org.apache.http.client.methods.HttpDelete;
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.methods.HttpUriRequest;
|
import org.apache.http.client.methods.HttpUriRequest;
|
||||||
|
import org.apache.http.client.protocol.HttpClientContext;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.apache.http.entity.ContentType;
|
import org.apache.http.entity.ContentType;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
@@ -269,10 +273,7 @@ public class DataCiteConnector
|
|||||||
default: {
|
default: {
|
||||||
log.warn("While checking if the DOI {} is registered, we got a "
|
log.warn("While checking if the DOI {} is registered, we got a "
|
||||||
+ "http status code {} and the message \"{}\".",
|
+ "http status code {} and the message \"{}\".",
|
||||||
new String[] {
|
doi, Integer.toString(resp.statusCode), resp.getContent());
|
||||||
doi, Integer.toString(resp.statusCode),
|
|
||||||
resp.getContent()
|
|
||||||
});
|
|
||||||
throw new DOIIdentifierException("Unable to parse an answer from "
|
throw new DOIIdentifierException("Unable to parse an answer from "
|
||||||
+ "DataCite API. Please have a look into DSpace logs.",
|
+ "DataCite API. Please have a look into DSpace logs.",
|
||||||
DOIIdentifierException.BAD_ANSWER);
|
DOIIdentifierException.BAD_ANSWER);
|
||||||
@@ -305,7 +306,7 @@ public class DataCiteConnector
|
|||||||
default: {
|
default: {
|
||||||
log.warn("While checking if the DOI {} is registered, we got a "
|
log.warn("While checking if the DOI {} is registered, we got a "
|
||||||
+ "http status code {} and the message \"{}\".",
|
+ "http status code {} and the message \"{}\".",
|
||||||
new String[] {doi, Integer.toString(response.statusCode), response.getContent()});
|
doi, Integer.toString(response.statusCode), response.getContent());
|
||||||
throw new DOIIdentifierException("Unable to parse an answer from "
|
throw new DOIIdentifierException("Unable to parse an answer from "
|
||||||
+ "DataCite API. Please have a look into DSpace logs.",
|
+ "DataCite API. Please have a look into DSpace logs.",
|
||||||
DOIIdentifierException.BAD_ANSWER);
|
DOIIdentifierException.BAD_ANSWER);
|
||||||
@@ -338,7 +339,7 @@ public class DataCiteConnector
|
|||||||
default: {
|
default: {
|
||||||
log.warn("While deleting metadata of DOI {}, we got a "
|
log.warn("While deleting metadata of DOI {}, we got a "
|
||||||
+ "http status code {} and the message \"{}\".",
|
+ "http status code {} and the message \"{}\".",
|
||||||
new String[] {doi, Integer.toString(resp.statusCode), resp.getContent()});
|
doi, Integer.toString(resp.statusCode), resp.getContent());
|
||||||
throw new DOIIdentifierException("Unable to parse an answer from "
|
throw new DOIIdentifierException("Unable to parse an answer from "
|
||||||
+ "DataCite API. Please have a look into DSpace logs.",
|
+ "DataCite API. Please have a look into DSpace logs.",
|
||||||
DOIIdentifierException.BAD_ANSWER);
|
DOIIdentifierException.BAD_ANSWER);
|
||||||
@@ -452,8 +453,8 @@ public class DataCiteConnector
|
|||||||
// Catch all other http status code in case we forgot one.
|
// Catch all other http status code in case we forgot one.
|
||||||
default: {
|
default: {
|
||||||
log.warn("While reserving the DOI {}, we got a http status code "
|
log.warn("While reserving the DOI {}, we got a http status code "
|
||||||
+ "{} and the message \"{}\".", new String[]
|
+ "{} and the message \"{}\".",
|
||||||
{doi, Integer.toString(resp.statusCode), resp.getContent()});
|
doi, Integer.toString(resp.statusCode), resp.getContent());
|
||||||
throw new DOIIdentifierException("Unable to parse an answer from "
|
throw new DOIIdentifierException("Unable to parse an answer from "
|
||||||
+ "DataCite API. Please have a look into DSpace logs.",
|
+ "DataCite API. Please have a look into DSpace logs.",
|
||||||
DOIIdentifierException.BAD_ANSWER);
|
DOIIdentifierException.BAD_ANSWER);
|
||||||
@@ -511,8 +512,8 @@ public class DataCiteConnector
|
|||||||
// Catch all other http status code in case we forgot one.
|
// Catch all other http status code in case we forgot one.
|
||||||
default: {
|
default: {
|
||||||
log.warn("While registration of DOI {}, we got a http status code "
|
log.warn("While registration of DOI {}, we got a http status code "
|
||||||
+ "{} and the message \"{}\".", new String[]
|
+ "{} and the message \"{}\".",
|
||||||
{doi, Integer.toString(resp.statusCode), resp.getContent()});
|
doi, Integer.toString(resp.statusCode), resp.getContent());
|
||||||
throw new DOIIdentifierException("Unable to parse an answer from "
|
throw new DOIIdentifierException("Unable to parse an answer from "
|
||||||
+ "DataCite API. Please have a look into DSpace logs.",
|
+ "DataCite API. Please have a look into DSpace logs.",
|
||||||
DOIIdentifierException.BAD_ANSWER);
|
DOIIdentifierException.BAD_ANSWER);
|
||||||
@@ -684,14 +685,16 @@ public class DataCiteConnector
|
|||||||
*/
|
*/
|
||||||
protected DataCiteResponse sendHttpRequest(HttpUriRequest req, String doi)
|
protected DataCiteResponse sendHttpRequest(HttpUriRequest req, String doi)
|
||||||
throws DOIIdentifierException {
|
throws DOIIdentifierException {
|
||||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||||
httpclient.getCredentialsProvider().setCredentials(
|
credentialsProvider.setCredentials(new AuthScope(HOST, 443),
|
||||||
new AuthScope(HOST, 443),
|
|
||||||
new UsernamePasswordCredentials(this.getUsername(), this.getPassword()));
|
new UsernamePasswordCredentials(this.getUsername(), this.getPassword()));
|
||||||
|
|
||||||
|
HttpClientContext httpContext = HttpClientContext.create();
|
||||||
|
httpContext.setCredentialsProvider(credentialsProvider);
|
||||||
|
|
||||||
HttpEntity entity = null;
|
HttpEntity entity = null;
|
||||||
try {
|
try ( CloseableHttpClient httpclient = HttpClientBuilder.create().build(); ) {
|
||||||
HttpResponse response = httpclient.execute(req);
|
HttpResponse response = httpclient.execute(req, httpContext);
|
||||||
|
|
||||||
StatusLine status = response.getStatusLine();
|
StatusLine status = response.getStatusLine();
|
||||||
int statusCode = status.getStatusCode();
|
int statusCode = status.getStatusCode();
|
||||||
|
@@ -17,13 +17,16 @@ import java.util.Map.Entry;
|
|||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.auth.AuthScope;
|
import org.apache.http.auth.AuthScope;
|
||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.CredentialsProvider;
|
||||||
import org.apache.http.client.methods.HttpDelete;
|
import org.apache.http.client.methods.HttpDelete;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.client.methods.HttpPut;
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.client.protocol.HttpClientContext;
|
||||||
import org.apache.http.entity.StringEntity;
|
import org.apache.http.entity.StringEntity;
|
||||||
import org.apache.http.impl.client.AbstractHttpClient;
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.dspace.identifier.DOI;
|
import org.dspace.identifier.DOI;
|
||||||
import org.dspace.identifier.IdentifierException;
|
import org.dspace.identifier.IdentifierException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -45,7 +48,9 @@ public class EZIDRequest {
|
|||||||
|
|
||||||
private static final String MD_KEY_STATUS = "_status";
|
private static final String MD_KEY_STATUS = "_status";
|
||||||
|
|
||||||
private final AbstractHttpClient client;
|
private final CloseableHttpClient client;
|
||||||
|
|
||||||
|
private final HttpClientContext httpContext;
|
||||||
|
|
||||||
private final String scheme;
|
private final String scheme;
|
||||||
|
|
||||||
@@ -82,11 +87,12 @@ public class EZIDRequest {
|
|||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
client = new DefaultHttpClient();
|
client = HttpClientBuilder.create().build();
|
||||||
|
httpContext = HttpClientContext.create();
|
||||||
if (null != username) {
|
if (null != username) {
|
||||||
URI uri = new URI(scheme, host, path, null);
|
URI uri = new URI(scheme, host, path, null);
|
||||||
client.getCredentialsProvider().setCredentials(
|
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||||
new AuthScope(uri.getHost(), uri.getPort()),
|
credentialsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
|
||||||
new UsernamePasswordCredentials(username, password));
|
new UsernamePasswordCredentials(username, password));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,12 +124,14 @@ public class EZIDRequest {
|
|||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
client = new DefaultHttpClient();
|
client = HttpClientBuilder.create().build();
|
||||||
|
httpContext = HttpClientContext.create();
|
||||||
if (null != username) {
|
if (null != username) {
|
||||||
|
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||||
URI uri = new URI(scheme, host, path, null);
|
URI uri = new URI(scheme, host, path, null);
|
||||||
client.getCredentialsProvider().setCredentials(
|
credentialsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()),
|
||||||
new AuthScope(uri.getHost(), uri.getPort()),
|
|
||||||
new UsernamePasswordCredentials(username, password));
|
new UsernamePasswordCredentials(username, password));
|
||||||
|
httpContext.setCredentialsProvider(credentialsProvider);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +151,7 @@ public class EZIDRequest {
|
|||||||
URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
|
URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
|
||||||
log.debug("EZID lookup {}", uri.toASCIIString());
|
log.debug("EZID lookup {}", uri.toASCIIString());
|
||||||
request = new HttpGet(uri);
|
request = new HttpGet(uri);
|
||||||
HttpResponse response = client.execute(request);
|
HttpResponse response = client.execute(request, httpContext);
|
||||||
return new EZIDResponse(response);
|
return new EZIDResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +177,7 @@ public class EZIDRequest {
|
|||||||
if (null != metadata) {
|
if (null != metadata) {
|
||||||
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
|
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
|
||||||
}
|
}
|
||||||
HttpResponse response = client.execute(request);
|
HttpResponse response = client.execute(request, httpContext);
|
||||||
return new EZIDResponse(response);
|
return new EZIDResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +201,7 @@ public class EZIDRequest {
|
|||||||
if (null != metadata) {
|
if (null != metadata) {
|
||||||
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
|
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
|
||||||
}
|
}
|
||||||
HttpResponse response = client.execute(request);
|
HttpResponse response = client.execute(request, httpContext);
|
||||||
EZIDResponse myResponse = new EZIDResponse(response);
|
EZIDResponse myResponse = new EZIDResponse(response);
|
||||||
return myResponse;
|
return myResponse;
|
||||||
}
|
}
|
||||||
@@ -220,7 +228,7 @@ public class EZIDRequest {
|
|||||||
log.debug("EZID modify {}", uri.toASCIIString());
|
log.debug("EZID modify {}", uri.toASCIIString());
|
||||||
request = new HttpPost(uri);
|
request = new HttpPost(uri);
|
||||||
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
|
request.setEntity(new StringEntity(formatMetadata(metadata), UTF_8));
|
||||||
HttpResponse response = client.execute(request);
|
HttpResponse response = client.execute(request, httpContext);
|
||||||
return new EZIDResponse(response);
|
return new EZIDResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +248,7 @@ public class EZIDRequest {
|
|||||||
URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
|
URI uri = new URI(scheme, host, path + ID_PATH + authority + name, null);
|
||||||
log.debug("EZID delete {}", uri.toASCIIString());
|
log.debug("EZID delete {}", uri.toASCIIString());
|
||||||
request = new HttpDelete(uri);
|
request = new HttpDelete(uri);
|
||||||
HttpResponse response = client.execute(request);
|
HttpResponse response = client.execute(request, httpContext);
|
||||||
return new EZIDResponse(response);
|
return new EZIDResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,7 +263,7 @@ public class EZIDRequest {
|
|||||||
*/
|
*/
|
||||||
public EZIDResponse withdraw(String name)
|
public EZIDResponse withdraw(String name)
|
||||||
throws IOException, IdentifierException, URISyntaxException {
|
throws IOException, IdentifierException, URISyntaxException {
|
||||||
Map<String, String> metadata = new HashMap<String, String>();
|
Map<String, String> metadata = new HashMap<>();
|
||||||
metadata.put(MD_KEY_STATUS, "unavailable");
|
metadata.put(MD_KEY_STATUS, "unavailable");
|
||||||
return modify(name, metadata);
|
return modify(name, metadata);
|
||||||
}
|
}
|
||||||
@@ -272,7 +280,7 @@ public class EZIDRequest {
|
|||||||
*/
|
*/
|
||||||
public EZIDResponse withdraw(String name, String reason)
|
public EZIDResponse withdraw(String name, String reason)
|
||||||
throws IOException, IdentifierException, URISyntaxException {
|
throws IOException, IdentifierException, URISyntaxException {
|
||||||
Map<String, String> metadata = new HashMap<String, String>();
|
Map<String, String> metadata = new HashMap<>();
|
||||||
metadata.put(MD_KEY_STATUS, "unavailable | " + escape(reason));
|
metadata.put(MD_KEY_STATUS, "unavailable | " + escape(reason));
|
||||||
return modify(name, metadata);
|
return modify(name, metadata);
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,8 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.apache.solr.client.solrj.SolrClient;
|
import org.apache.solr.client.solrj.SolrClient;
|
||||||
@@ -1067,7 +1068,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
|||||||
* The code below creates a query that will allow only records which do not have a bundlename
|
* The code below creates a query that will allow only records which do not have a bundlename
|
||||||
* (items, collections, ...) or bitstreams that have a configured bundle name
|
* (items, collections, ...) or bitstreams that have a configured bundle name
|
||||||
*/
|
*/
|
||||||
StringBuffer bundleQuery = new StringBuffer();
|
StringBuilder bundleQuery = new StringBuilder();
|
||||||
//Also add the possibility that if no bundle name is there these results will also be returned !
|
//Also add the possibility that if no bundle name is there these results will also be returned !
|
||||||
bundleQuery.append("-(bundleName:[* TO *]");
|
bundleQuery.append("-(bundleName:[* TO *]");
|
||||||
for (int i = 0; i < bundles.length; i++) {
|
for (int i = 0; i < bundles.length; i++) {
|
||||||
@@ -1219,12 +1220,20 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
|||||||
solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);
|
solrRequestUrl = generateURL(solrRequestUrl, yearQueryParams);
|
||||||
|
|
||||||
HttpGet get = new HttpGet(solrRequestUrl);
|
HttpGet get = new HttpGet(solrRequestUrl);
|
||||||
HttpResponse response = new DefaultHttpClient().execute(get);
|
InputStream csvInputstream;
|
||||||
InputStream csvInputstream = response.getEntity().getContent();
|
File csvFile = new File(tempDirectory.getPath()
|
||||||
|
+ File.separatorChar
|
||||||
|
+ "temp."
|
||||||
|
+ dcStart.getYearUTC()
|
||||||
|
+ "."
|
||||||
|
+ i
|
||||||
|
+ ".csv");
|
||||||
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
|
HttpResponse response = hc.execute(get);
|
||||||
|
csvInputstream = response.getEntity().getContent();
|
||||||
//Write the csv ouput to a file !
|
//Write the csv ouput to a file !
|
||||||
File csvFile = new File(
|
|
||||||
tempDirectory.getPath() + File.separatorChar + "temp." + dcStart.getYearUTC() + "." + i + ".csv");
|
|
||||||
FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
|
FileUtils.copyInputStreamToFile(csvInputstream, csvFile);
|
||||||
|
}
|
||||||
filesToUpload.add(csvFile);
|
filesToUpload.add(csvFile);
|
||||||
|
|
||||||
//Add 10000 & start over again
|
//Add 10000 & start over again
|
||||||
@@ -1300,14 +1309,14 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a list of all the multi valued fields in the solr core
|
* Retrieves a list of all the multi valued fields in the solr core.
|
||||||
*
|
*
|
||||||
* @return all fields tagged as multivalued
|
* @return all fields tagged as multivalued
|
||||||
* @throws SolrServerException When getting the schema information from the SOLR core fails
|
* @throws SolrServerException When getting the schema information from the SOLR core fails
|
||||||
* @throws IOException When connection to the SOLR server fails
|
* @throws IOException When connection to the SOLR server fails
|
||||||
*/
|
*/
|
||||||
public Set<String> getMultivaluedFieldNames() throws SolrServerException, IOException {
|
public Set<String> getMultivaluedFieldNames() throws SolrServerException, IOException {
|
||||||
Set<String> multivaluedFields = new HashSet<String>();
|
Set<String> multivaluedFields = new HashSet<>();
|
||||||
LukeRequest lukeRequest = new LukeRequest();
|
LukeRequest lukeRequest = new LukeRequest();
|
||||||
lukeRequest.setShowSchema(true);
|
lukeRequest.setShowSchema(true);
|
||||||
LukeResponse process = lukeRequest.process(solr);
|
LukeResponse process = lukeRequest.process(solr);
|
||||||
@@ -1360,11 +1369,13 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
|||||||
solrRequestUrl = generateURL(solrRequestUrl, params);
|
solrRequestUrl = generateURL(solrRequestUrl, params);
|
||||||
|
|
||||||
HttpGet get = new HttpGet(solrRequestUrl);
|
HttpGet get = new HttpGet(solrRequestUrl);
|
||||||
HttpResponse response = new DefaultHttpClient().execute(get);
|
List<String[]> rows;
|
||||||
|
try ( CloseableHttpClient hc = HttpClientBuilder.create().build(); ) {
|
||||||
|
HttpResponse response = hc.execute(get);
|
||||||
InputStream csvOutput = response.getEntity().getContent();
|
InputStream csvOutput = response.getEntity().getContent();
|
||||||
Reader csvReader = new InputStreamReader(csvOutput);
|
Reader csvReader = new InputStreamReader(csvOutput);
|
||||||
List<String[]> rows = new CSVReader(csvReader).readAll();
|
rows = new CSVReader(csvReader).readAll();
|
||||||
|
}
|
||||||
String[][] csvParsed = rows.toArray(new String[rows.size()][]);
|
String[][] csvParsed = rows.toArray(new String[rows.size()][]);
|
||||||
String[] header = csvParsed[0];
|
String[] header = csvParsed[0];
|
||||||
//Attempt to find the bitstream id index !
|
//Attempt to find the bitstream id index !
|
||||||
|
@@ -19,10 +19,11 @@ import org.apache.http.HttpException;
|
|||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.StatusLine;
|
import org.apache.http.StatusLine;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.params.CoreConnectionPNames;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.util.XMLUtils;
|
import org.dspace.app.util.XMLUtils;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
@@ -35,7 +36,7 @@ public class CiNiiService {
|
|||||||
/**
|
/**
|
||||||
* log4j category
|
* log4j category
|
||||||
*/
|
*/
|
||||||
private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(CiNiiService.class);
|
private static final Logger log = LogManager.getLogger(CiNiiService.class);
|
||||||
|
|
||||||
protected int timeout = 1000;
|
protected int timeout = 1000;
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ public class CiNiiService {
|
|||||||
public List<Record> searchByTerm(String title, String author, int year,
|
public List<Record> searchByTerm(String title, String author, int year,
|
||||||
int maxResults, String appId)
|
int maxResults, String appId)
|
||||||
throws HttpException, IOException {
|
throws HttpException, IOException {
|
||||||
List<Record> records = new ArrayList<Record>();
|
List<Record> records = new ArrayList<>();
|
||||||
|
|
||||||
List<String> ids = getCiNiiIDs(title, author, year, maxResults, appId);
|
List<String> ids = getCiNiiIDs(title, author, year, maxResults, appId);
|
||||||
if (ids != null && ids.size() > 0) {
|
if (ids != null && ids.size() > 0) {
|
||||||
@@ -78,10 +79,13 @@ public class CiNiiService {
|
|||||||
protected Record search(String id, String appId)
|
protected Record search(String id, String appId)
|
||||||
throws IOException, HttpException {
|
throws IOException, HttpException {
|
||||||
HttpGet method = null;
|
HttpGet method = null;
|
||||||
try {
|
try ( CloseableHttpClient client = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient client = new DefaultHttpClient();
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
.setConnectTimeout(timeout)
|
||||||
|
.build();
|
||||||
method = new HttpGet("http://ci.nii.ac.jp/naid/" + id + ".rdf?appid=" + appId);
|
method = new HttpGet("http://ci.nii.ac.jp/naid/" + id + ".rdf?appid=" + appId);
|
||||||
|
method.setConfig(requestConfig);
|
||||||
|
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
HttpResponse response = client.execute(method);
|
HttpResponse response = client.execute(method);
|
||||||
StatusLine statusLine = response.getStatusLine();
|
StatusLine statusLine = response.getStatusLine();
|
||||||
@@ -129,7 +133,7 @@ public class CiNiiService {
|
|||||||
* @param title record title
|
* @param title record title
|
||||||
* @param author record author
|
* @param author record author
|
||||||
* @param year record year
|
* @param year record year
|
||||||
* @param maxResults maximun number of results returned
|
* @param maxResults maximum number of results returned
|
||||||
* @param appId registered application identifier for the API
|
* @param appId registered application identifier for the API
|
||||||
* @return matching NAIDs
|
* @return matching NAIDs
|
||||||
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
|
* @throws IOException A general class of exceptions produced by failed or interrupted I/O operations.
|
||||||
@@ -144,10 +148,8 @@ public class CiNiiService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HttpGet method = null;
|
HttpGet method = null;
|
||||||
List<String> ids = new ArrayList<String>();
|
List<String> ids = new ArrayList<>();
|
||||||
try {
|
try ( CloseableHttpClient client = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient client = new DefaultHttpClient();
|
|
||||||
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
|
||||||
StringBuilder query = new StringBuilder();
|
StringBuilder query = new StringBuilder();
|
||||||
query.append("format=rss&appid=").append(appId)
|
query.append("format=rss&appid=").append(appId)
|
||||||
.append("&count=").append(maxResults);
|
.append("&count=").append(maxResults);
|
||||||
@@ -161,7 +163,13 @@ public class CiNiiService {
|
|||||||
query.append("&year_from=").append(String.valueOf(year));
|
query.append("&year_from=").append(String.valueOf(year));
|
||||||
query.append("&year_to=").append(String.valueOf(year));
|
query.append("&year_to=").append(String.valueOf(year));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(timeout)
|
||||||
|
.build();
|
||||||
method = new HttpGet("http://ci.nii.ac.jp/opensearch/search?" + query.toString());
|
method = new HttpGet("http://ci.nii.ac.jp/opensearch/search?" + query.toString());
|
||||||
|
method.setConfig(requestConfig);
|
||||||
|
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
HttpResponse response = client.execute(method);
|
HttpResponse response = client.execute(method);
|
||||||
StatusLine statusLine = response.getStatusLine();
|
StatusLine statusLine = response.getStatusLine();
|
||||||
|
@@ -30,10 +30,11 @@ import org.apache.http.HttpResponse;
|
|||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.StatusLine;
|
import org.apache.http.StatusLine;
|
||||||
import org.apache.http.client.HttpClient;
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.utils.URIBuilder;
|
import org.apache.http.client.utils.URIBuilder;
|
||||||
import org.apache.http.impl.client.DefaultHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.params.CoreConnectionPNames;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.app.util.XMLUtils;
|
import org.dspace.app.util.XMLUtils;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
@@ -62,14 +63,13 @@ public class CrossRefService {
|
|||||||
public List<Record> search(Context context, Set<String> dois, String apiKey)
|
public List<Record> search(Context context, Set<String> dois, String apiKey)
|
||||||
throws HttpException, IOException, JDOMException,
|
throws HttpException, IOException, JDOMException,
|
||||||
ParserConfigurationException, SAXException {
|
ParserConfigurationException, SAXException {
|
||||||
List<Record> results = new ArrayList<Record>();
|
List<Record> results = new ArrayList<>();
|
||||||
if (dois != null && dois.size() > 0) {
|
if (dois != null && dois.size() > 0) {
|
||||||
for (String record : dois) {
|
for (String record : dois) {
|
||||||
try {
|
try {
|
||||||
HttpGet method = null;
|
HttpGet method = null;
|
||||||
try {
|
try {
|
||||||
HttpClient client = new DefaultHttpClient();
|
HttpClient client = HttpClientBuilder.create().build();
|
||||||
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URIBuilder uriBuilder = new URIBuilder(
|
URIBuilder uriBuilder = new URIBuilder(
|
||||||
@@ -77,7 +77,12 @@ public class CrossRefService {
|
|||||||
uriBuilder.addParameter("pid", apiKey);
|
uriBuilder.addParameter("pid", apiKey);
|
||||||
uriBuilder.addParameter("noredirect", "true");
|
uriBuilder.addParameter("noredirect", "true");
|
||||||
uriBuilder.addParameter("id", record);
|
uriBuilder.addParameter("id", record);
|
||||||
|
|
||||||
method = new HttpGet(uriBuilder.build());
|
method = new HttpGet(uriBuilder.build());
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(timeout)
|
||||||
|
.build();
|
||||||
|
method.setConfig(requestConfig);
|
||||||
} catch (URISyntaxException ex) {
|
} catch (URISyntaxException ex) {
|
||||||
throw new HttpException("Request not sent", ex);
|
throw new HttpException("Request not sent", ex);
|
||||||
}
|
}
|
||||||
@@ -140,9 +145,7 @@ public class CrossRefService {
|
|||||||
public List<Record> search(Context context, String title, String authors,
|
public List<Record> search(Context context, String title, String authors,
|
||||||
int year, int count, String apiKey) throws IOException, HttpException {
|
int year, int count, String apiKey) throws IOException, HttpException {
|
||||||
HttpGet method = null;
|
HttpGet method = null;
|
||||||
try {
|
try ( CloseableHttpClient client = HttpClientBuilder.create().build(); ) {
|
||||||
HttpClient client = new DefaultHttpClient();
|
|
||||||
client.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
|
|
||||||
|
|
||||||
URIBuilder uriBuilder = new URIBuilder("http://search.labs.crossref.org/dois");
|
URIBuilder uriBuilder = new URIBuilder("http://search.labs.crossref.org/dois");
|
||||||
|
|
||||||
@@ -159,7 +162,12 @@ public class CrossRefService {
|
|||||||
|
|
||||||
uriBuilder.addParameter("year", year != -1 ? String.valueOf(year) : "");
|
uriBuilder.addParameter("year", year != -1 ? String.valueOf(year) : "");
|
||||||
uriBuilder.addParameter("rows", count != -1 ? String.valueOf(count) : "");
|
uriBuilder.addParameter("rows", count != -1 ? String.valueOf(count) : "");
|
||||||
|
|
||||||
method = new HttpGet(uriBuilder.build());
|
method = new HttpGet(uriBuilder.build());
|
||||||
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
|
.setConnectTimeout(timeout)
|
||||||
|
.build();
|
||||||
|
method.setConfig(requestConfig);
|
||||||
|
|
||||||
// Execute the method.
|
// Execute the method.
|
||||||
HttpResponse response = client.execute(method);
|
HttpResponse response = client.execute(method);
|
||||||
@@ -177,7 +185,7 @@ public class CrossRefService {
|
|||||||
List<Map> json = gson.fromJson(
|
List<Map> json = gson.fromJson(
|
||||||
IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8),
|
IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8),
|
||||||
listType);
|
listType);
|
||||||
Set<String> dois = new HashSet<String>();
|
Set<String> dois = new HashSet<>();
|
||||||
for (Map r : json) {
|
for (Map r : json) {
|
||||||
dois.add(SubmissionLookupUtils.normalizeDOI((String) r
|
dois.add(SubmissionLookupUtils.normalizeDOI((String) r
|
||||||
.get("doi")));
|
.get("doi")));
|
||||||
|
@@ -1,3 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* The contents of this file are subject to the license and copyright
|
||||||
|
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||||
|
* tree and available online at
|
||||||
|
*
|
||||||
|
* http://www.dspace.org/license/
|
||||||
|
*/
|
||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
Reference in New Issue
Block a user