Search in sources :

Example 16 with RestConnection

use of com.blackducksoftware.integration.hub.rest.RestConnection 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)

Aggregations

RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)16 Test (org.junit.Test)10 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)6 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)5 TestGlobalProperties (com.blackducksoftware.integration.hub.alert.TestGlobalProperties)5 Request (com.blackducksoftware.integration.hub.request.Request)5 ChannelRestConnectionFactory (com.blackducksoftware.integration.hub.alert.channel.rest.ChannelRestConnectionFactory)3 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)3 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)3 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 GlobalProperties (com.blackducksoftware.integration.hub.alert.config.GlobalProperties)2 GlobalHubConfigEntity (com.blackducksoftware.integration.hub.alert.datasource.entity.global.GlobalHubConfigEntity)2 GlobalHubRepositoryWrapper (com.blackducksoftware.integration.hub.alert.datasource.entity.repository.global.GlobalHubRepositoryWrapper)2 GlobalHubConfigRestModel (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigRestModel)2 ObjectTransformer (com.blackducksoftware.integration.hub.alert.web.ObjectTransformer)2 LoginRestModel (com.blackducksoftware.integration.hub.alert.web.model.LoginRestModel)2 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)2 UriCombiner (com.blackducksoftware.integration.hub.rest.UriCombiner)2 HubServicesFactory (com.blackducksoftware.integration.hub.service.HubServicesFactory)2