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
	public String getProtocol() {
16
		return "http";
17
	}
18

    
19
	@Override
20
	protected BufferedInputStream getBufferedInputStream(final String baseUrl) throws CollectorServiceException {
21
		try { 
22
			final HttpClient client = new HttpClient();
23
			final HttpMethod method = new GetMethod(baseUrl);
24
			final int responseCode = client.executeMethod(method);
25
	
26
			if (HttpStatus.SC_OK != responseCode) {
27
				throw new CollectorServiceException("Error " + responseCode + " dowloading url: " + baseUrl);
28
			}
29
			return new BufferedInputStream(method.getResponseBodyAsStream());
30
		} catch (Exception e) {
31
			throw new CollectorServiceException("Error dowloading url: " + baseUrl);
32
		}
33
	}
34

    
35
}
(6-6/6)