102 lines
3.0 KiB
Java
102 lines
3.0 KiB
Java
|
package org.gcube.dataanalysis.dataminer.poolmanager.util;
|
||
|
|
||
|
import java.net.URLEncoder;
|
||
|
|
||
|
import org.apache.activemq.transport.stomp.Stomp.Headers.Send;
|
||
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||
|
import org.gcube.contentmanagement.graphtools.utils.HttpRequest;
|
||
|
import org.gcube.contentmanagement.lexicalmatcher.utils.AnalysisLogger;
|
||
|
import org.gcube.dataanalysis.ecoengine.interfaces.StandardLocalInfraAlgorithm;
|
||
|
import org.gcube.dataanalysis.executor.util.InfraRetrieval;
|
||
|
|
||
|
public class SendMail extends StandardLocalInfraAlgorithm {
|
||
|
|
||
|
public SendMail() {
|
||
|
// TODO Auto-generated constructor stub
|
||
|
}
|
||
|
|
||
|
public void sendNotification(String subject, String body) throws Exception {
|
||
|
|
||
|
AnalysisLogger.getLogger().debug("Emailing System->Starting request of email in scope "+ScopeProvider.instance.get());
|
||
|
|
||
|
String serviceAddress = InfraRetrieval.findEmailingSystemAddress(ScopeProvider.instance.get());
|
||
|
|
||
|
if (!serviceAddress.endsWith("/"))
|
||
|
serviceAddress = serviceAddress+"/";
|
||
|
|
||
|
String requestForMessage = serviceAddress + "messages/writeMessageToUsers" + "?gcube-token=" + SecurityTokenProvider.instance.get();
|
||
|
requestForMessage = requestForMessage.replace("http://", "https://").replace(":80", ""); // remove the port (or set it to 443) otherwise you get an SSL error
|
||
|
|
||
|
AnalysisLogger.getLogger().debug("Emailing System->Request url is going to be " + requestForMessage);
|
||
|
|
||
|
// put the sender, the recipients, subject and body of the mail here
|
||
|
subject=URLEncoder.encode(subject,"UTF-8");
|
||
|
body=URLEncoder.encode(body,"UTF-8");
|
||
|
String requestParameters = "sender=dataminer&recipients="+SecurityTokenProvider.instance.get()+"&subject="+subject+"&body="+body;
|
||
|
|
||
|
String response = HttpRequest.sendPostRequest(requestForMessage, requestParameters);
|
||
|
AnalysisLogger.getLogger().debug("Emailing System->Emailing response OK ");
|
||
|
|
||
|
if (response==null){
|
||
|
Exception e = new Exception("Error in email sending response");
|
||
|
throw e;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// public void notifySubmitter(String a, String b) throws Exception {
|
||
|
// NotificationHelper nh = new NotificationHelper();
|
||
|
// super.sendNotification(nh.getSubject(),
|
||
|
// nh.getBody());
|
||
|
// }
|
||
|
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public String getDescription() {
|
||
|
// TODO Auto-generated method stub
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void init() throws Exception {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
@Override
|
||
|
protected void process() throws Exception {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
@Override
|
||
|
protected void setInputParameters() {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
@Override
|
||
|
public void shutdown() {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
public static void main(String[] args) throws Exception {
|
||
|
ScopeProvider.instance.set("/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab");
|
||
|
SecurityTokenProvider.instance.set("3a23bfa4-4dfe-44fc-988f-194b91071dd2-843339462");
|
||
|
|
||
|
NotificationHelper nh = new NotificationHelper();
|
||
|
SendMail sm = new SendMail();
|
||
|
sm.sendNotification(nh.getSubject(), nh.getBody());
|
||
|
}
|
||
|
}
|