1
|
package eu.dnetlib.data.collector.plugins;
|
2
|
|
3
|
import java.io.BufferedInputStream;
|
4
|
import java.io.IOException;
|
5
|
import eu.dnetlib.rmi.data.CollectorServiceException;
|
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
|
|
12
|
public class HttpCollectorPlugin extends AbstractSplittedRecordPlugin {
|
13
|
|
14
|
@Override
|
15
|
protected BufferedInputStream getBufferedInputStream(final String baseUrl) throws CollectorServiceException {
|
16
|
try(CloseableHttpClient client = HttpClients.createDefault()) {
|
17
|
final HttpGet method = new HttpGet(baseUrl);
|
18
|
try(CloseableHttpResponse response = client.execute(method)) {
|
19
|
int statusCode = response.getStatusLine().getStatusCode();
|
20
|
|
21
|
if (HttpStatus.SC_OK != statusCode) {
|
22
|
throw new CollectorServiceException("Error " + statusCode + " dowloading url: " + baseUrl);
|
23
|
}
|
24
|
|
25
|
return new BufferedInputStream(response.getEntity().getContent());
|
26
|
}
|
27
|
} catch (IOException e) {
|
28
|
throw new CollectorServiceException("Error dowloading url: " + baseUrl);
|
29
|
}
|
30
|
}
|
31
|
|
32
|
}
|