Search in sources :

Example 36 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class ChannelRestConnectionFactory method createUnauthenticatedRestConnection.

public RestConnection createUnauthenticatedRestConnection(final URL url, final IntLogger intLogger, final int timeout) {
    if (url == null) {
        logger.error("URL WAS NULL");
        return null;
    }
    final UnauthenticatedRestConnectionBuilder restConnectionBuilder = new UnauthenticatedRestConnectionBuilder();
    restConnectionBuilder.setBaseUrl(url.toString());
    restConnectionBuilder.setLogger(intLogger);
    if (globalProperties.getHubTrustCertificate() != null) {
        restConnectionBuilder.setAlwaysTrustServerCertificate(globalProperties.getHubTrustCertificate());
    }
    restConnectionBuilder.setProxyHost(globalProperties.getHubProxyHost());
    if (globalProperties.getHubProxyPort() != null) {
        restConnectionBuilder.setProxyPort(NumberUtils.toInt(globalProperties.getHubProxyPort()));
    }
    if (globalProperties.getHubProxyUsername() != null) {
        restConnectionBuilder.setProxyUsername(globalProperties.getHubProxyUsername());
    }
    if (globalProperties.getHubProxyPassword() != null) {
        restConnectionBuilder.setProxyPassword(globalProperties.getHubProxyPassword());
    }
    restConnectionBuilder.setTimeout(timeout);
    final RestConnection connection = restConnectionBuilder.build();
    try {
        // the build operation will catch the issues based on the configuration settings and throw an exception
        // the IntegrationException caught here is unlikely to occur with an UnauthenticatedRestConnection.
        connection.connect();
        return connection;
    } catch (final IntegrationException e) {
        logger.error("Could not connect to " + url.toString(), e);
        return null;
    }
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) UnauthenticatedRestConnectionBuilder(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)

Example 37 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class NotificationItemProcessor method init.

public void init(final GlobalProperties globalProperties, final IntLogger intLogger) {
    HubServicesFactory hubServicesFactory;
    try {
        hubServicesFactory = globalProperties.createHubServicesFactory(intLogger);
        final ProjectService projectService = hubServicesFactory.createProjectService();
        final MapProcessorCache policyCache = new UserNotificationCache(projectService);
        final VulnerabilityCache vulnerabilityCache = new VulnerabilityCache(projectService, hubServicesFactory);
        getCacheList().add(policyCache);
        getCacheList().add(vulnerabilityCache);
        getProcessorMap().put(PolicyViolationContentItem.class, new PolicyViolationProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyViolationClearedContentItem.class, new PolicyViolationClearedProcessor(policyCache, intLogger));
        getProcessorMap().put(PolicyOverrideContentItem.class, new PolicyOverrideProcessor(policyCache, intLogger));
        getProcessorMap().put(VulnerabilityContentItem.class, new VulnerabilityProcessor(vulnerabilityCache, intLogger));
    } catch (final IntegrationException ex) {
        intLogger.error("Error building the notification processor", ex);
    }
}
Also used : HubIntegrationException(com.blackducksoftware.integration.hub.exception.HubIntegrationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HubServicesFactory(com.blackducksoftware.integration.hub.service.HubServicesFactory) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) MapProcessorCache(com.blackducksoftware.integration.hub.notification.MapProcessorCache)

Example 38 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-alert by blackducksoftware.

the class AuditEntryActionsTest method testResendNotificationException.

