use of com.synopsys.integration.rest.body.StringBodyContent in project hub-alert by blackducksoftware.
the class BlackDuckProviderIssueHandler method performRequest.
private void performRequest(HttpUrl httpUrl, HttpMethod httpMethod, IssueRequest issueRequest) throws IntegrationException {
BlackDuckResponseRequest request = new BlackDuckRequestBuilder().method(httpMethod).bodyContent(new StringBodyContent(gson.toJson(issueRequest), BodyContentConverter.DEFAULT)).buildBlackDuckResponseRequest(httpUrl);
blackDuckApiClient.execute(request);
}
use of com.synopsys.integration.rest.body.StringBodyContent 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.body.StringBodyContent 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.body.StringBodyContent in project hub-alert by blackducksoftware.
the class ExternalAlertRequestUtility method executeRequest.
private String executeRequest(String path, HttpMethod httpMethod, String requestBody, String error) throws IntegrationException {
BodyContent requestBodyContent = new StringBodyContent(requestBody, BodyContentConverter.DEFAULT);
Request.Builder requestBuilder = createRequestBuilder(path);
requestBuilder.method(httpMethod);
if (null != requestBody) {
requestBuilder.bodyContent(requestBodyContent);
}
Request request = requestBuilder.build();
Response response = client.execute(request);
if (response.isStatusCodeError()) {
intLogger.error(error);
response.throwExceptionForError();
}
return response.getContentString();
}
use of com.synopsys.integration.rest.body.StringBodyContent in project hub-alert by blackducksoftware.
the class ExternalAlertRequestUtility method loginToExternalAlert.
public void loginToExternalAlert() throws IntegrationException {
String loginBody = "{\"alertUsername\":\"sysadmin\",\"alertPassword\":\"blackduck\"}";
BodyContent requestBody = new StringBodyContent(loginBody, BodyContentConverter.DEFAULT);
Request.Builder requestBuilder = createRequestBuilder("/api/login");
requestBuilder.method(HttpMethod.POST);
requestBuilder.bodyContent(requestBody);
Request request = requestBuilder.build();
Response response = client.execute(request);
if (response.isStatusCodeError()) {
intLogger.error("Could not log into Alert.");
response.throwExceptionForError();
}
String csrfToken = response.getHeaderValue("X-CSRF-TOKEN");
String cookie = response.getHeaderValue("Set-Cookie");
client.addCommonRequestHeader("X-CSRF-TOKEN", csrfToken);
client.addCommonRequestHeader("Cookie", cookie);
intLogger.info("Logged into Alert.");
}
Aggregations