From bf45eed5ab3dee391da9d4c7417d41a606b8b2e4 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Wed, 27 Jul 2016 16:49:47 +0000 Subject: [PATCH] fixed so that it correctly calls the v hosts with the new deployment scheme git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/liferay62-plugins/mail-reader-lr62@130865 82a268e6-3cf1-43bd-a215-b396298e98cf --- src/main/java/org/gcube/portal/GetCaller.java | 48 ++++++++----------- .../java/org/gcube/portal/ServletTrigger.java | 5 +- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/gcube/portal/GetCaller.java b/src/main/java/org/gcube/portal/GetCaller.java index 63ff7d7..8ac0f8b 100644 --- a/src/main/java/org/gcube/portal/GetCaller.java +++ b/src/main/java/org/gcube/portal/GetCaller.java @@ -5,15 +5,21 @@ import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; + import org.gcube.portal.SSLUtilities; + import javax.net.ssl.HttpsURLConnection; public class GetCaller extends Thread { - private final int MINUTES_4_MILLISECONDS = 180000; + private final int MINUTES_4_MILLISECONDS = 480000; + private final static String USER_AGENT = "Mozilla/5.0"; - + + 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"; + private List urlsToContact; - + public GetCaller(List urlsToContact) { super(); this.urlsToContact = urlsToContact; @@ -28,24 +34,28 @@ public class GetCaller extends Thread { 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 = sendHTTPsGet(url); + String response = sendHTTPsGet(url+SERVLET_CONTEXT_MAIL); 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); + 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"); + } } catch (Exception e) { e.printStackTrace(); } - + } - + private String sendHTTPsGet(String url) throws Exception { URL obj = new URL(null, url, new sun.net.www.protocol.https.Handler()); SSLUtilities.trustAllHostnames(); SSLUtilities.trustAllHttpsCertificates(); - + HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); con.setRequestProperty("User-Agent", USER_AGENT); int responseCode = con.getResponseCode(); @@ -63,26 +73,6 @@ public class GetCaller extends Thread { in.close(); return response.toString(); } - - 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(); - } } diff --git a/src/main/java/org/gcube/portal/ServletTrigger.java b/src/main/java/org/gcube/portal/ServletTrigger.java index 7a4f16a..4a56aba 100644 --- a/src/main/java/org/gcube/portal/ServletTrigger.java +++ b/src/main/java/org/gcube/portal/ServletTrigger.java @@ -14,9 +14,6 @@ import com.liferay.portal.service.VirtualHostLocalServiceUtil; public class ServletTrigger extends SimpleAction { private static final Logger _log = LoggerFactory.getLogger(ServletTrigger.class); - protected static final String SERVLET_CONTEXT_MAIL = "/social-mail-servlet/start-email-reader"; - protected static final String SERVLET_URL_LDAP = "http://localhost/ldap-export-servlet/start-ldap-export"; - private final String PROTOCOL = "https://"; /* (non-Java-doc) @@ -52,7 +49,7 @@ public class ServletTrigger extends SimpleAction { for (VirtualHost virtualHost : vHosts) { if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0) { String hostToContact = PROTOCOL+virtualHost.getHostname(); - toReturn.add(hostToContact+SERVLET_CONTEXT_MAIL); + toReturn.add(hostToContact); _log.info("Added host to contact: " + hostToContact); } }