Search in sources :

Example 16 with TemporaryException

use of com.hp.octane.integrations.exceptions.TemporaryException in project octane-ci-java-sdk by MicroFocus.

the class FODServiceImpl method scanIsCompleted.

private boolean scanIsCompleted(Long releaseId, Long scanId) {
    try {
        Scan completeScan = FODReleaseService.getCompleteScan(releaseId, scanId);
        if (completeScan == null) {
            return false;
        }
        logger.debug(configurer.octaneConfiguration.getLocationForLog() + "scan:" + scanId + " is:" + completeScan.status);
        if (completeScan.status == null) {
            return false;
        }
        // Scan that has not started, and not in progress is completed.
        return (!Scan.IN_PROGRESS.equals(completeScan.status) && !Scan.NOT_STARTED.equals(completeScan.status) && !Scan.QUEUED.equals(completeScan.status));
    } catch (PermanentException e) {
        throw e;
    } catch (TemporaryException e) {
        throw e;
    } catch (Exception e) {
        return false;
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) Scan(com.hp.octane.integrations.services.vulnerabilities.fod.dto.pojos.Scan) TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) IOException(java.io.IOException) PermanentException(com.hp.octane.integrations.exceptions.PermanentException)

Example 17 with TemporaryException

use of com.hp.octane.integrations.exceptions.TemporaryException 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);
        }
    }
}
Also used : TemporaryException(com.hp.octane.integrations.exceptions.TemporaryException) HttpGet(org.apache.http.client.methods.HttpGet) PermanentException(com.hp.octane.integrations.exceptions.PermanentException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException)

Aggregations

PermanentException (com.hp.octane.integrations.exceptions.PermanentException)17 TemporaryException (com.hp.octane.integrations.exceptions.TemporaryException)17 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)10 IOException (java.io.IOException)10 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)7 RequestTimeoutException (com.hp.octane.integrations.exceptions.RequestTimeoutException)4 InputStream (java.io.InputStream)3 InterruptedIOException (java.io.InterruptedIOException)3 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)3 HttpGet (org.apache.http.client.methods.HttpGet)3 OctaneRestClient (com.hp.octane.integrations.services.rest.OctaneRestClient)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 BuildCoverage (com.hp.octane.integrations.dto.coverage.BuildCoverage)1 CIEvent (com.hp.octane.integrations.dto.events.CIEvent)1 CIEventsList (com.hp.octane.integrations.dto.events.CIEventsList)1 CIServerInfo (com.hp.octane.integrations.dto.general.CIServerInfo)1 Scan (com.hp.octane.integrations.services.vulnerabilities.fod.dto.pojos.Scan)1