mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 06:23:10 +00:00
[DURACOM-109] Continued configuring proxy for other classes
This commit is contained in:
@@ -93,7 +93,7 @@ public class DSpaceHttpClientFactory {
|
||||
public CloseableHttpClient buildWithoutAutomaticRetries(int maxConnTotal) {
|
||||
HttpClientBuilder clientBuilder = HttpClientBuilder.create()
|
||||
.disableAutomaticRetries()
|
||||
.setMaxConnTotal(5);
|
||||
.setMaxConnTotal(maxConnTotal);
|
||||
return build(clientBuilder, true);
|
||||
}
|
||||
|
||||
|
@@ -11,8 +11,6 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -21,7 +19,11 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
@@ -1312,11 +1314,11 @@ public abstract class AbstractMETSIngester extends AbstractPackageIngester {
|
||||
// we will assume all external files are available via URLs.
|
||||
try {
|
||||
// attempt to open a connection to given URL
|
||||
URL fileURL = new URL(path);
|
||||
URLConnection connection = fileURL.openConnection();
|
||||
CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().build();
|
||||
CloseableHttpResponse httpResponse = httpClient.execute(new HttpGet(path));
|
||||
|
||||
// open stream to access file contents
|
||||
return connection.getInputStream();
|
||||
return httpResponse.getEntity().getContent();
|
||||
} catch (IOException io) {
|
||||
log
|
||||
.error("Unable to retrieve external file from URL '"
|
||||
|
@@ -9,11 +9,15 @@ package org.dspace.ctask.general;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.MetadataValue;
|
||||
@@ -136,15 +140,15 @@ public class BasicLinkChecker extends AbstractCurationTask {
|
||||
*/
|
||||
protected int getResponseStatus(String url, int redirects) {
|
||||
try {
|
||||
URL theURL = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection) theURL.openConnection();
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
int statusCode = connection.getResponseCode();
|
||||
RequestConfig config = RequestConfig.custom().setRedirectsEnabled(true).build();
|
||||
CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().buildWithRequestConfig(config);
|
||||
CloseableHttpResponse httpResponse = httpClient.execute(new HttpGet(url));
|
||||
int statusCode = httpResponse.getStatusLine().getStatusCode();
|
||||
int maxRedirect = configurationService.getIntProperty("curate.checklinks.max-redirect", 0);
|
||||
if ((statusCode == HttpURLConnection.HTTP_MOVED_TEMP || statusCode == HttpURLConnection.HTTP_MOVED_PERM ||
|
||||
statusCode == HttpURLConnection.HTTP_SEE_OTHER)) {
|
||||
connection.disconnect();
|
||||
String newUrl = connection.getHeaderField("Location");
|
||||
httpClient.close();
|
||||
String newUrl = httpResponse.getFirstHeader("Location").getValue();
|
||||
if (newUrl != null && (maxRedirect >= redirects || maxRedirect == -1)) {
|
||||
redirects++;
|
||||
return getResponseStatus(newUrl, redirects);
|
||||
|
@@ -18,9 +18,9 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
import org.dspace.google.GoogleAnalyticsEvent;
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class GoogleAnalyticsClientImpl implements GoogleAnalyticsClient {
|
||||
public GoogleAnalyticsClientImpl(String keyPrefix, GoogleAnalyticsClientRequestBuilder requestBuilder) {
|
||||
this.keyPrefix = keyPrefix;
|
||||
this.requestBuilder = requestBuilder;
|
||||
this.httpclient = HttpClients.createDefault();
|
||||
this.httpclient = DSpaceHttpClientFactory.getInstance().build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -12,12 +12,14 @@ import static org.dspace.iiif.canvasdimension.Util.checkDimensions;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.iiif.util.IIIFSharedUtils;
|
||||
|
||||
@@ -35,14 +37,11 @@ public class IIIFApiQueryServiceImpl implements IIIFApiQueryService {
|
||||
public int[] getImageDimensions(Bitstream bitstream) {
|
||||
int[] arr = new int[2];
|
||||
String path = IIIFSharedUtils.getInfoJsonPath(bitstream);
|
||||
URL url;
|
||||
BufferedReader in = null;
|
||||
try {
|
||||
url = new URL(path);
|
||||
HttpURLConnection con = (HttpURLConnection) url.openConnection();
|
||||
con.setRequestMethod("GET");
|
||||
in = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream()));
|
||||
CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().build();
|
||||
CloseableHttpResponse httpResponse = httpClient.execute(new HttpGet(path));
|
||||
in = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
|
||||
String inputLine;
|
||||
StringBuilder response = new StringBuilder();
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
|
@@ -17,19 +17,16 @@ import java.util.Optional;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
import org.apache.http.client.config.RequestConfig.Builder;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
import org.dspace.services.ConfigurationService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -53,16 +50,12 @@ public class LiveImportClientImpl implements LiveImportClient {
|
||||
@Override
|
||||
public String executeHttpGetRequest(int timeout, String URL, Map<String, Map<String, String>> params) {
|
||||
HttpGet method = null;
|
||||
RequestConfig config = RequestConfig.custom().setConnectionRequestTimeout(timeout).build();
|
||||
try (CloseableHttpClient httpClient = Optional.ofNullable(this.httpClient)
|
||||
.orElseGet(HttpClients::createDefault)) {
|
||||
|
||||
Builder requestConfigBuilder = RequestConfig.custom();
|
||||
requestConfigBuilder.setConnectionRequestTimeout(timeout);
|
||||
RequestConfig defaultRequestConfig = requestConfigBuilder.build();
|
||||
|
||||
.orElse(DSpaceHttpClientFactory.getInstance().buildWithRequestConfig(config))) {
|
||||
String uri = buildUrl(URL, params.get(URI_PARAMETERS));
|
||||
method = new HttpGet(uri);
|
||||
method.setConfig(defaultRequestConfig);
|
||||
method.setConfig(config);
|
||||
|
||||
Map<String, String> headerParams = params.get(HEADER_PARAMETERS);
|
||||
if (MapUtils.isNotEmpty(headerParams)) {
|
||||
@@ -71,7 +64,6 @@ public class LiveImportClientImpl implements LiveImportClient {
|
||||
}
|
||||
}
|
||||
|
||||
configureProxy(method, defaultRequestConfig);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Performing GET request to \"" + uri + "\"...");
|
||||
}
|
||||
@@ -95,21 +87,17 @@ public class LiveImportClientImpl implements LiveImportClient {
|
||||
@Override
|
||||
public String executeHttpPostRequest(String URL, Map<String, Map<String, String>> params, String entry) {
|
||||
HttpPost method = null;
|
||||
RequestConfig config = RequestConfig.custom().build();
|
||||
try (CloseableHttpClient httpClient = Optional.ofNullable(this.httpClient)
|
||||
.orElseGet(HttpClients::createDefault)) {
|
||||
|
||||
Builder requestConfigBuilder = RequestConfig.custom();
|
||||
RequestConfig defaultRequestConfig = requestConfigBuilder.build();
|
||||
.orElse(DSpaceHttpClientFactory.getInstance().buildWithRequestConfig(config))) {
|
||||
|
||||
String uri = buildUrl(URL, params.get(URI_PARAMETERS));
|
||||
method = new HttpPost(uri);
|
||||
method.setConfig(defaultRequestConfig);
|
||||
if (StringUtils.isNotBlank(entry)) {
|
||||
method.setEntity(new StringEntity(entry));
|
||||
}
|
||||
setHeaderParams(method, params);
|
||||
|
||||
configureProxy(method, defaultRequestConfig);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Performing POST request to \"" + uri + "\"..." );
|
||||
}
|
||||
@@ -129,17 +117,6 @@ public class LiveImportClientImpl implements LiveImportClient {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
private void configureProxy(HttpRequestBase method, RequestConfig defaultRequestConfig) {
|
||||
String proxyHost = configurationService.getProperty("http.proxy.host");
|
||||
String proxyPort = configurationService.getProperty("http.proxy.port");
|
||||
if (StringUtils.isNotBlank(proxyHost) && StringUtils.isNotBlank(proxyPort)) {
|
||||
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
|
||||
.setProxy(new HttpHost(proxyHost, Integer.parseInt(proxyPort), "http"))
|
||||
.build();
|
||||
method.setConfig(requestConfig);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to set the header parameters to the HTTP Post method
|
||||
*
|
||||
|
@@ -10,9 +10,6 @@ package org.dspace.license;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.StringReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -328,23 +325,14 @@ public class CCLicenseConnectorServiceImpl implements CCLicenseConnectorService,
|
||||
@Override
|
||||
public Document retrieveLicenseRDFDoc(String licenseURI) throws IOException {
|
||||
String ccLicenseUrl = configurationService.getProperty("cc.api.rooturl");
|
||||
|
||||
String issueUrl = ccLicenseUrl + "/details?license-uri=" + licenseURI;
|
||||
|
||||
URL request_url;
|
||||
try {
|
||||
request_url = new URL(issueUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
return null;
|
||||
}
|
||||
URLConnection connection = request_url.openConnection();
|
||||
connection.setDoOutput(true);
|
||||
try {
|
||||
CloseableHttpClient httpClient = DSpaceHttpClientFactory.getInstance().build();
|
||||
CloseableHttpResponse httpResponse = httpClient.execute(new HttpPost(issueUrl));
|
||||
// parsing document from input stream
|
||||
InputStream stream = connection.getInputStream();
|
||||
InputStream stream = httpResponse.getEntity().getContent();
|
||||
Document doc = parser.build(stream);
|
||||
return doc;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error while retrieving the license document for URI: " + licenseURI, e);
|
||||
}
|
||||
|
@@ -22,9 +22,9 @@ import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.app.client.DSpaceHttpClientFactory;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.QAEvent;
|
||||
import org.dspace.content.service.ItemService;
|
||||
@@ -123,7 +123,7 @@ public class QAEventActionServiceImpl implements QAEventActionService {
|
||||
node.put("eventId", eventId);
|
||||
node.put("status", status);
|
||||
StringEntity requestEntity = new StringEntity(node.toString(), ContentType.APPLICATION_JSON);
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
CloseableHttpClient httpclient = DSpaceHttpClientFactory.getInstance().buildWithoutProxy();
|
||||
HttpPost postMethod = new HttpPost(ackwnoledgeCallback);
|
||||
postMethod.setEntity(requestEntity);
|
||||
try {
|
||||
|
@@ -1223,7 +1223,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
+ "."
|
||||
+ i
|
||||
+ ".csv");
|
||||
try (CloseableHttpClient hc = DSpaceHttpClientFactory.getInstance().build()) {
|
||||
try (CloseableHttpClient hc = DSpaceHttpClientFactory.getInstance().buildWithoutProxy()) {
|
||||
HttpResponse response = hc.execute(get);
|
||||
csvInputstream = response.getEntity().getContent();
|
||||
//Write the csv output to a file !
|
||||
@@ -1365,7 +1365,7 @@ public class SolrLoggerServiceImpl implements SolrLoggerService, InitializingBea
|
||||
|
||||
HttpGet get = new HttpGet(solrRequestUrl);
|
||||
List<String[]> rows;
|
||||
try (CloseableHttpClient hc = DSpaceHttpClientFactory.getInstance().build()) {
|
||||
try (CloseableHttpClient hc = DSpaceHttpClientFactory.getInstance().buildWithoutProxy()) {
|
||||
HttpResponse response = hc.execute(get);
|
||||
InputStream csvOutput = response.getEntity().getContent();
|
||||
Reader csvReader = new InputStreamReader(csvOutput);
|
||||
|
@@ -411,6 +411,8 @@ http.proxy.host =
|
||||
# port number of proxy server
|
||||
http.proxy.port =
|
||||
|
||||
http.proxy.hosts-to-ignore = 127.0.0.1, localhost
|
||||
|
||||
# If enabled, the logging and the Solr statistics system will look for an X-Forwarded-For header.
|
||||
# If it finds it, it will use this for the user IP address.
|
||||
# NOTE: This is required to be enabled if you plan to use the Angular UI, as the server-side rendering provided in
|
||||
|
Reference in New Issue
Block a user