Search in sources :

Example 11 with IntHttpClient

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()));
}
Also used : JsonObject(com.google.gson.JsonObject) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) Collectors(java.util.stream.Collectors) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) SlackJobDetailsModel(com.synopsys.integration.alert.common.persistence.model.job.details.SlackJobDetailsModel) ChannelMessageSender(com.synopsys.integration.alert.api.channel.ChannelMessageSender) List(java.util.List) Component(org.springframework.stereotype.Component) SlackChannelKey(com.synopsys.integration.alert.descriptor.api.SlackChannelKey) Map(java.util.Map) Optional(java.util.Optional) HashMap(java.util.HashMap) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) RestChannelUtility(com.synopsys.integration.alert.api.channel.rest.RestChannelUtility) Request(com.synopsys.integration.rest.request.Request) MessageResult(com.synopsys.integration.alert.common.message.model.MessageResult)

Example 12 with IntHttpClient

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);
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient)

Example 13 with IntHttpClient

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);
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) PhoneHomeClient(com.synopsys.integration.phonehome.PhoneHomeClient) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) IntLogger(com.synopsys.integration.log.IntLogger) Slf4jIntLogger(com.synopsys.integration.log.Slf4jIntLogger)

Example 14 with IntHttpClient

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());
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)14 Request (com.synopsys.integration.rest.request.Request)7 Test (org.junit.jupiter.api.Test)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)5 Response (com.synopsys.integration.rest.response.Response)5 JsonObject (com.google.gson.JsonObject)2 ChannelMessageSender (com.synopsys.integration.alert.api.channel.ChannelMessageSender)2 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)2 RestChannelUtility (com.synopsys.integration.alert.api.channel.rest.RestChannelUtility)2 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2 DockerTagsResponseModel (com.synopsys.integration.alert.update.model.DockerTagsResponseModel)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 IntLogger (com.synopsys.integration.log.IntLogger)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2