Revision 53932
Added by Alessia Bardi over 5 years ago
HttpCollectorPlugin.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.BufferedInputStream; |
4 | 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 | 5 |
import eu.dnetlib.data.collector.rmi.CollectorServiceException; |
6 |
import org.apache.commons.io.IOUtils; |
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
11 | 8 |
|
12 | 9 |
public class HttpCollectorPlugin extends AbstractSplittedRecordPlugin { |
13 | 10 |
|
11 |
@Autowired |
|
12 |
private HttpConnector httpConnector; |
|
13 |
|
|
14 | 14 |
@Override |
15 | 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 | 16 |
|
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 |
} |
|
17 |
String res = httpConnector.getInputSource(baseUrl); |
|
18 |
return new BufferedInputStream(IOUtils.toInputStream(res)); |
|
26 | 19 |
} |
27 | 20 |
|
28 | 21 |
} |
Also available in: Unified diff
Upgrade to commons.net:commons.net 3.6 (from 3.3) and commons-httpclient 4.5.6 (from 3.1).
using HttpConnector where needed.
httpConnector can now return an InputStream and not only a string.