mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-19 09:47:27 +10:00
git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-testweb/trunk@3520 84d0f5b1-2673-498c-a247-62c4ff18d310
47 lines
1.4 KiB
Java
47 lines
1.4 KiB
Java
package com.nhn.pinpoint.testweb.httpclient;
|
|
|
|
import java.io.IOException;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
import org.junit.Test;
|
|
|
|
import com.ning.http.client.AsyncCompletionHandler;
|
|
import com.ning.http.client.AsyncHttpClient;
|
|
import com.ning.http.client.AsyncHttpClientConfig;
|
|
import com.ning.http.client.ListenableFuture;
|
|
import com.ning.http.client.Response;
|
|
import com.ning.http.client.providers.netty.NettyAsyncHttpProvider;
|
|
|
|
public class AsyncHTTPClientTest {
|
|
|
|
@Test
|
|
public void asyncHttpClient() {
|
|
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().build();
|
|
AsyncHttpClient client = new AsyncHttpClient(new NettyAsyncHttpProvider(config), config);
|
|
|
|
try {
|
|
ListenableFuture<Response> future = client.prepareGet("http://www.naver.com").execute(new AsyncCompletionHandler<Response>() {
|
|
@Override
|
|
public Response onCompleted(Response response) throws Exception {
|
|
// do something
|
|
return response;
|
|
}
|
|
});
|
|
|
|
Response response = future.get(300L, TimeUnit.MILLISECONDS);
|
|
|
|
System.out.println(response.getResponseBody());
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
} catch (ExecutionException e) {
|
|
e.printStackTrace();
|
|
} catch (TimeoutException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|