use of com.synopsys.integration.rest.request.Request in project hub-alert by blackducksoftware.
the class DockerTagRetriever method getTagResponseModel.
private DockerTagsResponseModel getTagResponseModel(String pageUrl) {
HttpUrl httpUrl;
try {
httpUrl = new HttpUrl(pageUrl);
} catch (IntegrationException e) {
logger.warn("Invalid url: " + pageUrl);
return DockerTagsResponseModel.EMPTY;
}
Request dockerTagsRequest = new Request.Builder(httpUrl).build();
try (Response tagsResponse = intHttpClient.execute(dockerTagsRequest)) {
tagsResponse.throwExceptionForError();
return gson.fromJson(tagsResponse.getContentString(), DockerTagsResponseModel.class);
} catch (IOException | IntegrationException e) {
logger.warn("Could not get docker tags from {}: {}", pageUrl, e.getMessage());
}
return DockerTagsResponseModel.EMPTY;
}
use of com.synopsys.integration.rest.request.Request in project hub-alert by blackducksoftware.
the class MSTeamsChannelMessageSender method sendMessages.
@Override
public MessageResult sendMessages(MSTeamsJobDetailsModel msTeamsJobDetailsModel, List<MSTeamsChannelMessageModel> channelMessages) throws AlertException {
String webhook = msTeamsJobDetailsModel.getWebhook();
Map<String, String> requestHeaders = new HashMap<>();
requestHeaders.put("Content-Type", "application/json");
IntHttpClient intHttpClient = connectionFactory.createIntHttpClient(webhook);
RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
List<Request> messageRequests = channelMessages.stream().map(this::createJsonString).map(jsonString -> restChannelUtility.createPostMessageRequest(webhook, requestHeaders, jsonString)).collect(Collectors.toList());
restChannelUtility.sendMessage(messageRequests, msTeamsKey.getUniversalKey());
return new MessageResult(String.format("Successfully sent %d MSTeams message(s)", channelMessages.size()));
}
use of com.synopsys.integration.rest.request.Request in project hub-alert by blackducksoftware.
the class RestChannelUtility method createPostMessageRequest.
public Request createPostMessageRequest(String url, Map<String, String> headers, @Nullable Map<String, Set<String>> queryParameters, String jsonString) {
HttpUrl httpUrl;
try {
httpUrl = new HttpUrl(url);
} catch (IntegrationException e) {
throw new AlertRuntimeException(e);
}
Request.Builder requestBuilder = new Request.Builder().method(HttpMethod.POST).url(httpUrl);
requestBuilder.getHeaders().putAll(headers);
requestBuilder.bodyContent(new StringBodyContent(jsonString, BodyContentConverter.DEFAULT));
if (queryParameters != null && !queryParameters.isEmpty()) {
requestBuilder.queryParameters(queryParameters);
}
return requestBuilder.build();
}
use of com.synopsys.integration.rest.request.Request in project hub-alert by blackducksoftware.
the class RestChannelUtilityTest method createPostMessageRequestTest.
@Test
public void createPostMessageRequestTest() {
String testUrl = "https://a-url";
String testJson = "{\"testField\": \"test value\"}";
Map<String, String> testHeaders = new HashMap<>();
String testHeaderKey = "Test Header";
testHeaders.put(testHeaderKey, "header value");
RestChannelUtility restChannelUtility = new RestChannelUtility(null);
Request request = restChannelUtility.createPostMessageRequest(testUrl, testHeaders, testJson);
assertEquals(testUrl, request.getUrl().string());
assertEquals(HttpMethod.POST, request.getMethod());
assertTrue(request.getHeaders().containsKey(testHeaderKey));
assertTrue(request.getQueryParameters().isEmpty());
assertReflectionEquals(new StringBodyContent(testJson, BodyContentConverter.DEFAULT), request.getBodyContent());
}
use of com.synopsys.integration.rest.request.Request in project hub-alert by blackducksoftware.
the class DockerTagRetrieverTest method getTagsModelTestIT.
@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void getTagsModelTestIT() throws IntegrationException {
IntLogger intLogger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
IntHttpClient intHttpClient = new IntHttpClient(intLogger, gson, 10, true, ProxyInfo.NO_PROXY_INFO);
HttpUrl httpUrl = new HttpUrl("https://google.com");
Request testRequest = new Request.Builder(httpUrl).build();
try (Response googleResponse = intHttpClient.execute(testRequest)) {
googleResponse.throwExceptionForError();
} catch (IntegrationException | IOException e) {
assumeTrue(null == e, "Could not connect. Skipping this test...");
}
DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
assertFalse(tagsModel.isEmpty(), "Expected tags from the docker repo to exist");
}
Aggregations