use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project pinpoint by naver.
the class NingAsyncHttpClientIT method test.
@Test
public void test() throws Exception {
AsyncHttpClient client = new AsyncHttpClient();
try {
Future<Response> f = client.preparePost("http://www.naver.com/").addParameter("param1", "value1").execute();
Response response = f.get();
} finally {
client.close();
}
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(event("ASYNC_HTTP_CLIENT", AsyncHttpClient.class.getMethod("executeRequest", Request.class, AsyncHandler.class), null, null, "www.naver.com", annotation("http.url", "http://www.naver.com"), annotation("http.param", "param1=value1")));
verifier.verifyTraceCount(0);
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project cdap by caskdata.
the class NettyRouterTestBase method testUpload.
@Test
public void testUpload() throws Exception {
AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder();
final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(new NettyAsyncHttpProvider(configBuilder.build()), configBuilder.build());
byte[] requestBody = generatePostData();
final Request request = new RequestBuilder("POST").setUrl(resolveURI(DEFAULT_SERVICE, "/v1/upload")).setContentLength(requestBody.length).setBody(new ByteEntityWriter(requestBody)).build();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Future<Void> future = asyncHttpClient.executeRequest(request, new AsyncCompletionHandler<Void>() {
@Override
public Void onCompleted(Response response) throws Exception {
return null;
}
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
//TimeUnit.MILLISECONDS.sleep(RANDOM.nextInt(10));
content.writeTo(byteArrayOutputStream);
return super.onBodyPartReceived(content);
}
});
future.get();
Assert.assertArrayEquals(requestBody, byteArrayOutputStream.toByteArray());
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project cdap by caskdata.
the class NettyRouterTestBase method testRouterAsync.
@Test
public void testRouterAsync() throws Exception {
int numElements = 123;
AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder();
final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(new NettyAsyncHttpProvider(configBuilder.build()), configBuilder.build());
final CountDownLatch latch = new CountDownLatch(numElements);
final AtomicInteger numSuccessfulRequests = new AtomicInteger(0);
for (int i = 0; i < numElements; ++i) {
final int elem = i;
final Request request = new RequestBuilder("GET").setUrl(resolveURI(DEFAULT_SERVICE, String.format("%s/%s-%d", "/v1/echo", "async", i))).build();
asyncHttpClient.executeRequest(request, new AsyncCompletionHandler<Void>() {
@Override
public Void onCompleted(Response response) throws Exception {
latch.countDown();
Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusCode());
String responseBody = response.getResponseBody();
LOG.trace("Got response {}", responseBody);
Assert.assertEquals("async-" + elem, responseBody);
numSuccessfulRequests.incrementAndGet();
return null;
}
@Override
public void onThrowable(Throwable t) {
LOG.error("Got exception while posting {}", elem, t);
latch.countDown();
}
});
// Sleep so as not to overrun the server.
TimeUnit.MILLISECONDS.sleep(1);
}
latch.await();
asyncHttpClient.close();
Assert.assertEquals(numElements, numSuccessfulRequests.get());
// we use sticky endpoint strategy so the sum of requests from the two gateways should be NUM_ELEMENTS
Assert.assertTrue(numElements == (defaultServer1.getNumRequests() + defaultServer2.getNumRequests()));
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project cdap by caskdata.
the class NettyRouterPipelineTest method testChunkRequestSuccess.
@Test
public void testChunkRequestSuccess() throws Exception {
AsyncHttpClientConfig.Builder configBuilder = new AsyncHttpClientConfig.Builder();
final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(new NettyAsyncHttpProvider(configBuilder.build()), configBuilder.build());
byte[] requestBody = generatePostData();
final Request request = new RequestBuilder("POST").setUrl(String.format("http://%s:%d%s", HOSTNAME, ROUTER.getServiceMap().get(GATEWAY_NAME), "/v1/upload")).setContentLength(requestBody.length).setBody(new ByteEntityWriter(requestBody)).build();
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Future<Void> future = asyncHttpClient.executeRequest(request, new AsyncCompletionHandler<Void>() {
@Override
public Void onCompleted(Response response) throws Exception {
return null;
}
@Override
public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
//TimeUnit.MILLISECONDS.sleep(RANDOM.nextInt(10));
content.writeTo(byteArrayOutputStream);
return super.onBodyPartReceived(content);
}
});
future.get();
Assert.assertArrayEquals(requestBody, byteArrayOutputStream.toByteArray());
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project cdap by caskdata.
the class WorkflowClient method getWorkflowStatus.
public void getWorkflowStatus(String namespaceId, String appId, String workflowId, String runId, final Callback callback) throws IOException {
// determine the service provider for the given path
String serviceName = String.format("workflow.%s.%s.%s.%s", namespaceId, appId, workflowId, runId);
Discoverable discoverable = new RandomEndpointStrategy(discoveryServiceClient.discover(serviceName)).pick();
if (discoverable == null) {
LOG.debug("No endpoint for service {}", serviceName);
callback.handle(new Status(Status.Code.NOT_FOUND, ""));
return;
}
// make HTTP call to workflow service.
InetSocketAddress endpoint = discoverable.getSocketAddress();
// Construct request
String scheme = Arrays.equals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload()) ? Constants.Security.SSL_URI_SCHEME : Constants.Security.URI_SCHEME;
String url = String.format("%s%s:%d/status", scheme, endpoint.getHostName(), endpoint.getPort());
Request workflowRequest = new RequestBuilder("GET").setUrl(url).build();
httpClient.executeRequest(workflowRequest, new AsyncCompletionHandler<Void>() {
@Override
public Void onCompleted(Response response) throws Exception {
callback.handle(new Status(Status.Code.OK, response.getResponseBody(Charsets.UTF_8.name())));
return null;
}
@Override
public void onThrowable(Throwable t) {
LOG.warn("Failed to request for workflow status", t);
callback.handle(new Status(Status.Code.ERROR, ""));
}
});
}
Aggregations