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
This commit is contained in:
parent
1ce0c9e5a1
commit
bf45eed5ab
|
@ -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<String> urlsToContact;
|
||||
|
||||
|
||||
public GetCaller(List<String> 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue