use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class FODConnector method getAccessToken.
private void getAccessToken() {
HttpPost post = new HttpPost(fodConfig.authURL);
HttpEntity content = new StringEntity(fodConfig.getAuthBody(), ContentType.APPLICATION_FORM_URLENCODED);
post.setEntity(content);
CloseableHttpResponse response = null;
try {
logger.debug("inside getAccessToken():before Post ");
response = httpClient.execute(post);
logger.debug("inside getAccessToken():after Post, got status : " + response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() != 200 && response.getStatusLine().getStatusCode() != 201) {
logger.error("inside getAccessToken():after Post, got status : " + response.getStatusLine().getStatusCode());
throw new PermanentException("Cannot authenticate:" + response.getStatusLine().getReasonPhrase());
}
String secToken = isToString(response.getEntity().getContent());
HashMap secTokeAsMap = new ObjectMapper().readValue(secToken, HashMap.class);
access_token = secTokeAsMap.get("access_token").toString();
accessTokenTime = new Date().getTime();
logger.debug("inside getAccessToken():after Post ");
} catch (IOException e) {
logger.error("inside getAccessToken():After Post inside exception ", e);
e.printStackTrace();
if (response != null) {
EntityUtils.consumeQuietly(response.getEntity());
HttpClientUtils.closeQuietly(response);
}
throw new PermanentException("Cannot authenticate:" + e.getMessage());
} finally {
if (response != null) {
EntityUtils.consumeQuietly(response.getEntity());
HttpClientUtils.closeQuietly(response);
}
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class FODConnector method getRawResponseFromFOD.
private String getRawResponseFromFOD(String url) {
// URL encode
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Authorization", "Bearer " + getUpdatedAccessToken());
httpGet.setHeader("Accept", "application/json");
httpGet.setHeader("Cookie", "__zlcmid=hTgaa94NtAdw5T; FoD=1725197834.36895.0000");
httpGet.setHeader("Accept-Encoding", "gzip, deflate, br");
CloseableHttpResponse response = null;
try {
logger.debug("sending the request : " + url);
response = httpClient.execute(httpGet);
if (response.getStatusLine().getStatusCode() > 300) {
if (response.getStatusLine().getStatusCode() == 401) {
throw new PermanentException("Cannot authenticate , the user is Unauthorized , make sure you are using the correct role for the user (): " + response.getStatusLine().getReasonPhrase());
}
if (response.getStatusLine().getStatusCode() == 503) {
throw new TemporaryException("Service Unavailable , retry");
}
throw new PermanentException("unexpected return response : " + response.getStatusLine().getReasonPhrase());
}
return isToString(response.getEntity().getContent());
} catch (IOException e) {
throw new PermanentException(e);
} finally {
if (response != null) {
EntityUtils.consumeQuietly(response.getEntity());
HttpClientUtils.closeQuietly(response);
}
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SonarVulnerabilitiesServiceImpl method getIssuesFromSecurityTool.
public List<SonarIssue> getIssuesFromSecurityTool(VulnerabilitiesQueueItem queueItem) {
String projectKey = queueItem.getAdditionalProperties().get(PROJECT_KEY_KEY);
String sonarToken = queueItem.getAdditionalProperties().get(SONAR_TOKEN_KEY);
StringBuilder errorMessage = new StringBuilder().append("failed to get sonarqube vulnerability data for project key: ").append(projectKey).append(" with jobId: ").append(queueItem.getJobId()).append(" with buildId: ").append(queueItem.getBuildId());
try {
List<SonarIssue> sonarIssues = new ArrayList<>();
// retrieve coverage report from Sonar
Integer pageIndex = 0;
JsonNode jsonReport;
do {
pageIndex++;
URIBuilder vulnerabilityQuery = createQueryForSonarVulnerability(pageIndex, queueItem);
InputStream reportStream = SonarUtils.getDataFromSonar(projectKey, sonarToken, vulnerabilityQuery);
jsonReport = CIPluginSDKUtils.getObjectMapper().readTree(reportStream);
sonarIssues.addAll(getSonarIssuesFromReport(jsonReport));
} while (SonarUtils.sonarReportHasAnotherPage(pageIndex, jsonReport));
return sonarIssues;
} catch (IOException e) {
logger.error(errorMessage, e);
throw new PermanentException(e);
}
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SSCHandler method isScanProcessFinished.
public boolean isScanProcessFinished() {
logger.debug("enter isScanProcessFinished");
Artifacts artifacts = sscProjectConnector.getArtifactsOfProjectVersion(this.projectVersion.id, 10);
Artifacts.Artifact closestArtifact = getClosestArtifact(artifacts);
if (closestArtifact == null) {
logger.debug("Cannot find artifact of the run");
return false;
}
if (closestArtifact.status.equals(ARTIFACT_STATUS_COMPLETE)) {
logger.debug("artifact of the run is in completed");
return true;
}
if (closestArtifact.status.equals(ARTIFACT_ERROR_PROCESSING)) {
throw new PermanentException("artifact of the run faced error, polling should stop");
}
// todo , if there are more cases need to handle separately
logger.debug("artifact of the run is not complete, polling should continue");
return false;
}
use of com.hp.octane.integrations.exceptions.PermanentException in project octane-ci-java-sdk by MicroFocus.
the class SSCProjectConnector method readPagedEntities.
public <SSCArray extends SscBaseEntityArray> SSCArray readPagedEntities(String url, Class<SSCArray> type) {
int startIndex = 0;
try {
boolean allFetched = false;
SSCArray total = type.newInstance();
while (!allFetched) {
String pagedURL = getPagedURL(url, startIndex);
String rawResponse = sendGetEntity(pagedURL);
SSCArray page = stringToObject(rawResponse, type);
if (total.getData() == null) {
total.setData(page.getData());
} else {
total.getData().addAll(page.getData());
}
total.setCount(total.getData().size());
allFetched = (total.getData().size() == page.getCount());
startIndex = total.getCount();
}
return total;
} catch (InstantiationException | IllegalAccessException e) {
logger.error(e.getMessage());
throw new PermanentException("Fail to fetch Issues", e);
}
}
Aggregations