You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2014/12/23 10:11:59 UTC
svn commit: r1647509 - in /manifoldcf/branches/CONNECTORS-1119:
connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/
framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/
framework/pull-agen...
Author: kwright
Date: Tue Dec 23 09:11:59 2014
New Revision: 1647509
URL: http://svn.apache.org/r1647509
Log:
Finish email connector, I hope
Modified:
manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java
manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java
manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java
manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java
Modified: manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java?rev=1647509&r1=1647508&r2=1647509&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java (original)
+++ manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailConnector.java Tue Dec 23 09:11:59 2014
@@ -216,6 +216,45 @@ public class EmailConnector extends org.
//////////////////////////////Start of Notification Connector Method///////////////////////////////////
+ /** Notify of job end.
+ *@param spec is the notification specification.
+ */
+ @Override
+ public void notifyOfJobEnd(Specification spec)
+ throws ManifoldCFException, ServiceInterruption
+ {
+ // Grab the necessary info from the spec
+ final List<String> to = new ArrayList<String>();
+ String from = null;
+ String subject = "";
+ String body = "";
+ for (int i = 0; i < spec.getChildCount(); i++) {
+ SpecificationNode sn = spec.getChild(i);
+ if (sn.getType().equals(EmailConfig.NODE_TO))
+ to.add(sn.getAttributeValue(EmailConfig.ATTRIBUTE_VALUE));
+ else if (sn.getType().equals(EmailConfig.NODE_FROM))
+ from = sn.getAttributeValue(EmailConfig.ATTRIBUTE_VALUE);
+ else if (sn.getType().equals(EmailConfig.NODE_SUBJECT))
+ subject = sn.getAttributeValue(EmailConfig.ATTRIBUTE_VALUE);
+ else if (sn.getType().equals(EmailConfig.NODE_BODY))
+ body = sn.getAttributeValue(EmailConfig.ATTRIBUTE_VALUE);
+ }
+
+ // Construct and send an email
+ getSession();
+
+ SendThread st = new SendThread(session,to,from,subject,body);
+ st.start();
+ try {
+ st.finishUp();
+ } catch (InterruptedException e) {
+ throw new ManifoldCFException(e.getMessage(),ManifoldCFException.INTERRUPTED);
+ } catch (MessagingException e) {
+ handleMessagingException(e,"sending email");
+ }
+ }
+
+
//////////////////////////////End of Notification Connector Methods///////////////////////////////////
@@ -768,6 +807,64 @@ public class EmailConnector extends org.
}
catch (Throwable e)
{
+ exception = e;
+ }
+ }
+
+ public void finishUp()
+ throws MessagingException, InterruptedException
+ {
+ try
+ {
+ join();
+ if (exception != null)
+ {
+ if (exception instanceof RuntimeException)
+ throw (RuntimeException)exception;
+ else if (exception instanceof Error)
+ throw (Error)exception;
+ else if (exception instanceof MessagingException)
+ throw (MessagingException)exception;
+ else
+ throw new RuntimeException("Unknown exception type: "+exception.getClass().getName()+": "+exception.getMessage(),exception);
+ }
+ } catch (InterruptedException e) {
+ this.interrupt();
+ throw e;
+ }
+ }
+ }
+
+ /** Class to send email.
+ */
+ protected static class SendThread extends Thread
+ {
+ protected final EmailSession session;
+ protected final List<String> to;
+ protected final String from;
+ protected final String subject;
+ protected final String body;
+
+ protected Throwable exception = null;
+
+ public SendThread(EmailSession session, List<String> to, String from, String subject, String body)
+ {
+ this.session = session;
+ this.to = to;
+ this.from = from;
+ this.subject = subject;
+ this.body = body;
+ setDaemon(true);
+ }
+
+ public void run()
+ {
+ try
+ {
+ session.send(to,from,subject,body);
+ }
+ catch (Throwable e)
+ {
exception = e;
}
}
Modified: manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java?rev=1647509&r1=1647508&r2=1647509&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java (original)
+++ manifoldcf/branches/CONNECTORS-1119/connectors/email/connector/src/main/java/org/apache/manifoldcf/crawler/notifications/email/EmailSession.java Tue Dec 23 09:11:59 2014
@@ -22,7 +22,7 @@ import java.util.*;
import javax.mail.*;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
-import javax.mail.search.*;
+import javax.mail.internet.InternetAddress;
/** This class represents a raw email session, without any protection
* from threads waiting on sockets, etc.
@@ -60,25 +60,6 @@ public class EmailSession
store = thisStore;
}
- public String[] listFolders()
- throws MessagingException
- {
- if (store != null)
- {
- List<String> folderList = new ArrayList<String>();
- Folder[] folders = store.getDefaultFolder().list("*");
- for (Folder folder : folders)
- {
- if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0)
- folderList.add(folder.getFullName());
- }
- String[] rval = folderList.toArray(new String[0]);
- java.util.Arrays.sort(rval);
- return rval;
- }
- return null;
- }
-
public void checkConnection()
throws MessagingException
{
@@ -90,34 +71,28 @@ public class EmailSession
}
}
- public Folder openFolder(String folderName)
+ public void send(List<String> to, String from, String subject, String body)
throws MessagingException
{
- if (store != null)
- {
- Folder thisFolder = store.getFolder(folderName);
- thisFolder.open(Folder.READ_ONLY);
- return thisFolder;
+ // Create a default MimeMessage object.
+ MimeMessage message = new MimeMessage(session);
+
+ // Set From: header field of the header.
+ message.setFrom(new InternetAddress(from));
+
+ // Set To: header field of the header.
+ for (String toValue : to) {
+ message.addRecipient(Message.RecipientType.TO, new InternetAddress(toValue));
}
- return null;
- }
-
- public void closeFolder(Folder folder)
- throws MessagingException
- {
- folder.close(false);
- }
-
- public Message[] getMessages(Folder folder)
- throws MessagingException
- {
- return folder.getMessages();
- }
-
- public Message[] search(Folder folder, SearchTerm searchTerm)
- throws MessagingException
- {
- return folder.search(searchTerm);
+
+ // Set Subject: header field
+ message.setSubject(subject);
+
+ // Now set the actual message
+ message.setText(body);
+
+ // Send message
+ Transport.send(message);
}
public void close()
Modified: manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java?rev=1647509&r1=1647508&r2=1647509&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java (original)
+++ manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/interfaces/INotificationConnector.java Tue Dec 23 09:11:59 2014
@@ -59,9 +59,10 @@ public interface INotificationConnector
public boolean requestInfo(Configuration output, String command)
throws ManifoldCFException;
- /** Notify of job end.
+ /** Notify of job end
+ *@param spec is the notification specification.
*/
- public void notifyOfJobEnd()
+ public void notifyOfJobEnd(Specification spec)
throws ManifoldCFException, ServiceInterruption;
// UI support methods.
Modified: manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java?rev=1647509&r1=1647508&r2=1647509&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java (original)
+++ manifoldcf/branches/CONNECTORS-1119/framework/pull-agent/src/main/java/org/apache/manifoldcf/crawler/notifications/BaseNotificationConnector.java Tue Dec 23 09:11:59 2014
@@ -65,9 +65,10 @@ public abstract class BaseNotificationCo
}
/** Notify of job end.
+ *@param spec is the notification specification.
*/
@Override
- public void notifyOfJobEnd()
+ public void notifyOfJobEnd(Specification spec)
throws ManifoldCFException, ServiceInterruption
{
}