private SSLContext sslContext;
public char monitor(Host host) {
HttpHost httpHost = (HttpHost) host;
HttpURLConnection http = null;
BufferedInputStream bis = null;
try {
String urlString = null;
if (httpHost.isSecure()) {
urlString = "https://";
} else {
urlString = "http://";
}
urlString = urlString + httpHost.getInetAddress().getHostAddress()
+ ":" + httpHost.getInetSocketAddress().getPort() + httpHost.getUri();
URL url = new URL(urlString);
http = (HttpURLConnection) url.openConnection();
if (httpHost.isSecure()) {
HttpsURLConnection https = (HttpsURLConnection) http;
makeSSLSocketFactory();
https.setSSLSocketFactory(sslSocketFactory);
https.setHostnameVerifier(vf);
}
http.setRequestMethod("GET");
http.setDoOutput(true);
http.setReadTimeout(httpHost.getTimeout());
http.connect();
String httpResponseCode = "" + http.getResponseCode();
if(httpResponseCode.equals(httpHost.getHttpStatusCode())==false) {
logger.fine("StatusCode does not match.. got "+httpResponseCode+
", expected: "+httpHost.getHttpStatusCode());
return Host.DOWN;
}
if (httpHost.getTextToExpect() != null) {
InputStream is = http.getErrorStream();
if(is==null) {
is = http.getInputStream();
}
bis = new BufferedInputStream(is);
String textGot = new String(BlockingClient.readInputStream(bis), "utf-8");
if (textGot.indexOf(httpHost.getTextToExpect()) != -1) {
return Host.ACTIVE;
} else {
logger.fine(httpHost + " Error: Text [" + httpHost.getTextToExpect()
+ "]Not found! Got: " + textGot);
return Host.DOWN;
}
} else {
return Host.ACTIVE;
}
} catch (IOException e) {
logger.fine(httpHost + " IOError: " + e);
return Host.DOWN;
} catch (Exception e) {
logger.warning(httpHost + " Error: " + e);
return Host.ERROR;
} finally {
if(bis!=null) {
try {
bis.close();
} catch (IOException ex) {
Logger.getLogger(HttpMonitor.class.getName()).log(Level.SEVERE, null, ex);
}
}
if (http != null) {