Search in sources :

Example 11 with CheckmarxException

use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class GoScanner method getScanDetails.

public Scan getScanDetails(Integer scanId) throws CheckmarxException {
    HttpEntity httpEntity = new HttpEntity<>(authClient.createAuthHeaders());
    try {
        log.debug("Retrieving scan with id {}", scanId);
        ResponseEntity<Scan> response = restTemplate.exchange(cxGoProperties.getUrl().concat(SCAN), HttpMethod.GET, httpEntity, Scan.class, scanId);
        return Optional.ofNullable(response.getBody()).orElseThrow(() -> new CheckmarxRuntimeException("Scan details response body is missing."));
    } catch (HttpStatusCodeException e) {
        log.error("Error occurred while retrieving the scan with id {}", scanId);
        log.error(ExceptionUtils.getStackTrace(e));
        throw new CheckmarxException("Error occurred while retrieving the scan with id".concat(Integer.toString(scanId)));
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) CheckmarxRuntimeException(com.checkmarx.sdk.exception.CheckmarxRuntimeException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 12 with CheckmarxException

use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class GoScanner method getScans.

public List<Scan> getScans() throws CheckmarxException {
    HttpEntity<?> httpEntity = new HttpEntity<>(authClient.createAuthHeaders());
    try {
        log.debug("Retrieving all scans");
        ResponseEntity<Scan[]> response = restTemplate.exchange(cxGoProperties.getUrl().concat(SCANS), HttpMethod.GET, httpEntity, Scan[].class);
        return Arrays.asList(Objects.requireNonNull(response.getBody()));
    } catch (HttpStatusCodeException e) {
        log.error("Error occurred while retrieving scans");
        log.error(ExceptionUtils.getStackTrace(e));
        throw new CheckmarxException("Error occurred while retrieving scans");
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 13 with CheckmarxException

use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class GoScanner method getScanResults.

private GoScanResults getScanResults(Integer scanId) throws CheckmarxException {
    HttpEntity<?> httpEntity = new HttpEntity<>(authClient.createAuthHeaders());
    try {
        log.info("Retrieving Scan Results for Scan Id {} ", scanId);
        ResponseEntity<GoScanResults> response = restTemplate.exchange(cxGoProperties.getUrl().concat(SCAN_RESULTS), HttpMethod.GET, httpEntity, GoScanResults.class, scanId);
        return response.getBody();
    } catch (HttpStatusCodeException e) {
        log.error("Error occurred while retrieving the scan results for id {}.", scanId);
        log.error(ExceptionUtils.getStackTrace(e));
        throw new CheckmarxException("Error occurred while retrieving the scan status for id ".concat(Integer.toString(scanId)));
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 14 with CheckmarxException

use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class GoScanner method getNavigationTree.

private OdNavigationTree getNavigationTree(String clientSecret) throws CheckmarxException {
    HttpEntity<?> httpEntity = new HttpEntity<>(authClient.createAuthHeaders(clientSecret));
    try {
        log.debug("Retrieving OD Navigation Tree");
        ResponseEntity<OdNavigationTree> response = restTemplate.exchange(cxGoProperties.getUrl().concat("/navigation-tree/navigation-tree"), HttpMethod.GET, httpEntity, OdNavigationTree.class);
        return response.getBody();
    } catch (HttpStatusCodeException e) {
        log.error("Error occurred while retrieving the navigation tree.");
        log.error(ExceptionUtils.getStackTrace(e));
        throw new CheckmarxException("Error retrieving Business Units.");
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException) HttpStatusCodeException(org.springframework.web.client.HttpStatusCodeException)

Example 15 with CheckmarxException

use of com.checkmarx.sdk.exception.CheckmarxException in project checkmarx-spring-boot-java-sdk by checkmarx-ltd.

the class CxLegacyService method getLdapServerId.

Integer getLdapServerId(String session, String serverName) throws CheckmarxException {
    GetLdapServersConfigurations request = new GetLdapServersConfigurations();
    request.setSessionId(session);
    log.debug("Retrieving Ldap Server Configurations");
    GetLdapServersConfigurationsResponse response = (GetLdapServersConfigurationsResponse) ws.marshalSendAndReceive(ws.getDefaultUri(), request, new SoapActionCallback(CX_WS_LDAP_CONFIGURATIONS_URI));
    try {
        if (!response.getGetLdapServersConfigurationsResult().isIsSuccesfull()) {
            log.error(response.getGetLdapServersConfigurationsResult().getErrorMessage());
            throw new CheckmarxException(response.getGetLdapServersConfigurationsResult().getErrorMessage());
        } else {
            List<CxWSLdapServerConfiguration> ldapConfigs = response.getGetLdapServersConfigurationsResult().getServerConfigs().getCxWSLdapServerConfiguration();
            for (CxWSLdapServerConfiguration ldap : ldapConfigs) {
                if (ldap.getName().equalsIgnoreCase(serverName)) {
                    return ldap.getId();
                }
            }
            return -1;
        }
    } catch (NullPointerException e) {
        log.warn("Error occurred getting ldap server configurations");
        throw new CheckmarxException("Error occurred while getting ldap server configurations");
    }
}
Also used : SoapActionCallback(org.springframework.ws.soap.client.core.SoapActionCallback) CheckmarxException(com.checkmarx.sdk.exception.CheckmarxException)

Aggregations

CheckmarxException (com.checkmarx.sdk.exception.CheckmarxException)62 HttpStatusCodeException (org.springframework.web.client.HttpStatusCodeException)23 ScanResults (com.checkmarx.sdk.dto.ScanResults)11 HttpEntity (org.springframework.http.HttpEntity)10 MachinaException (com.checkmarx.flow.exception.MachinaException)8 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 File (java.io.File)6 JSONObject (org.json.JSONObject)6 CxProject (com.checkmarx.sdk.dto.cx.CxProject)5 CxScanParams (com.checkmarx.sdk.dto.cx.CxScanParams)4 IOException (java.io.IOException)4 JAXBContext (javax.xml.bind.JAXBContext)4 JAXBException (javax.xml.bind.JAXBException)4 Unmarshaller (javax.xml.bind.Unmarshaller)4 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 SoapActionCallback (org.springframework.ws.soap.client.core.SoapActionCallback)3 ScanReport (com.checkmarx.flow.dto.report.ScanReport)2