use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class SlackChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(SlackJobDetailsModel slackJobDetails, List<SlackChannelMessageModel> channelMessages) throws AlertException {
String webhook = slackJobDetails.getWebhook();
String channelName = slackJobDetails.getChannelName();
String channelUsername = Optional.ofNullable(slackJobDetails.getChannelUsername()).orElse(SLACK_DEFAULT_USERNAME);
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> requests = channelMessages.stream().map(channelMessage -> createJsonString(channelMessage.getMarkdownContent(), channelName, channelUsername)).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(requests, slackChannelKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d Slack message(s)", requests.size()));
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class UpdateChecker method createHttpClient.
private IntHttpClient createHttpClient() {
ProxyInfo proxyInfo = proxyManager.createProxyInfoForHost(DockerTagRetriever.ALERT_DOCKER_REGISTRY_URL);
Boolean alwaysTrustServerCert = alertProperties.getAlertTrustCertificate().orElse(Boolean.FALSE);
return new IntHttpClient(logger, gson, 120, alwaysTrustServerCert, proxyInfo);
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class PhoneHomeTask method createPhoneHomeService.
private PhoneHomeService createPhoneHomeService(ExecutorService phoneHomeExecutor) {
IntLogger intLogger = new Slf4jIntLogger(logger);
ProxyInfo proxyInfo = proxyManager.createProxyInfoForHost(GoogleAnalyticsConstants.BASE_URL);
IntHttpClient intHttpClient = new IntHttpClient(intLogger, gson, IntHttpClient.DEFAULT_TIMEOUT, true, proxyInfo);
PhoneHomeClient phoneHomeClient = BlackDuckPhoneHomeHelper.createPhoneHomeClient(intLogger, intHttpClient.getClientBuilder(), gson);
return PhoneHomeService.createAsynchronousPhoneHomeService(intLogger, phoneHomeClient, phoneHomeExecutor);
}
use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.
the class ProxyTestService method pingHost.
public ConfigurationTestResult pingHost(String testUrl, SettingsProxyModel settingsProxyModel) {
ProxyInfo proxyInfo = proxyManager.createProxyInfo(settingsProxyModel);
IntHttpClient client = createIntHttpClient(proxyInfo);
try {
HttpUrl httpUrl = new HttpUrl(testUrl);
Request testRequest = new Request.Builder(httpUrl).build();
Response response = client.execute(testRequest);
if (RestConstants.OK_200 >= response.getStatusCode() && response.getStatusCode() < RestConstants.MULT_CHOICE_300) {
logger.info("Successfully pinged {}!", testUrl);
return ConfigurationTestResult.success();
} else {
return ConfigurationTestResult.failure(String.format("Could not ping: %s. Status Message: %s. Status code: %s", testUrl, response.getStatusMessage(), response.getStatusCode()));
}
} catch (IntegrationException e) {
logger.error(e.getMessage(), e);
return ConfigurationTestResult.failure(e.getMessage());
}
}
Aggregations