Revision 49643
Added by Alessia Bardi over 6 years ago
modules/dnet-modular-collector-service/trunk/src/test/java/eu/dnetlib/data/collector/plugins/oai/HttpConnectorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.collector.plugins.oai; |
|
2 |
|
|
3 |
import org.junit.Before; |
|
4 |
import org.junit.Ignore; |
|
5 |
import org.junit.Test; |
|
6 |
|
|
7 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector; |
|
8 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
|
9 |
|
|
10 |
public class HttpConnectorTest { |
|
11 |
|
|
12 |
private HttpConnector connector; |
|
13 |
|
|
14 |
private static final String URL = "https://researchdata.ands.org.au/registry/services/oai?verb=Identify"; |
|
15 |
|
|
16 |
@Before |
|
17 |
public void setUp() { |
|
18 |
connector = new HttpConnector(); |
|
19 |
connector.initTrustManager(); |
|
20 |
connector.setMaxNumberOfRetry(1); |
|
21 |
} |
|
22 |
|
|
23 |
@Test |
|
24 |
@Ignore |
|
25 |
public void testGetInputSource() throws CollectorServiceException { |
|
26 |
System.out.println(connector.getInputSource(URL)); |
|
27 |
} |
|
28 |
} |
modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/oai/engine/HttpConnector.java | ||
---|---|---|
1 |
package eu.dnetlib.data.collector.plugins.oai.engine; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.net.CookieHandler; |
|
6 |
import java.net.CookieManager; |
|
7 |
import java.net.CookiePolicy; |
|
8 |
import java.net.HttpURLConnection; |
|
9 |
import java.net.URL; |
|
10 |
import java.security.GeneralSecurityException; |
|
11 |
import java.security.KeyManagementException; |
|
12 |
import java.security.NoSuchAlgorithmException; |
|
13 |
import java.security.cert.CertificateException; |
|
14 |
import java.security.cert.X509Certificate; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
import javax.net.ssl.HttpsURLConnection; |
|
19 |
import javax.net.ssl.SSLContext; |
|
20 |
import javax.net.ssl.TrustManager; |
|
21 |
import javax.net.ssl.X509TrustManager; |
|
22 |
|
|
23 |
import org.apache.commons.io.IOUtils; |
|
24 |
import org.apache.commons.lang.math.NumberUtils; |
|
25 |
import org.apache.commons.logging.Log; |
|
26 |
import org.apache.commons.logging.LogFactory; |
|
27 |
|
|
28 |
import eu.dnetlib.data.collector.plugin.CollectorPluginErrorLogList; |
|
29 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author jochen, michele, andrea |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class HttpConnector { |
|
36 |
|
|
37 |
private static final Log log = LogFactory.getLog(HttpConnector.class); |
|
38 |
|
|
39 |
private int maxNumberOfRetry = 6; |
|
40 |
private int defaultDelay = 120; // seconds |
|
41 |
private int readTimeOut = 120; // seconds |
|
42 |
private String userAgent = "Mozilla/5.0 (compatible; OAI; +http://www.openaire.eu)"; |
|
43 |
|
|
44 |
public HttpConnector(){ |
|
45 |
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* @param requestUrl |
|
50 |
* @return the content of the downloaded resource |
|
51 |
* @throws CollectorServiceException |
|
52 |
*/ |
|
53 |
public String getInputSource(final String requestUrl) throws CollectorServiceException { |
|
54 |
return attemptDownload(requestUrl, 1, new CollectorPluginErrorLogList()); |
|
55 |
} |
|
56 |
|
|
57 |
private String attemptDownload(final String requestUrl, final int retryNumber, final CollectorPluginErrorLogList errorList) |
|
58 |
throws CollectorServiceException { |
|
59 |
|
|
60 |
if (retryNumber > maxNumberOfRetry) { throw new CollectorServiceException("Max number of retries exceeded. Cause: \n " + errorList); } |
|
61 |
|
|
62 |
log.debug("Downloading " + requestUrl + " - try: " + retryNumber); |
|
63 |
try { |
|
64 |
InputStream input = null; |
|
65 |
|
|
66 |
try { |
|
67 |
final HttpURLConnection urlConn = (HttpURLConnection) new URL(requestUrl).openConnection(); |
|
68 |
urlConn.setInstanceFollowRedirects(false); |
|
69 |
urlConn.setReadTimeout(readTimeOut * 1000); |
|
70 |
urlConn.addRequestProperty("User-Agent", userAgent); |
|
71 |
|
|
72 |
if (log.isDebugEnabled()) { |
|
73 |
logHeaderFields(urlConn); |
|
74 |
} |
|
75 |
|
|
76 |
int retryAfter = obtainRetryAfter(urlConn.getHeaderFields()); |
|
77 |
if (retryAfter > 0) { |
|
78 |
log.warn("waiting and repeating request after " + retryAfter + " sec."); |
|
79 |
Thread.sleep(retryAfter * 1000); |
|
80 |
errorList.add("503 Service Unavailable"); |
|
81 |
return attemptDownload(requestUrl, retryNumber + 1, errorList); |
|
82 |
} else if ((urlConn.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM) || (urlConn.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP)) { |
|
83 |
final String newUrl = obtainNewLocation(urlConn.getHeaderFields()); |
|
84 |
log.info("The requested url has been moved to " + newUrl); |
|
85 |
errorList.add(String.format("%s %s. Moved to: %s", urlConn.getResponseCode(), urlConn.getResponseMessage(), newUrl)); |
|
86 |
return attemptDownload(newUrl, retryNumber + 1, errorList); |
|
87 |
} else if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) { |
|
88 |
log.error(String.format("HTTP error: %s %s", urlConn.getResponseCode(), urlConn.getResponseMessage())); |
|
89 |
Thread.sleep(defaultDelay * 1000); |
|
90 |
errorList.add(String.format("%s %s", urlConn.getResponseCode(), urlConn.getResponseMessage())); |
|
91 |
return attemptDownload(requestUrl, retryNumber + 1, errorList); |
|
92 |
} else { |
|
93 |
input = urlConn.getInputStream(); |
|
94 |
return IOUtils.toString(input); |
|
95 |
} |
|
96 |
} catch (IOException e) { |
|
97 |
log.error("error while retrieving from http-connection occured: " + e, e); |
|
98 |
Thread.sleep(defaultDelay * 1000); |
|
99 |
errorList.add(e.getMessage()); |
|
100 |
return attemptDownload(requestUrl, retryNumber + 1, errorList); |
|
101 |
} finally { |
|
102 |
IOUtils.closeQuietly(input); |
|
103 |
} |
|
104 |
} catch (InterruptedException e) { |
|
105 |
throw new CollectorServiceException(e); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
private void logHeaderFields(final HttpURLConnection urlConn) throws IOException { |
|
110 |
log.debug("StatusCode: " + urlConn.getResponseMessage()); |
|
111 |
|
|
112 |
for (Map.Entry<String, List<String>> e : urlConn.getHeaderFields().entrySet()) { |
|
113 |
if (e.getKey() != null) { |
|
114 |
for (String v : e.getValue()) { |
|
115 |
log.debug(" key: " + e.getKey() + " - value: " + v); |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
private int obtainRetryAfter(final Map<String, List<String>> headerMap) { |
|
122 |
for (String key : headerMap.keySet()) { |
|
123 |
if ((key != null) && key.toLowerCase().equals("retry-after") && (headerMap.get(key).size() > 0) && NumberUtils.isNumber(headerMap.get(key).get(0))) { return Integer |
|
124 |
.parseInt(headerMap.get(key).get(0)) + 10; } |
|
125 |
} |
|
126 |
return -1; |
|
127 |
} |
|
128 |
|
|
129 |
private String obtainNewLocation(final Map<String, List<String>> headerMap) throws CollectorServiceException { |
|
130 |
for (String key : headerMap.keySet()) { |
|
131 |
if ((key != null) && key.toLowerCase().equals("location") && (headerMap.get(key).size() > 0)) { return headerMap.get(key).get(0); } |
|
132 |
} |
|
133 |
throw new CollectorServiceException("The requested url has been MOVED, but 'location' param is MISSING"); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* register for https scheme; this is a workaround and not intended for the use in trusted environments |
|
138 |
* |
|
139 |
* @throws NoSuchAlgorithmException |
|
140 |
* @throws KeyManagementException |
|
141 |
*/ |
|
142 |
public void initTrustManager() { |
|
143 |
final X509TrustManager tm = new X509TrustManager() { |
|
144 |
|
|
145 |
@Override |
|
146 |
public void checkClientTrusted(final X509Certificate[] xcs, final String string) throws CertificateException {} |
|
147 |
|
|
148 |
@Override |
|
149 |
public void checkServerTrusted(final X509Certificate[] xcs, final String string) throws CertificateException {} |
|
150 |
|
|
151 |
@Override |
|
152 |
public X509Certificate[] getAcceptedIssuers() { |
|
153 |
return null; |
|
154 |
} |
|
155 |
}; |
|
156 |
try { |
|
157 |
final SSLContext ctx = SSLContext.getInstance("TLS"); |
|
158 |
ctx.init(null, new TrustManager[] { tm }, null); |
|
159 |
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); |
|
160 |
} catch (GeneralSecurityException e) { |
|
161 |
log.fatal(e); |
|
162 |
throw new IllegalStateException(e); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
public int getMaxNumberOfRetry() { |
|
167 |
return maxNumberOfRetry; |
|
168 |
} |
|
169 |
|
|
170 |
public void setMaxNumberOfRetry(final int maxNumberOfRetry) { |
|
171 |
this.maxNumberOfRetry = maxNumberOfRetry; |
|
172 |
} |
|
173 |
|
|
174 |
public int getDefaultDelay() { |
|
175 |
return defaultDelay; |
|
176 |
} |
|
177 |
|
|
178 |
public void setDefaultDelay(final int defaultDelay) { |
|
179 |
this.defaultDelay = defaultDelay; |
|
180 |
} |
|
181 |
|
|
182 |
public int getReadTimeOut() { |
|
183 |
return readTimeOut; |
|
184 |
} |
|
185 |
|
|
186 |
public void setReadTimeOut(final int readTimeOut) { |
|
187 |
this.readTimeOut = readTimeOut; |
|
188 |
} |
|
189 |
|
|
190 |
} |
modules/dnet-modular-collector-service/trunk/src/test/java/eu/dnetlib/data/collector/plugins/oai/OaiIteratorTest.java | ||
---|---|---|
4 | 4 |
import org.junit.Ignore; |
5 | 5 |
import org.junit.Test; |
6 | 6 |
|
7 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
7 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
8 | 8 |
|
9 | 9 |
public class OaiIteratorTest { |
10 | 10 |
|
modules/dnet-modular-collector-service/trunk/src/test/java/eu/dnetlib/data/collector/plugins/HttpConnectorTest.java | ||
---|---|---|
1 |
package eu.dnetlib.data.collector.plugins; |
|
2 |
|
|
3 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
|
4 |
import org.junit.Before; |
|
5 |
import org.junit.Ignore; |
|
6 |
import org.junit.Test; |
|
7 |
|
|
8 |
public class HttpConnectorTest { |
|
9 |
|
|
10 |
private HttpConnector connector; |
|
11 |
|
|
12 |
private static final String URL = "https://researchdata.ands.org.au/registry/services/oai?verb=Identify"; |
|
13 |
|
|
14 |
@Before |
|
15 |
public void setUp() { |
|
16 |
connector = new HttpConnector(); |
|
17 |
connector.initTrustManager(); |
|
18 |
connector.setMaxNumberOfRetry(1); |
|
19 |
} |
|
20 |
|
|
21 |
@Test |
|
22 |
@Ignore |
|
23 |
public void testGetInputSource() throws CollectorServiceException { |
|
24 |
System.out.println(connector.getInputSource(URL)); |
|
25 |
} |
|
26 |
} |
modules/dnet-modular-collector-service/trunk/src/test/resources/eu/dnetlib/data/collector/plugins/oaisets/applicationContext-OaiSetsCollectorPluginTest.xml | ||
---|---|---|
13 | 13 |
http://dnetlib.eu/springbeans/template http://dnetlib.eu/springbeans/template.xsd"> |
14 | 14 |
|
15 | 15 |
<bean id="oaiHttpConnector" |
16 |
class="eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector"
|
|
16 |
class="eu.dnetlib.data.collector.plugins.HttpConnector" |
|
17 | 17 |
init-method="initTrustManager" /> |
18 | 18 |
|
19 | 19 |
<bean id="oaiSetsIteratorFactory" |
modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/oaisets/OaiSetsIterator.java | ||
---|---|---|
16 | 16 |
|
17 | 17 |
import com.google.common.collect.Sets; |
18 | 18 |
|
19 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
19 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
20 | 20 |
import eu.dnetlib.data.collector.plugins.oai.engine.XmlCleaner; |
21 | 21 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
22 | 22 |
|
modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/oaisets/OaiSetsIteratorFactory.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.springframework.beans.factory.annotation.Required; |
6 | 6 |
|
7 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
7 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
8 | 8 |
|
9 | 9 |
public class OaiSetsIteratorFactory { |
10 | 10 |
|
modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/oai/OaiIterator.java | ||
---|---|---|
14 | 14 |
import org.dom4j.Node; |
15 | 15 |
import org.dom4j.io.SAXReader; |
16 | 16 |
|
17 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
17 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
18 | 18 |
import eu.dnetlib.data.collector.plugins.oai.engine.XmlCleaner; |
19 | 19 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
20 | 20 |
|
modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/oai/OaiIteratorFactory.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.springframework.beans.factory.annotation.Required; |
6 | 6 |
|
7 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
7 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
8 | 8 |
|
9 | 9 |
public class OaiIteratorFactory { |
10 | 10 |
|
modules/dnet-modular-collector-service/trunk/src/main/java/eu/dnetlib/data/collector/plugins/HttpConnector.java | ||
---|---|---|
1 |
package eu.dnetlib.data.collector.plugins; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.net.CookieHandler; |
|
6 |
import java.net.CookieManager; |
|
7 |
import java.net.CookiePolicy; |
|
8 |
import java.net.HttpURLConnection; |
|
9 |
import java.net.URL; |
|
10 |
import java.security.GeneralSecurityException; |
|
11 |
import java.security.KeyManagementException; |
|
12 |
import java.security.NoSuchAlgorithmException; |
|
13 |
import java.security.cert.CertificateException; |
|
14 |
import java.security.cert.X509Certificate; |
|
15 |
import java.util.List; |
|
16 |
import java.util.Map; |
|
17 |
|
|
18 |
import javax.net.ssl.HttpsURLConnection; |
|
19 |
import javax.net.ssl.SSLContext; |
|
20 |
import javax.net.ssl.TrustManager; |
|
21 |
import javax.net.ssl.X509TrustManager; |
|
22 |
|
|
23 |
import org.apache.commons.io.IOUtils; |
|
24 |
import org.apache.commons.lang.math.NumberUtils; |
|
25 |
import org.apache.commons.logging.Log; |
|
26 |
import org.apache.commons.logging.LogFactory; |
|
27 |
|
|
28 |
import eu.dnetlib.data.collector.plugin.CollectorPluginErrorLogList; |
|
29 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author jochen, michele, andrea |
|
33 |
* |
|
34 |
*/ |
|
35 |
public class HttpConnector { |
|
36 |
|
|
37 |
private static final Log log = LogFactory.getLog(HttpConnector.class); |
|
38 |
|
|
39 |
private int maxNumberOfRetry = 6; |
|
40 |
private int defaultDelay = 120; // seconds |
|
41 |
private int readTimeOut = 120; // seconds |
|
42 |
private String userAgent = "Mozilla/5.0 (compatible; OAI; +http://www.openaire.eu)"; |
|
43 |
|
|
44 |
public HttpConnector(){ |
|
45 |
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* @param requestUrl |
|
50 |
* @return the content of the downloaded resource |
|
51 |
* @throws CollectorServiceException |
|
52 |
*/ |
|
53 |
public String getInputSource(final String requestUrl) throws CollectorServiceException { |
|
54 |
return attemptDownload(requestUrl, 1, new CollectorPluginErrorLogList()); |
|
55 |
} |
|
56 |
|
|
57 |
private String attemptDownload(final String requestUrl, final int retryNumber, final CollectorPluginErrorLogList errorList) |
|
58 |
throws CollectorServiceException { |
|
59 |
|
|
60 |
if (retryNumber > maxNumberOfRetry) { throw new CollectorServiceException("Max number of retries exceeded. Cause: \n " + errorList); } |
|
61 |
|
|
62 |
log.debug("Downloading " + requestUrl + " - try: " + retryNumber); |
|
63 |
try { |
|
64 |
InputStream input = null; |
|
65 |
|
|
66 |
try { |
|
67 |
final HttpURLConnection urlConn = (HttpURLConnection) new URL(requestUrl).openConnection(); |
|
68 |
urlConn.setInstanceFollowRedirects(false); |
|
69 |
urlConn.setReadTimeout(readTimeOut * 1000); |
|
70 |
urlConn.addRequestProperty("User-Agent", userAgent); |
|
71 |
|
|
72 |
if (log.isDebugEnabled()) { |
|
73 |
logHeaderFields(urlConn); |
|
74 |
} |
|
75 |
|
|
76 |
int retryAfter = obtainRetryAfter(urlConn.getHeaderFields()); |
|
77 |
if (retryAfter > 0) { |
|
78 |
log.warn("waiting and repeating request after " + retryAfter + " sec."); |
|
79 |
Thread.sleep(retryAfter * 1000); |
|
80 |
errorList.add("503 Service Unavailable"); |
|
81 |
return attemptDownload(requestUrl, retryNumber + 1, errorList); |
|
82 |
} else if ((urlConn.getResponseCode() == HttpURLConnection.HTTP_MOVED_PERM) || (urlConn.getResponseCode() == HttpURLConnection.HTTP_MOVED_TEMP)) { |
|
83 |
final String newUrl = obtainNewLocation(urlConn.getHeaderFields()); |
|
84 |
log.info("The requested url has been moved to " + newUrl); |
|
85 |
errorList.add(String.format("%s %s. Moved to: %s", urlConn.getResponseCode(), urlConn.getResponseMessage(), newUrl)); |
|
86 |
return attemptDownload(newUrl, retryNumber + 1, errorList); |
|
87 |
} else if (urlConn.getResponseCode() != HttpURLConnection.HTTP_OK) { |
|
88 |
log.error(String.format("HTTP error: %s %s", urlConn.getResponseCode(), urlConn.getResponseMessage())); |
|
89 |
Thread.sleep(defaultDelay * 1000); |
|
90 |
errorList.add(String.format("%s %s", urlConn.getResponseCode(), urlConn.getResponseMessage())); |
|
91 |
return attemptDownload(requestUrl, retryNumber + 1, errorList); |
|
92 |
} else { |
|
93 |
input = urlConn.getInputStream(); |
|
94 |
return IOUtils.toString(input); |
|
95 |
} |
|
96 |
} catch (IOException e) { |
|
97 |
log.error("error while retrieving from http-connection occured: " + e, e); |
|
98 |
Thread.sleep(defaultDelay * 1000); |
|
99 |
errorList.add(e.getMessage()); |
|
100 |
return attemptDownload(requestUrl, retryNumber + 1, errorList); |
|
101 |
} finally { |
|
102 |
IOUtils.closeQuietly(input); |
|
103 |
} |
|
104 |
} catch (InterruptedException e) { |
|
105 |
throw new CollectorServiceException(e); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
private void logHeaderFields(final HttpURLConnection urlConn) throws IOException { |
|
110 |
log.debug("StatusCode: " + urlConn.getResponseMessage()); |
|
111 |
|
|
112 |
for (Map.Entry<String, List<String>> e : urlConn.getHeaderFields().entrySet()) { |
|
113 |
if (e.getKey() != null) { |
|
114 |
for (String v : e.getValue()) { |
|
115 |
log.debug(" key: " + e.getKey() + " - value: " + v); |
|
116 |
} |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
private int obtainRetryAfter(final Map<String, List<String>> headerMap) { |
|
122 |
for (String key : headerMap.keySet()) { |
|
123 |
if ((key != null) && key.toLowerCase().equals("retry-after") && (headerMap.get(key).size() > 0) && NumberUtils.isNumber(headerMap.get(key).get(0))) { return Integer |
|
124 |
.parseInt(headerMap.get(key).get(0)) + 10; } |
|
125 |
} |
|
126 |
return -1; |
|
127 |
} |
|
128 |
|
|
129 |
private String obtainNewLocation(final Map<String, List<String>> headerMap) throws CollectorServiceException { |
|
130 |
for (String key : headerMap.keySet()) { |
|
131 |
if ((key != null) && key.toLowerCase().equals("location") && (headerMap.get(key).size() > 0)) { return headerMap.get(key).get(0); } |
|
132 |
} |
|
133 |
throw new CollectorServiceException("The requested url has been MOVED, but 'location' param is MISSING"); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* register for https scheme; this is a workaround and not intended for the use in trusted environments |
|
138 |
* |
|
139 |
* @throws NoSuchAlgorithmException |
|
140 |
* @throws KeyManagementException |
|
141 |
*/ |
|
142 |
public void initTrustManager() { |
|
143 |
final X509TrustManager tm = new X509TrustManager() { |
|
144 |
|
|
145 |
@Override |
|
146 |
public void checkClientTrusted(final X509Certificate[] xcs, final String string) throws CertificateException {} |
|
147 |
|
|
148 |
@Override |
|
149 |
public void checkServerTrusted(final X509Certificate[] xcs, final String string) throws CertificateException {} |
|
150 |
|
|
151 |
@Override |
|
152 |
public X509Certificate[] getAcceptedIssuers() { |
|
153 |
return null; |
|
154 |
} |
|
155 |
}; |
|
156 |
try { |
|
157 |
final SSLContext ctx = SSLContext.getInstance("TLS"); |
|
158 |
ctx.init(null, new TrustManager[] { tm }, null); |
|
159 |
HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory()); |
|
160 |
} catch (GeneralSecurityException e) { |
|
161 |
log.fatal(e); |
|
162 |
throw new IllegalStateException(e); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
public int getMaxNumberOfRetry() { |
|
167 |
return maxNumberOfRetry; |
|
168 |
} |
|
169 |
|
|
170 |
public void setMaxNumberOfRetry(final int maxNumberOfRetry) { |
|
171 |
this.maxNumberOfRetry = maxNumberOfRetry; |
|
172 |
} |
|
173 |
|
|
174 |
public int getDefaultDelay() { |
|
175 |
return defaultDelay; |
|
176 |
} |
|
177 |
|
|
178 |
public void setDefaultDelay(final int defaultDelay) { |
|
179 |
this.defaultDelay = defaultDelay; |
|
180 |
} |
|
181 |
|
|
182 |
public int getReadTimeOut() { |
|
183 |
return readTimeOut; |
|
184 |
} |
|
185 |
|
|
186 |
public void setReadTimeOut(final int readTimeOut) { |
|
187 |
this.readTimeOut = readTimeOut; |
|
188 |
} |
|
189 |
|
|
190 |
} |
modules/dnet-modular-collector-service/trunk/src/main/resources/eu/dnetlib/data/collector/applicationContext-dnet-modular-collector-utils.xml | ||
---|---|---|
8 | 8 |
|
9 | 9 |
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd"> |
10 | 10 |
|
11 |
<bean id="oaiHttpConnector" class="eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector"
|
|
12 |
init-method="initTrustManager"
|
|
13 |
p:defaultDelay="${collector.oai.http.defaultDelay}"
|
|
14 |
p:readTimeOut="${collector.oai.http.readTimeOut}"
|
|
15 |
p:maxNumberOfRetry="${collector.oai.http.maxNumberOfRetry}" />
|
|
11 |
<bean id="httpConnector" class="eu.dnetlib.data.collector.plugins.HttpConnector"
|
|
12 |
init-method="initTrustManager"
|
|
13 |
p:defaultDelay="${collector.oai.http.defaultDelay}"
|
|
14 |
p:readTimeOut="${collector.oai.http.readTimeOut}"
|
|
15 |
p:maxNumberOfRetry="${collector.oai.http.maxNumberOfRetry}" />
|
|
16 | 16 |
|
17 | 17 |
<bean id="oaiIteratorFactory" class="eu.dnetlib.data.collector.plugins.oai.OaiIteratorFactory" |
18 |
p:httpConnector-ref="oaiHttpConnector" />
|
|
18 |
p:httpConnector-ref="httpConnector" />
|
|
19 | 19 |
|
20 | 20 |
<bean id="oaiSetsIteratorFactory" class="eu.dnetlib.data.collector.plugins.oaisets.OaiSetsIteratorFactory" |
21 |
p:httpConnector-ref="oaiHttpConnector" />
|
|
21 |
p:httpConnector-ref="httpConnector" />
|
|
22 | 22 |
|
23 | 23 |
<bean id="ftpIteratorFactory" class="eu.dnetlib.data.collector.plugins.ftp.FtpIteratorFactory"/> |
24 | 24 |
|
modules/dnet-collector-plugins/trunk/src/test/java/eu/dnetlib/data/collector/plugins/datasources/Re3DataRepositoriesIteratorTest.java | ||
---|---|---|
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.util.Iterator; |
7 | 7 |
|
8 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
8 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
9 | 9 |
import org.apache.commons.io.FileUtils; |
10 | 10 |
import org.apache.commons.io.IOUtils; |
11 | 11 |
import org.apache.commons.logging.Log; |
modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/datasources/Re3DataRepositoriesIterator.java | ||
---|---|---|
8 | 8 |
import javax.xml.stream.XMLStreamException; |
9 | 9 |
import javax.xml.stream.XMLStreamReader; |
10 | 10 |
|
11 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
11 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
12 | 12 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
13 | 13 |
import eu.dnetlib.data.collector.rmi.CollectorServiceRuntimeException; |
14 | 14 |
import org.apache.commons.logging.Log; |
modules/dnet-collector-plugins/trunk/src/main/java/eu/dnetlib/data/collector/plugins/datasources/Re3DataCollectorPlugin.java | ||
---|---|---|
3 | 3 |
import java.io.IOException; |
4 | 4 |
|
5 | 5 |
import eu.dnetlib.data.collector.plugin.AbstractCollectorPlugin; |
6 |
import eu.dnetlib.data.collector.plugins.oai.engine.HttpConnector;
|
|
6 |
import eu.dnetlib.data.collector.plugins.HttpConnector; |
|
7 | 7 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
8 | 8 |
import eu.dnetlib.data.collector.rmi.InterfaceDescriptor; |
9 | 9 |
import org.apache.commons.io.IOUtils; |
Also available in: Unified diff
Moved HttpConnector in common package