1
|
package eu.dnetlib.msro.workers.aggregation.collect.plugins.split;
|
2
|
|
3
|
import java.io.BufferedInputStream;
|
4
|
import java.io.IOException;
|
5
|
|
6
|
import org.apache.http.HttpStatus;
|
7
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
8
|
import org.apache.http.client.methods.HttpGet;
|
9
|
import org.apache.http.impl.client.CloseableHttpClient;
|
10
|
import org.apache.http.impl.client.HttpClients;
|
11
|
import org.springframework.stereotype.Component;
|
12
|
|
13
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorParam;
|
14
|
import eu.dnetlib.msro.workers.aggregation.collect.plugins.DnetCollectorPlugin;
|
15
|
import eu.dnetlib.msro.workflows.nodes.collect.CollectException;
|
16
|
|
17
|
@Component
|
18
|
@DnetCollectorPlugin(value = "http", parameters = {
|
19
|
@DnetCollectorParam("splitOnElement")
|
20
|
})
|
21
|
public class HttpCollectorPlugin extends AbstractSplittedRecordPlugin {
|
22
|
|
23
|
@Override
|
24
|
protected BufferedInputStream getBufferedInputStream(final String baseUrl) throws CollectException {
|
25
|
try (CloseableHttpClient client = HttpClients.createDefault()) {
|
26
|
final HttpGet method = new HttpGet(baseUrl);
|
27
|
try (CloseableHttpResponse response = client.execute(method)) {
|
28
|
final int statusCode = response.getStatusLine().getStatusCode();
|
29
|
|
30
|
if (HttpStatus.SC_OK != statusCode) { throw new CollectException("Error " + statusCode + " dowloading url: " + baseUrl); }
|
31
|
|
32
|
return new BufferedInputStream(response.getEntity().getContent());
|
33
|
}
|
34
|
} catch (final IOException e) {
|
35
|
throw new CollectException("Error dowloading url: " + baseUrl);
|
36
|
}
|
37
|
}
|
38
|
|
39
|
}
|