Revision 57636
Added by Sandro La Bruzzo over 4 years ago
CrossRefIteratorTest.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import org.antlr.stringtemplate.StringTemplate; |
4 | 4 |
import org.apache.commons.io.IOUtils; |
5 |
import org.apache.http.HttpEntity; |
|
6 |
import org.apache.http.client.ResponseHandler; |
|
7 |
import org.apache.http.client.config.RequestConfig; |
|
8 |
import org.apache.http.client.methods.CloseableHttpResponse; |
|
9 |
import org.apache.http.client.methods.HttpGet; |
|
10 |
import org.apache.http.impl.client.CloseableHttpClient; |
|
11 |
import org.apache.http.impl.client.HttpClientBuilder; |
|
12 |
import org.apache.http.util.EntityUtils; |
|
5 | 13 |
import org.junit.Ignore; |
6 | 14 |
import org.junit.Test; |
7 | 15 |
|
... | ... | |
31 | 39 |
} |
32 | 40 |
} |
33 | 41 |
} |
42 |
|
|
43 |
|
|
44 |
private static ResponseHandler<String> responseHandler = response -> { |
|
45 |
int status = response.getStatusLine().getStatusCode(); |
|
46 |
if (status >= 200 && status < 300) { |
|
47 |
HttpEntity entity = response.getEntity(); |
|
48 |
return entity != null ? EntityUtils.toString(entity) : null; |
|
49 |
} else { |
|
50 |
System.out.println("Unexpected response status: " + status); |
|
51 |
return null; |
|
52 |
} |
|
53 |
}; |
|
54 |
|
|
55 |
@Test |
|
56 |
public void testGettingRequest() throws IOException { |
|
57 |
final String url ="https://api.eventdata.crossref.org/v1/events/scholix?mailto=sandro.labruzzo@isti.cnr.it&rows=100"; |
|
58 |
int timeout = 300; |
|
59 |
|
|
60 |
RequestConfig config = RequestConfig.custom() |
|
61 |
.setConnectTimeout(timeout * 1000) |
|
62 |
.setConnectionRequestTimeout(timeout * 1000) |
|
63 |
.setSocketTimeout(timeout * 1000).build(); |
|
64 |
final CloseableHttpClient httpclient = HttpClientBuilder.create().setDefaultRequestConfig(config).build(); |
|
65 |
HttpGet httpGet = new HttpGet(url); |
|
66 |
String s = httpclient.execute(httpGet, responseHandler); |
|
67 |
|
|
68 |
System.out.println(s); |
|
69 |
|
|
70 |
|
|
71 |
} |
|
72 |
|
|
34 | 73 |
} |
Also available in: Unified diff
Added failedCallback to mdstore plugin invocation