@Test
public void testResendNotificationException() {
    final AuditEntryRepositoryWrapper auditEntryRepository = Mockito.mock(AuditEntryRepositoryWrapper.class);
    final NotificationRepositoryWrapper notificationRepository = Mockito.mock(NotificationRepositoryWrapper.class);
    final VulnerabilityRepositoryWrapper vulnerabilityRepository = Mockito.mock(VulnerabilityRepositoryWrapper.class);
    final AuditNotificationRepositoryWrapper auditNotificationRepository = Mockito.mock(AuditNotificationRepositoryWrapper.class);
    final CommonDistributionRepositoryWrapper commonDistributionRepositoryWrapper = Mockito.mock(CommonDistributionRepositoryWrapper.class);
    final MockAuditEntryEntity mockAuditEntryEntity = new MockAuditEntryEntity();
    final MockNotificationEntity mockNotificationEntity = new MockNotificationEntity();
    Mockito.when(auditEntryRepository.findOne(Mockito.anyLong())).thenReturn(mockAuditEntryEntity.createEmptyEntity());
    Mockito.when(commonDistributionRepositoryWrapper.findOne(Mockito.anyLong())).thenReturn(null);
    Mockito.when(notificationRepository.findAll(Mockito.any())).thenReturn(Arrays.asList(mockNotificationEntity.createEntity()));
    final AuditEntryActions auditEntryActions = new AuditEntryActions(auditEntryRepository, new NotificationManager(notificationRepository, vulnerabilityRepository, auditEntryRepository, auditNotificationRepository), auditNotificationRepository, commonDistributionRepositoryWrapper, null, null, null, null);
    List<AuditEntryRestModel> restModel = null;
    try {
        restModel = auditEntryActions.resendNotification(1L);
        fail();
    } catch (final IllegalArgumentException e) {
        assertTrue(true);
    } catch (final IntegrationException e) {
        fail();
    }
    assertNull(restModel);
}
Also used : AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) NotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.NotificationRepositoryWrapper) NotificationManager(com.blackducksoftware.integration.hub.alert.NotificationManager) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AuditEntryRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper) CommonDistributionRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper) MockNotificationEntity(com.blackducksoftware.integration.hub.alert.mock.entity.MockNotificationEntity) AuditNotificationRepositoryWrapper(com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper) VulnerabilityRepositoryWrapper(com.blackducksoftware.integration.hub.alert.datasource.entity.repository.VulnerabilityRepositoryWrapper) MockAuditEntryEntity(com.blackducksoftware.integration.hub.alert.audit.mock.MockAuditEntryEntity) Test(org.junit.Test)

Example 39 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-detect by blackducksoftware.

the class HubManager method manageExistingCodeLocations.

public void manageExistingCodeLocations(final List<String> codeLocationNames) {
    if (!detectConfiguration.getHubOfflineMode()) {
        final CodeLocationService codeLocationService = hubServiceWrapper.createCodeLocationService();
        for (final String codeLocationName : codeLocationNames) {
            try {
                final CodeLocationView codeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
                if (detectConfiguration.getProjectCodeLocationDeleteOldNames()) {
                    try {
                        codeLocationService.deleteCodeLocation(codeLocationView);
                        logger.info(String.format("Deleted code location '%s'", codeLocationName));
                    } catch (final IntegrationException e) {
                        logger.error(String.format("Not able to delete the code location '%s': %s", codeLocationName, e.getMessage()));
                    }
                } else {
                    logger.warn(String.format("Found a code location with a naming pattern that is no longer supported: %s. This code location may need to be removed to avoid duplicate entries in the Bill of Materials. You can run with --detect.project.codelocation.delete.old.names=true which will automatically delete these code locations, but please USE CAUTION.", codeLocationName));
                }
            } catch (final DoesNotExistException e) {
                logger.debug(String.format("Didn't find the code location %s - this is a good thing!", codeLocationName));
            } catch (final IntegrationException e) {
                logger.error(String.format("Error finding the code location name %s: %s", codeLocationName, e.getMessage()));
            }
        }
    }
}
Also used : CodeLocationService(com.blackducksoftware.integration.hub.service.CodeLocationService) CodeLocationView(com.blackducksoftware.integration.hub.api.generated.view.CodeLocationView) DoesNotExistException(com.blackducksoftware.integration.hub.exception.DoesNotExistException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException)

Example 40 with IntegrationException

use of com.blackducksoftware.integration.exception.IntegrationException in project hub-detect by blackducksoftware.

the class HubServiceWrapper method assertHubConnection.

public void assertHubConnection(final IntLogger intLogger) throws IntegrationException {
    logger.info("Attempting connection to the Hub");
    try {
        final HubServerConfig hubServerConfig = createHubServerConfig(intLogger);
        final RestConnection connection = hubServerConfig.createRestConnection(intLogger);
        connection.connect();
        logger.info("Connection to the Hub was successful");
    } catch (final IllegalStateException e) {
        throw new IntegrationException(e.getMessage(), e);
    }
}
Also used : RestConnection(com.blackducksoftware.integration.hub.rest.RestConnection) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) HubServerConfig(com.blackducksoftware.integration.hub.configuration.HubServerConfig)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)49 Test (org.junit.Test)21 IOException (java.io.IOException)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)8 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)8 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 HubIntegrationException (com.blackducksoftware.integration.hub.exception.HubIntegrationException)5 ArrayList (java.util.ArrayList)5 Request (com.blackducksoftware.integration.hub.request.Request)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 UpdateFortifyApplicationAttributesRequest (com.blackducksoftware.integration.fortify.model.UpdateFortifyApplicationAttributesRequest)3 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)3 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 File (java.io.File)3 Date (java.util.Date)3