50 lines
1.6 KiB
Java
50 lines
1.6 KiB
Java
/*
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or (at your
|
|
* option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
package com.inteligr8.alfresco.acs;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
import org.apache.http.client.HttpClient;
|
|
import org.apache.http.client.methods.HttpUriRequest;
|
|
import org.apache.http.client.methods.RequestBuilder;
|
|
import org.apache.http.impl.client.DefaultRedirectStrategy;
|
|
import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
|
import com.inteligr8.rs.ClientConfiguration;
|
|
|
|
public abstract class ConditionalIT {
|
|
|
|
public abstract ClientConfiguration getConfiguration();
|
|
|
|
public boolean hostExists() {
|
|
String uri = this.getConfiguration().getBaseUrl();
|
|
|
|
HttpUriRequest request = RequestBuilder.get()
|
|
.setUri(uri)
|
|
.build();
|
|
|
|
HttpClient client = HttpClientBuilder.create()
|
|
.setRedirectStrategy(DefaultRedirectStrategy.INSTANCE)
|
|
.build();
|
|
|
|
try {
|
|
HttpResponse response = client.execute(request);
|
|
return response.getStatusLine().getStatusCode() < 300;
|
|
} catch (Exception e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
}
|