use of com.synopsys.integration.rest.body.BodyContent 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.BodyContent 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