package org.gcube.portal; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; public class GetCaller extends Thread { private final int MINUTES_4_MILLISECONDS = 240000; private final static String USER_AGENT = "Mozilla/5.0"; private List urlsToContact; public GetCaller(List 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) { String response = sendGet(url); System.out.println("**********\n\n"+ "Called URL=" + url + " correctly, response:" + response); } String response_ldap = sendGet(ServletTrigger.SERVLET_URL_LDAP); System.out.println("**********\n\n"+ "Called URL=" + ServletTrigger.SERVLET_URL_LDAP + " correctly, response: " + response_ldap); } catch (Exception e) { e.printStackTrace(); } } private String sendGet(String url) throws Exception { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 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(); } }