65 lines
2.0 KiB
Java
65 lines
2.0 KiB
Java
package org.gcube.portal;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import com.liferay.portal.kernel.events.ActionException;
|
|
import com.liferay.portal.kernel.events.SimpleAction;
|
|
import com.liferay.portal.model.VirtualHost;
|
|
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:9090/ldap-export-servlet/start-ldap-export";
|
|
|
|
private final String PROTOCOL = "http://";
|
|
private final String PORT = "9090";
|
|
|
|
/* (non-Java-doc)
|
|
* @see com.liferay.portal.kernel.events.SimpleAction#SimpleAction()
|
|
*/
|
|
public ServletTrigger() {
|
|
super();
|
|
}
|
|
|
|
/* (non-Java-doc)
|
|
* @see com.liferay.portal.kernel.events.SimpleAction#run(String[] arg0)
|
|
*/
|
|
public void run(String[] arg0) throws ActionException {
|
|
try {
|
|
List<String> urlsToContact = getVirtualHostURLs();
|
|
GetCaller gc = new GetCaller(urlsToContact);
|
|
gc.start();
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
/**
|
|
* I am containg the same servlet for each vHost
|
|
* @return
|
|
*/
|
|
private List<String> getVirtualHostURLs() {
|
|
List<String> toReturn = new ArrayList<String>();
|
|
List<VirtualHost> vHosts = null;
|
|
try {
|
|
vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount());
|
|
for (VirtualHost virtualHost : vHosts) {
|
|
if (virtualHost.getHostname().compareTo("localhost") != 0 && virtualHost.getLayoutSetId() != 0) {
|
|
String hostToContact = PROTOCOL+virtualHost.getHostname()+":"+PORT;
|
|
toReturn.add(hostToContact+SERVLET_CONTEXT_MAIL);
|
|
_log.debug("Added host to contact: " + hostToContact);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
return toReturn;
|
|
}
|
|
|
|
} |