Search in sources :

Example 1 with UnauthenticatedRestConnectionBuilder

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

IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 UnauthenticatedRestConnectionBuilder (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)1