Search in sources :

Example 21 with IntegrationException

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

the class ChannelRequestHelper method sendGenericRequest.

public Response sendGenericRequest(final Request request) throws IntegrationException {
    Response response = null;
    try {
        final HubService service = hubServicesFactory.createHubService();
        response = service.executeRequest(request);
        logger.trace("Response: " + response.toString());
        return response;
    } catch (final Exception generalException) {
        logger.error("Error sending request", generalException);
        throw new AlertException(generalException.getMessage());
    }
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) HubService(com.blackducksoftware.integration.hub.service.HubService) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) AlertException(com.blackducksoftware.integration.hub.alert.exception.AlertException)

Example 22 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 23 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 24 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)

Aggregations

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)24 Test (org.junit.Test)12 ChannelTest (com.blackducksoftware.integration.hub.alert.channel.ChannelTest)5 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)5 AlertException (com.blackducksoftware.integration.hub.alert.exception.AlertException)4 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)4 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)3 AuditEntryRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditEntryRepositoryWrapper)3 GlobalHipChatConfigEntity (com.blackducksoftware.integration.hub.alert.channel.hipchat.repository.global.GlobalHipChatConfigEntity)3 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)3 CommonDistributionRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.CommonDistributionRepositoryWrapper)3 ProjectData (com.blackducksoftware.integration.hub.alert.digest.model.ProjectData)3 Request (com.blackducksoftware.integration.hub.request.Request)3 UserGroupService (com.blackducksoftware.integration.hub.service.UserGroupService)3 ExternalConnectionTest (com.blackducksoftware.integration.test.annotation.ExternalConnectionTest)3 HashMap (java.util.HashMap)3 NotificationManager (com.blackducksoftware.integration.hub.alert.NotificationManager)2 AuditNotificationRepositoryWrapper (com.blackducksoftware.integration.hub.alert.audit.repository.AuditNotificationRepositoryWrapper)2 CommonDistributionConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.CommonDistributionConfigEntity)2