Search in sources :

Example 11 with Response

use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.

the class ProxyTestService method pingHost.

public ConfigurationTestResult pingHost(String testUrl, SettingsProxyModel settingsProxyModel) {
    ProxyInfo proxyInfo = proxyManager.createProxyInfo(settingsProxyModel);
    IntHttpClient client = createIntHttpClient(proxyInfo);
    try {
        HttpUrl httpUrl = new HttpUrl(testUrl);
        Request testRequest = new Request.Builder(httpUrl).build();
        Response response = client.execute(testRequest);
        if (RestConstants.OK_200 >= response.getStatusCode() && response.getStatusCode() < RestConstants.MULT_CHOICE_300) {
            logger.info("Successfully pinged {}!", testUrl);
            return ConfigurationTestResult.success();
        } else {
            return ConfigurationTestResult.failure(String.format("Could not ping: %s. Status Message: %s. Status code: %s", testUrl, response.getStatusMessage(), response.getStatusCode()));
        }
    } catch (IntegrationException e) {
        logger.error(e.getMessage(), e);
        return ConfigurationTestResult.failure(e.getMessage());
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Aggregations

Response (com.synopsys.integration.rest.response.Response)11 Request (com.synopsys.integration.rest.request.Request)6 IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)5 Test (org.junit.jupiter.api.Test)4 DockerTagsResponseModel (com.synopsys.integration.alert.update.model.DockerTagsResponseModel)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 BodyContent (com.synopsys.integration.rest.body.BodyContent)2 StringBodyContent (com.synopsys.integration.rest.body.StringBodyContent)2 IOException (java.io.IOException)2 TestTags (com.synopsys.integration.alert.test.common.TestTags)1 DockerTagModel (com.synopsys.integration.alert.update.model.DockerTagModel)1 IntLogger (com.synopsys.integration.log.IntLogger)1 PrintStreamIntLogger (com.synopsys.integration.log.PrintStreamIntLogger)1 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)1 Tags (org.junit.jupiter.api.Tags)1