use of org.apache.hc.core5.function.Callback in project wiremock by wiremock.
the class WebhooksAcceptanceTest method addsFixedDelayViaDSL.
@Test
public void addsFixedDelayViaDSL() throws Exception {
final int DELAY_MILLISECONDS = 1_000;
rule.stubFor(post(urlPathEqualTo("/delayed")).willReturn(ok()).withPostServeAction("webhook", webhook().withFixedDelay(DELAY_MILLISECONDS).withMethod(RequestMethod.GET).withUrl(targetServer.url("/callback"))));
verify(0, postRequestedFor(anyUrl()));
client.post("/delayed", new StringEntity("", TEXT_PLAIN));
Stopwatch stopwatch = Stopwatch.createStarted();
waitForRequestToTargetServer();
stopwatch.stop();
double elapsedMilliseconds = stopwatch.elapsed(MILLISECONDS);
assertThat(elapsedMilliseconds, closeTo(DELAY_MILLISECONDS, 500.0));
verify(1, getRequestedFor(urlEqualTo("/callback")));
}
use of org.apache.hc.core5.function.Callback in project wiremock by wiremock.
the class WebhooksAcceptanceTest method firesASingleWebhookWhenRequested.
@Test
public void firesASingleWebhookWhenRequested() throws Exception {
rule.stubFor(post(urlPathEqualTo("/something-async")).willReturn(aResponse().withStatus(200)).withPostServeAction("webhook", webhook().withMethod(POST).withUrl(targetServer.url("/callback")).withHeader("Content-Type", "application/json").withHeader("X-Multi", "one", "two").withBody("{ \"result\": \"SUCCESS\" }")));
verify(0, postRequestedFor(anyUrl()));
client.post("/something-async", new StringEntity("", TEXT_PLAIN));
waitForRequestToTargetServer();
targetServer.verify(1, postRequestedFor(urlEqualTo("/callback")).withHeader("Content-Type", equalTo("application/json")).withRequestBody(equalToJson("{ \"result\": \"SUCCESS\" }")));
List<String> multiHeaderValues = targetServer.findAll(postRequestedFor(urlEqualTo("/callback"))).get(0).header("X-Multi").values();
assertThat(multiHeaderValues, hasItems("one", "two"));
System.out.println("All info notifications:\n" + testNotifier.getInfoMessages().stream().map(message -> message.replace("\n", "\n>>> ")).collect(Collectors.joining("\n>>> ")));
assertThat(testNotifier.getInfoMessages(), hasItem(allOf(containsString("Webhook POST request to"), containsString("/callback returned status"), containsString("200"))));
}
use of org.apache.hc.core5.function.Callback in project invesdwin-util by invesdwin.
the class URIsConnectApacheAsync method openConnection.
public <T> Future<T> openConnection(final String method, final AsyncResponseConsumer<T> responseConsumer, final FutureCallback<T> callback) {
final SimpleHttpRequest request = SimpleHttpRequests.create(method, uri);
request.setConfig(getRequestConfig());
if (headers != null) {
for (final Entry<String, String> header : headers.entrySet()) {
request.addHeader(header.getKey(), header.getValue());
}
}
if (body != null) {
final ContentType commonsContentType;
if (contentType != null) {
commonsContentType = ContentType.create(contentType);
} else {
commonsContentType = null;
}
request.setBody(body, commonsContentType);
}
final SimpleRequestProducer requestProducer = SimpleRequestProducer.create(request);
final Future<T> response = getHttpClient().execute(requestProducer, responseConsumer, callback);
return response;
}
use of org.apache.hc.core5.function.Callback in project easeagent by megaease.
the class HttpClient5AsyncTracingInterceptor method doBefore.
@Override
public void doBefore(MethodInfo methodInfo, Context context) {
AsyncRequestProducer requestProducer = (AsyncRequestProducer) methodInfo.getArgs()[0];
HttpRequest request = AgentFieldReflectAccessor.getFieldValue(requestProducer, "request");
if (request == null) {
return;
}
InternalRequest internalRequest = new InternalRequest(request);
RequestContext requestContext = context.clientRequest(internalRequest);
HttpUtils.handleReceive(requestContext.span().start(), internalRequest);
context.put(HttpClient5AsyncTracingInterceptor.class, requestContext);
@SuppressWarnings("unchecked") FutureCallback<HttpResponse> callback = (FutureCallback<HttpResponse>) methodInfo.getArgs()[4];
InternalFutureCallback internalFutureCallback = new InternalFutureCallback(callback, request, requestContext);
methodInfo.changeArg(4, internalFutureCallback);
}
use of org.apache.hc.core5.function.Callback in project httpcomponents-core by apache.
the class HttpAsyncServer method listen.
/**
* @since 5.1
*/
public Future<ListenerEndpoint> listen(final SocketAddress address, final URIScheme scheme, final Object attachment, final FutureCallback<ListenerEndpoint> callback) {
final InetSocketAddress inetSocketAddress = (InetSocketAddress) address;
final EndpointParameters parameters = new EndpointParameters(scheme.id, canonicalName != null ? canonicalName : "localhost", inetSocketAddress.getPort(), attachment);
return super.listen(address, parameters, callback);
}
Aggregations