use of org.apache.http.client.methods.HttpGet in project openkit-android by OpenKit.
the class OKHTTPClient method get.
public static void get(String relativeUrl, RequestParams params, AsyncHttpResponseHandler responseHandler) {
HttpGet request = new HttpGet(AsyncHttpClient.getUrlWithQueryString(getAbsoluteUrl(relativeUrl), params));
sign(request);
client.get(request, responseHandler);
}
use of org.apache.http.client.methods.HttpGet in project openkit-android by OpenKit.
the class AsyncHttpClient method get.
/**
* Perform a HTTP GET request and track the Android Context which initiated
* the request with customized headers
*
* @param url the URL to send the request to.
* @param headers set headers only for this request
* @param params additional GET parameters to send with the request.
* @param responseHandler the response handler instance that should handle
* the response.
*/
public void get(Context context, String url, Header[] headers, RequestParams params, AsyncHttpResponseHandler responseHandler) {
HttpUriRequest request = new HttpGet(getUrlWithQueryString(url, params));
if (headers != null)
request.setHeaders(headers);
sendRequest(httpClient, httpContext, request, null, responseHandler, context);
}
use of org.apache.http.client.methods.HttpGet in project DataX by alibaba.
the class RetryUtilTest method testRetryAsync3.
//@Test
@Ignore
public void testRetryAsync3() throws Exception {
final int TIME_OUT = 30000;
ThreadPoolExecutor executor = RetryUtil.createThreadPoolExecutor();
String res = RetryUtil.asyncExecuteWithRetry(new Callable<String>() {
@Override
public String call() throws Exception {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIME_OUT).setConnectTimeout(TIME_OUT).setConnectionRequestTimeout(TIME_OUT).setStaleConnectionCheckEnabled(true).build();
HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(10).setMaxConnPerRoute(10).setDefaultRequestConfig(requestConfig).build();
HttpGet httpGet = new HttpGet();
httpGet.setURI(new URI("http://0.0.0.0:8080/test"));
httpClient.execute(httpGet);
return OK;
}
}, 3, 1000L, false, 6000L, executor);
Assert.assertEquals(res, OK);
// Assert.assertEquals(RetryUtil.EXECUTOR.getActiveCount(), 0);
}
use of org.apache.http.client.methods.HttpGet in project DataX by alibaba.
the class HttpClientUtilTest method testExecuteAndGetWithRetry2.
/**
* 和测试方法一样:testExecuteAndGetWithRetry(),只是换了一种写法,直接采用 Mockito 进行验证的。
*/
@Test
public void testExecuteAndGetWithRetry2() throws Exception {
String url = "http://127.0.0.1/:8080";
HttpRequestBase httpRequestBase = new HttpGet(url);
HttpClientUtil httpClientUtil = Mockito.spy(HttpClientUtil.getHttpClientUtil());
Mockito.doThrow(new Exception("one")).doThrow(new Exception("two")).doThrow(new Exception("three")).doReturn("成功").when(httpClientUtil).executeAndGet(httpRequestBase);
String str = httpClientUtil.executeAndGetWithRetry(httpRequestBase, 4, 1000l);
Assert.assertEquals(str, "成功");
Mockito.reset(httpClientUtil);
Mockito.doThrow(new Exception("one")).doThrow(new Exception("two")).doThrow(new Exception("three")).doReturn("成功").when(httpClientUtil).executeAndGet(httpRequestBase);
try {
httpClientUtil.executeAndGetWithRetry(httpRequestBase, 2, 1000l);
} catch (Exception e) {
Assert.assertTrue(e instanceof DataXException);
Assert.assertTrue(e.getMessage().contains("two"));
}
httpClientUtil.destroy();
}
use of org.apache.http.client.methods.HttpGet in project DataX by alibaba.
the class HttpClientUtilTest method testExecuteAndGetWithRetry.
@Test
public void testExecuteAndGetWithRetry() throws Exception {
String url = "http://127.0.0.1/:8080";
HttpRequestBase httpRequestBase = new HttpGet(url);
HttpClientUtil httpClientUtil = PowerMockito.spy(HttpClientUtil.getHttpClientUtil());
PowerMockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
System.out.println("失败第1次");
return new Exception("失败第1次");
}
}).doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
System.out.println("失败第2次");
return new Exception("失败第2次");
}
}).doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
System.out.println("失败第3次");
return new Exception("失败第3次");
}
}).doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
System.out.println("失败第4次");
return new Exception("失败第4次");
}
}).doReturn("成功").when(httpClientUtil).executeAndGet(any(HttpRequestBase.class));
String str = httpClientUtil.executeAndGetWithRetry(httpRequestBase, 5, 1000l);
Assert.assertEquals(str, "成功");
try {
httpClientUtil.executeAndGetWithRetry(httpRequestBase, 2, 1000l);
} catch (Exception e) {
Assert.assertTrue(e instanceof DataXException);
}
httpClientUtil.destroy();
}
Aggregations