2016-05-19 00:15:16 +02:00
|
|
|
package org.gcube.portal;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.List;
|
2016-07-27 18:49:47 +02:00
|
|
|
|
2016-07-26 16:07:16 +02:00
|
|
|
import org.gcube.portal.SSLUtilities;
|
2016-07-27 18:49:47 +02:00
|
|
|
|
2016-07-26 15:26:45 +02:00
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
|
2016-05-19 00:15:16 +02:00
|
|
|
public class GetCaller extends Thread {
|
2016-07-27 18:49:47 +02:00
|
|
|
private final int MINUTES_4_MILLISECONDS = 480000;
|
|
|
|
|
2016-05-19 00:15:16 +02:00
|
|
|
private final static String USER_AGENT = "Mozilla/5.0";
|
2016-07-27 18:49:47 +02:00
|
|
|
|
|
|
|
protected static final String SERVLET_CONTEXT_MAIL = "/social-mail-servlet/start-email-reader";
|
|
|
|
protected static final String SERVLET_URL_LDAP = "/ldap-export-servlet/start-ldap-export";
|
|
|
|
|
2016-05-19 00:15:16 +02:00
|
|
|
private List<String> urlsToContact;
|
2016-07-27 18:49:47 +02:00
|
|
|
|
2016-05-19 00:15:16 +02:00
|
|
|
public GetCaller(List<String> urlsToContact) {
|
|
|
|
super();
|
|
|
|
this.urlsToContact = urlsToContact;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
System.out.println("********** READING MAILS THREAD Waiting ... starting in " + MINUTES_4_MILLISECONDS/60000 + " minutes");
|
|
|
|
System.out.println("********** LDAP EXPORT THREAD Waiting ... starting in " + MINUTES_4_MILLISECONDS/60000 + " minutes");
|
|
|
|
Thread.sleep(MINUTES_4_MILLISECONDS);
|
|
|
|
for (String url : urlsToContact) {
|
2016-07-27 18:49:47 +02:00
|
|
|
String response = sendHTTPsGet(url+SERVLET_CONTEXT_MAIL);
|
2016-05-19 00:15:16 +02:00
|
|
|
System.out.println("**********\n\n"+ "Called URL=" + url + " correctly, response:" + response);
|
|
|
|
}
|
2016-07-27 18:49:47 +02:00
|
|
|
if (!urlsToContact.isEmpty()) {
|
|
|
|
String response_ldap = sendHTTPsGet(urlsToContact.get(0)+SERVLET_URL_LDAP);
|
|
|
|
System.out.println("**********\n\n"+ "Called URL=" + urlsToContact.get(0)+SERVLET_URL_LDAP + " correctly, response: " + response_ldap);
|
|
|
|
} else {
|
|
|
|
System.out.println("The list of virtualHost was empty");
|
|
|
|
}
|
2016-05-19 00:15:16 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2016-07-27 18:49:47 +02:00
|
|
|
|
2016-05-19 00:15:16 +02:00
|
|
|
}
|
2016-07-27 18:49:47 +02:00
|
|
|
|
2016-07-26 15:26:45 +02:00
|
|
|
private String sendHTTPsGet(String url) throws Exception {
|
|
|
|
|
|
|
|
URL obj = new URL(null, url, new sun.net.www.protocol.https.Handler());
|
|
|
|
|
|
|
|
SSLUtilities.trustAllHostnames();
|
|
|
|
SSLUtilities.trustAllHttpsCertificates();
|
|
|
|
|
2016-07-27 18:49:47 +02:00
|
|
|
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
|
2016-05-19 00:15:16 +02:00
|
|
|
con.setRequestProperty("User-Agent", USER_AGENT);
|
|
|
|
int responseCode = con.getResponseCode();
|
|
|
|
System.out.println("\nSending 'GET' request to URL : " + url);
|
|
|
|
System.out.println("Response Code : " + responseCode);
|
|
|
|
|
|
|
|
BufferedReader in = new BufferedReader(
|
|
|
|
new InputStreamReader(con.getInputStream()));
|
|
|
|
String inputLine;
|
|
|
|
StringBuffer response = new StringBuffer();
|
|
|
|
|
|
|
|
while ((inputLine = in.readLine()) != null) {
|
|
|
|
response.append(inputLine);
|
|
|
|
}
|
|
|
|
in.close();
|
|
|
|
return response.toString();
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 15:26:45 +02:00
|
|
|
|
|
|
|
|