Project

General

Profile

1
package eu.dnetlib.data.collector.plugins;
2

    
3
import java.io.BufferedInputStream;
4

    
5
import org.apache.commons.httpclient.HttpClient;
6
import org.apache.commons.httpclient.HttpMethod;
7
import org.apache.commons.httpclient.HttpStatus;
8
import org.apache.commons.httpclient.methods.GetMethod;
9

    
10
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
11

    
12
public class HttpCollectorPlugin extends AbstractSplittedRecordPlugin {
13

    
14
	@Override
15
	protected BufferedInputStream getBufferedInputStream(final String baseUrl) throws CollectorServiceException {
16
		try {
17
			final HttpClient client = new HttpClient();
18
			final HttpMethod method = new GetMethod(baseUrl);
19
			final int responseCode = client.executeMethod(method);
20

    
21
			if (HttpStatus.SC_OK != responseCode) { throw new CollectorServiceException("Error " + responseCode + " dowloading url: " + baseUrl); }
22
			return new BufferedInputStream(method.getResponseBodyAsStream());
23
		} catch (Exception e) {
24
			throw new CollectorServiceException("Error dowloading url: " + baseUrl);
25
		}
26
	}
27

    
28
}
(7-7/8)