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