use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project riposte by Nike-Inc.
the class VerifyAsyncHttpClientHelperComponentTest method verify_basic_functionality.
@Test
public void verify_basic_functionality() throws Exception {
// given
RequestBuilderWrapper rbw = asyncClient.getRequestBuilder("http://localhost:" + serverPort + TestEndpoint.MATCHING_PATH, HttpMethod.GET);
rbw.requestBuilder.setHeader(TestEndpoint.EXPECTED_HEADER_KEY, TestEndpoint.EXPECTED_HEADER_VAL);
rbw.requestBuilder.setBody(TestEndpoint.EXPECTED_REQUEST_PAYLOAD);
Span origSpan = Tracer.getInstance().startRequestWithRootSpan("overallReqSpan");
Deque<Span> distributedTraceStackForCall = Tracer.getInstance().getCurrentSpanStackCopy();
Map<String, String> mdcContextForCall = MDC.getCopyOfContextMap();
resetTracingAndMdc();
// when
Response result = asyncClient.executeAsyncHttpRequest(rbw, response -> response, distributedTraceStackForCall, mdcContextForCall).join();
// then
assertThat(result.getStatusCode()).isEqualTo(200);
assertThat(result.getResponseBody()).isEqualTo(TestEndpoint.RESPONSE_PAYLOAD);
assertThat(result.getHeader(TraceHeaders.TRACE_ID)).isEqualTo(origSpan.getTraceId());
// The async client should have surrounded the request in a subspan,
// so the parent ID sent to the downstream service should be the original span's span ID.
assertThat(result.getHeader(TraceHeaders.PARENT_SPAN_ID)).isEqualTo(origSpan.getSpanId());
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project riposte by Nike-Inc.
the class AwsUtil method getAwsRegion.
/**
* @param asyncHttpClientHelper The async HTTP client you want this method to use to make the AWS metadata call.
*
* @return A {@link CompletableFuture} that will contain the AWS region this app is running in (assuming it
* completes successfully). If an error occurs retrieving the region from AWS then the error will be logged and
* {@link AppInfo#UNKNOWN_VALUE} returned as the value.
*/
public static CompletableFuture<String> getAwsRegion(AsyncHttpClientHelper asyncHttpClientHelper) {
return asyncHttpClientHelper.executeAsyncHttpRequest(asyncHttpClientHelper.getRequestBuilder(AMAZON_METADATA_DOCUMENT_URL, HttpMethod.GET), response -> {
String region = null;
try {
ObjectMapper objectMapper = new ObjectMapper();
Map<String, String> resultMap = objectMapper.readValue(response.getResponseBody(), new TypeReference<Map<String, String>>() {
});
region = resultMap.get("region");
} catch (Throwable t) {
logger.error("Error retrieving region from AWS", t);
}
if (region == null) {
logger.error("AWS metadata service returned null for region. Using 'unknown' as fallback.");
region = AppInfo.UNKNOWN_VALUE;
}
return region;
}).handle((region, error) -> {
if (error != null) {
logger.error("Unable to get region info from AWS metadata service.", error);
return AppInfo.UNKNOWN_VALUE;
}
if (region == null) {
logger.error("AWS metadata service returned null for region. Using 'unknown' as fallback.");
region = AppInfo.UNKNOWN_VALUE;
}
return region;
});
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project killbill by killbill.
the class TestPlugin method testPassRequestsToKnownPluginButWrongPath.
@Test(groups = "slow")
public void testPassRequestsToKnownPluginButWrongPath() throws Exception {
final String uri = TEST_PLUGIN_NAME + "/somethingSomething";
Response response;
response = killBillClient.pluginGET(uri);
testAndResetAllMarkers(response, 200, new byte[] {}, false, false, false, false, false, false);
response = killBillClient.pluginHEAD(uri);
testAndResetAllMarkers(response, 204, new byte[] {}, false, false, false, false, false, false);
response = killBillClient.pluginPOST(uri, null);
testAndResetAllMarkers(response, 200, new byte[] {}, false, false, false, false, false, false);
response = killBillClient.pluginPUT(uri, null);
testAndResetAllMarkers(response, 200, new byte[] {}, false, false, false, false, false, false);
response = killBillClient.pluginDELETE(uri);
testAndResetAllMarkers(response, 200, new byte[] {}, false, false, false, false, false, false);
response = killBillClient.pluginOPTIONS(uri);
testAndResetAllMarkers(response, 200, new byte[] {}, false, false, false, false, false, false);
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project killbill by killbill.
the class TestPlugin method testPassRequestsToUnknownPlugin.
@Test(groups = "slow")
public void testPassRequestsToUnknownPlugin() throws Exception {
final String uri = "pluginDoesNotExist/something";
Response response;
// We don't test the output here as it is some Jetty specific HTML blurb
response = killBillClient.pluginGET(uri);
testAndResetAllMarkers(response, 404, null, false, false, false, false, false, false);
response = killBillClient.pluginHEAD(uri);
testAndResetAllMarkers(response, 404, null, false, false, false, false, false, false);
response = killBillClient.pluginPOST(uri, null);
testAndResetAllMarkers(response, 404, null, false, false, false, false, false, false);
response = killBillClient.pluginPUT(uri, null);
testAndResetAllMarkers(response, 404, null, false, false, false, false, false, false);
response = killBillClient.pluginDELETE(uri);
testAndResetAllMarkers(response, 404, null, false, false, false, false, false, false);
response = killBillClient.pluginOPTIONS(uri);
testAndResetAllMarkers(response, 404, null, false, false, false, false, false, false);
}
use of org.apache.apex.shaded.ning19.com.ning.http.client.Response in project pinot by linkedin.
the class JsonAsyncHttpPinotClientTransport method executeQueryAsync.
@Override
public Future<BrokerResponse> executeQueryAsync(String brokerAddress, final String query) {
try {
final JSONObject json = new JSONObject();
json.put("pql", query);
final String url = "http://" + brokerAddress + "/query";
final Future<Response> response = _httpClient.preparePost(url).setBody(json.toString()).execute();
return new BrokerResponseFuture(response, query, url);
} catch (Exception e) {
throw new PinotClientException(e);
}
}
Aggregations