in webhooks-server/src/main/java/jetbrains/buildServer/webhook/WebhooksEventListener.java [133:171]
private void sendWithRetry(String uri, SimpleCredentials simpleCredentials, String json, Integer retryCount) {
AtomicInteger retryCountRef = new AtomicInteger(retryCount);
Consumer<Exception> exception = (ex) -> {
if (retryCountRef.get() > 0) {
sendWithRetry(uri, simpleCredentials, json, retryCountRef.decrementAndGet());
}
else {
if (ex instanceof WebhookSendException)
throw (WebhookSendException) ex;
throw new WebhookSendException(ex.getClass().getName(), format("Sending webhook to %s failed with exception %s.", uri, ex.getMessage()));
}
};
BiConsumer<Integer, String> error = (code, message) -> {
if (retryCountRef.get() > 0)
sendWithRetry(uri, simpleCredentials, json, retryCountRef.decrementAndGet());
else
throw new WebhookSendException(String.valueOf(code), format("Sending webhook to %s failed with HTTP code: %s %s.", uri, code, message));
};
try {
HTTPRequestBuilder request = new HTTPRequestBuilder(uri)
.withTimeout(60 * 1000)
.withAuthenticateHeader(simpleCredentials)
.withTrustStore(sslTrustStoreProvider.getTrustStore())
.allowNonSecureConnection(true)
.withEncodingInterceptor(true)
.withHeader(Collections.singletonMap("Content-Type", "application/json"))
.withMethod(HttpMethod.POST)
.withPostStringEntity(json, "application/json", StandardCharsets.UTF_8)
.onException(exception)
.onErrorResponse(error);
IOGuard.allowNetworkCall(() -> requestHandler.doRequest(request.build()));
} catch (URISyntaxException ex) {
throw new WebhookSendException(uri, format("Sending webhook to %s failed because of wrong URL syntax. Exception message: %s.", uri, ex.getMessage()));
}
}