use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class IssuesFileSerializer method serializeIssues.
public static InputStream serializeIssues(List<OctaneIssue> octaneIssues) {
try {
Map<String, List<OctaneIssue>> dataFormat = new HashMap<>();
dataFormat.put("data", octaneIssues);
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
mapper.writeValue(baos, dataFormat);
InputStream is = new ByteArrayInputStream(baos.toByteArray());
return is;
} catch (Exception e) {
throw new PermanentException(e);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class IssuesFileSerializer method cacheIssues.
public static void cacheIssues(String targetDir, List<OctaneIssue> octaneIssues) {
try {
if (targetDir != null) {
validateFolderExists(targetDir);
Map<String, List<OctaneIssue>> dataFormat = new HashMap<>();
dataFormat.put("data", octaneIssues);
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
// send to cache
String vulnerabilitiesScanFilePath = targetDir + File.separator + SSCHandler.SCAN_RESULT_FILE;
PrintWriter fw = new PrintWriter(vulnerabilitiesScanFilePath, "UTF-8");
mapper.writeValue(fw, dataFormat);
fw.flush();
fw.close();
}
} catch (Exception e) {
throw new PermanentException(e);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method pushVulnerabilities.
private void pushVulnerabilities(InputStream vulnerabilities, String jobId, String buildId) throws IOException {
OctaneRestClient octaneRestClient = restService.obtainOctaneRestClient();
Map<String, String> headers = new HashMap<>();
headers.put(RestService.CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
boolean base64 = isEncodeBase64();
String encodedJobId = base64 ? CIPluginSDKUtils.urlEncodeBase64(jobId) : CIPluginSDKUtils.urlEncodePathParam(jobId);
String encodedBuildId = CIPluginSDKUtils.urlEncodePathParam(buildId);
String url = getVulnerabilitiesContextPath(configurer.octaneConfiguration.getUrl(), configurer.octaneConfiguration.getSharedSpace()) + "?instance-id=" + configurer.octaneConfiguration.getInstanceId() + "&job-ci-id=" + encodedJobId + "&build-ci-id=" + encodedBuildId;
if (base64) {
url = CIPluginSDKUtils.addParameterEncode64ToUrl(url);
}
OctaneRequest request = dtoFactory.newDTO(OctaneRequest.class).setMethod(HttpMethod.POST).setUrl(url).setHeaders(headers).setBody(vulnerabilities);
OctaneResponse response = octaneRestClient.execute(request);
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities pushed; status: " + response.getStatus() + ", response: " + response.getBody());
if (response.getStatus() == HttpStatus.SC_ACCEPTED) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities push SUCCEED for " + jobId + " #" + buildId);
} else if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
throw new TemporaryException("vulnerabilities push FAILED, service unavailable");
} else {
throw new PermanentException("vulnerabilities push FAILED, status " + response.getStatus() + "; dropping this item from the queue \n" + response.getBody());
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class VulnerabilitiesServiceImpl method vulnerabilitiesPreflightRequest.
private Date vulnerabilitiesPreflightRequest(String jobId, String buildId) throws IOException {
OctaneResponse response = getBaselineDateFromOctane(jobId, buildId);
if (response.getStatus() == HttpStatus.SC_OK) {
if (response.getBody() == null || "".equals(response.getBody())) {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities data of " + jobId + " #" + buildId + " is not relevant to Octane");
return null;
} else {
logger.info(configurer.octaneConfiguration.getLocationForLog() + "vulnerabilities data of " + jobId + " #" + buildId + " found to be relevant to Octane");
boolean forTest = false;
// backward compatibility with Octane
if ("true".equals(response.getBody()) || forTest) {
return DateUtils.getDateFromUTCString("2000-01-01", "yyyy-MM-dd");
}
return DateUtils.getDateFromUTCString(response.getBody(), DateUtils.octaneFormat);
}
}
if (response.getStatus() == HttpStatus.SC_SERVICE_UNAVAILABLE || response.getStatus() == HttpStatus.SC_BAD_GATEWAY) {
throw new TemporaryException("vulnerabilities preflight request FAILED, service unavailable");
} else {
throw new PermanentException("vulnerabilities preflight request FAILED with " + response.getStatus() + "");
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SSCRestClientImpl method sendGetRequest.
@Override
public CloseableHttpResponse sendGetRequest(SSCProjectConfiguration sscProjectConfiguration, String url) {
HttpGet request = new HttpGet(url);
request.addHeader("Authorization", "FortifyToken " + getToken(sscProjectConfiguration, false));
request.addHeader("Accept", "application/json");
request.addHeader("Host", getNetHost(sscProjectConfiguration.getSSCUrl()));
CloseableHttpResponse response;
try {
response = httpClient.execute(request);
// 401. Access..
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
request.removeHeaders("Authorization");
request.addHeader("Authorization", "FortifyToken " + getToken(sscProjectConfiguration, true));
response = httpClient.execute(request);
}
return response;
} catch (IOException e) {
throw new TemporaryException(e);
} catch (Exception e) {
throw new PermanentException(e);
}
}
Aggregations