Permalink
Browse files

Merge branch 'master' of git://github.com/ieb/open-experiments

Conflicts:
	slingtests/osgikernel/bundles/messaging/src/main/java/org/sakaiproject/kernel/api/message/MessageConstants.java
  • Loading branch information...
2 parents cf48d02 + 2ef9b04 commit 27578a71e6cfbd76f89abdc1899001296552870f Simon Gaeremynck committed Sep 16, 2009
Showing with 1,012 additions and 120 deletions.
  1. +1 −1 slingtests/osgikernel/app-bundles/pom.xml
  2. +1 −1 slingtests/osgikernel/bundles/activity/pom.xml
  3. +2 −2 slingtests/osgikernel/bundles/connections/pom.xml
  4. +2 −2 slingtests/osgikernel/bundles/discussion/pom.xml
  5. +6 −0 slingtests/osgikernel/bundles/email-outgoing/pom.xml
  6. +6 −3 ...dles/email-outgoing/src/main/java/org/sakaiproject/kernel/email/outgoing/EmailMessageHandler.java
  7. +80 −54 ...l-outgoing/src/main/java/org/sakaiproject/kernel/email/outgoing/OutgoingEmailMessageListener.java
  8. +58 −0 .../email-outgoing/src/test/java/org/sakaiproject/kernel/email/outgoing/EmailMessageHandlerTest.java
  9. +24 −14 ...tgoing/src/test/java/org/sakaiproject/kernel/email/outgoing/OutgoingEmailMessageListenerTest.java
  10. +7 −6 ...ikernel/bundles/messaging/src/main/java/org/sakaiproject/kernel/api/message/MessageConstants.java
  11. +37 −0 ...undles/messaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageRouteImplTest.java
  12. +28 −0 ...ndles/messaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageRoutesImplTest.java
  13. +77 −0 ...les/messaging/src/test/java/org/sakaiproject/kernel/message/listener/MessageSentListenerTest.java
  14. +1 −1 slingtests/osgikernel/bundles/personal/pom.xml
  15. +4 −0 .../osgikernel/bundles/proxy/src/main/java/org/sakaiproject/kernel/api/proxy/ProxyClientService.java
  16. +14 −3 .../osgikernel/bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImpl.java
  17. +4 −7 ...ikernel/bundles/proxy/src/main/java/org/sakaiproject/kernel/proxy/velocity/JcrResourceLoader.java
  18. +35 −4 ...ikernel/bundles/proxy/src/test/java/org/sakaiproject/kernel/proxy/ProxyClientServiceImplTest.java
  19. +59 −7 .../apache/sling/jcr/jackrabbit/server/impl/security/dynamic/DynamicPrincipalManagerFactoryImpl.java
  20. +30 −2 ...rc/main/java/org/apache/sling/jcr/jackrabbit/server/security/dynamic/DynamicPrincipalManager.java
  21. +2 −1 ...les/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/all-members.json
  22. +2 −1 ...dles/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/contact-us.json
  23. +2 −1 ...es/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/introduction.json
  24. +2 −1 ...les/site/src/main/resources/SLING-INF/content/templates/interdisciplinary/_pages/latest-news.json
  25. +2 −1 ...gikernel/bundles/site/src/main/resources/SLING-INF/content/templates/template/_pages/welcome.json
  26. +2 −2 slingtests/osgikernel/bundles/sling/api/pom.xml
  27. +1 −1 slingtests/osgikernel/bundles/sling/resource/pom.xml
  28. +18 −0 ...rnel/bundles/user/src/main/java/org/sakaiproject/kernel/user/owner/OwnerPrincipalManagerImpl.java
  29. +16 −3 slingtests/osgikernel/libraries/utils/src/main/java/org/sakaiproject/kernel/util/JcrUtils.java
  30. +90 −0 .../osgikernel/libraries/utils/src/main/java/org/sakaiproject/kernel/util/MultiValueInputStream.java
  31. +222 −0 slingtests/osgikernel/libraries/utils/src/test/java/org/sakaiproject/kernel/util/JcrUtilsTest.java
  32. +114 −0 ...ikernel/libraries/utils/src/test/java/org/sakaiproject/kernel/util/MultiValueInputStreamTest.java
  33. +2 −2 slingtests/osgikernel/testscripts/SlingRuby/sling/message.rb
  34. +61 −0 slingtests/osgikernel/testscripts/SlingRuby/tests/send-email-message.rb
@@ -258,7 +258,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
@@ -119,4 +119,4 @@
<version>0.9.0</version>
</dependency>
</dependencies>
-</project>
+</project>
@@ -106,7 +106,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- servlet -->
@@ -168,4 +168,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
+</project>
@@ -122,7 +122,7 @@
<dependency>
<groupId>org.sakaiproject.kernel</groupId>
<artifactId>org.apache.sling.api</artifactId>
- <version>2.0.5-sakai-SNAPSHOT</version>
+ <version>2.0.6-sakai-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- servlet -->
@@ -184,4 +184,4 @@
<scope>provided</scope>
</dependency>
</dependencies>
-</project>
+</project>
@@ -117,5 +117,11 @@
<version>1.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.sakaiproject.kernel</groupId>
+ <artifactId>org.sakaiproject.kernel.utils</artifactId>
+ <version>0.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
@@ -49,23 +49,23 @@
@Reference
protected EventAdmin eventAdmin;
- private static final String TYPE = MessageConstants.TYPE_EMAIL;
+ private static final String TYPE = MessageConstants.TYPE_SMTP;
public String getType() {
return TYPE;
}
/**
* {@inheritDoc}
- *
+ *
* @see org.sakaiproject.kernel.api.message.MessageTransport#send(org.sakaiproject.kernel.api.message.MessageRoutes,
* org.osgi.service.event.Event, javax.jcr.Node)
*/
public void send(MessageRoutes routes, Event event, Node n) {
LOGGER.debug("Started handling an email message");
List<String> recipents = new ArrayList<String>();
for (MessageRoute route : routes) {
- if ("smtp".equals(route.getTransport())) {
+ if (TYPE.equals(route.getTransport())) {
recipents.add(route.getRcpt());
}
}
@@ -82,4 +82,7 @@ public void send(MessageRoutes routes, Event event, Node n) {
}
}
+ protected void bindEventAdmin(EventAdmin eventAdmin) {
+ this.eventAdmin = eventAdmin;
+ }
}
@@ -42,6 +42,8 @@
import java.util.Dictionary;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -69,7 +71,7 @@
public static final String BROKER_URL = "email.out.brokerUrl";
@Property(value = "localhost")
private static final String SMTP_SERVER = "sakai.smtp.server";
- @Property(intValue = 8025, label = "%sakai.smtp.port.name")
+ @Property(intValue = 25, label = "%sakai.smtp.port.name")
private static final String SMTP_PORT = "sakai.smtp.port";
@Property(intValue = 240)
private static final String MAX_RETRIES = "sakai.email.maxRetries";
@@ -109,70 +111,90 @@ public OutgoingEmailMessageListener(ConnectionFactoryService connFactoryService)
this.connFactoryService = connFactoryService;
}
+ @SuppressWarnings("unchecked")
public void onMessage(Message message) {
try {
String nodePath = message.getStringProperty(NODE_PATH_PROPERTY);
- String[] recipients = StringUtils.split(message.getStringProperty(RECIPIENTS),',');
+ Object objRcpt = message.getObjectProperty(RECIPIENTS);
+ List<String> recipients = null;
+
+ if (objRcpt instanceof List<?>) {
+ recipients = (List<String>) objRcpt;
+ } else if (objRcpt instanceof String) {
+ recipients = new LinkedList<String>();
+ String[] rcpts = StringUtils.split((String) objRcpt, ',');
+ for (String rcpt : rcpts) {
+ recipients.add(rcpt);
+ }
+ }
javax.jcr.Session adminSession = repository.loginAdministrative(null);
- ResourceResolver resolver = jcrResourceResolverFactory
- .getResourceResolver(adminSession);
+ ResourceResolver resolver = jcrResourceResolverFactory.getResourceResolver(adminSession);
Node messageNode = resolver.getResource(nodePath).adaptTo(Node.class);
- // validate the message
- if (messageNode != null) {
- if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX)
- && MessageConstants.BOX_OUTBOX.equals(messageNode.getProperty(
- MessageConstants.PROP_SAKAI_MESSAGEBOX).getString())) {
- if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
- // We're retrying this message, so clear the errors
- messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR,
- (String) null);
- }
- if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)
- && messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)) {
- // make a commons-email message from the message
- MultiPartEmail email;
- try {
- email = constructMessage(messageNode, recipients);
-
- email.setSmtpPort(smtpPort);
- email.setHostName(smtpServer);
-
- email.send();
- } catch (EmailException e) {
- setError(messageNode, e.getMessage());
- // Get the SMTP error code
- // There has to be a better way to do this
- if (e.getCause() != null && e.getCause().getMessage() != null) {
- String smtpError = e.getCause().getMessage().trim();
- try {
- int errorCode = Integer.parseInt(smtpError.substring(0, 3));
- // All retry-able SMTP errors should have codes starting with 4
- scheduleRetry(errorCode, messageNode);
- } catch (NumberFormatException nfe) {
- // smtpError didn't start with an error code, let's dig for it
- String searchFor = "response:";
- int rindex = smtpError.indexOf(searchFor);
- if (rindex > -1 && (rindex + searchFor.length()) < smtpError.length()) {
- int errorCode = Integer.parseInt(smtpError.substring(searchFor
- .length(), searchFor.length() + 3));
+ if (objRcpt != null) {
+ // validate the message
+ if (messageNode != null) {
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX)
+ && MessageConstants.BOX_OUTBOX.equals(messageNode.getProperty(
+ MessageConstants.PROP_SAKAI_MESSAGEBOX).getString())) {
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
+ // We're retrying this message, so clear the errors
+ messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR, (String) null);
+ }
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO)
+ && messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)) {
+ // make a commons-email message from the message
+ MultiPartEmail email;
+ try {
+ email = constructMessage(messageNode, recipients);
+
+ email.setSmtpPort(smtpPort);
+ email.setHostName(smtpServer);
+
+ email.send();
+ } catch (EmailException e) {
+ setError(messageNode, e.getMessage());
+ // Get the SMTP error code
+ // There has to be a better way to do this
+ if (e.getCause() != null && e.getCause().getMessage() != null) {
+ String smtpError = e.getCause().getMessage().trim();
+ try {
+ int errorCode = Integer.parseInt(smtpError.substring(0, 3));
+ // All retry-able SMTP errors should have codes starting
+ // with 4
scheduleRetry(errorCode, messageNode);
+ } catch (NumberFormatException nfe) {
+ // smtpError didn't start with an error code, let's dig for
+ // it
+ String searchFor = "response:";
+ int rindex = smtpError.indexOf(searchFor);
+ if (rindex > -1 && (rindex + searchFor.length()) < smtpError.length()) {
+ int errorCode = Integer.parseInt(smtpError.substring(searchFor.length(),
+ searchFor.length() + 3));
+ scheduleRetry(errorCode, messageNode);
+ }
}
}
}
+ } else {
+ setError(messageNode, "Message must have a to and from set");
}
} else {
- setError(messageNode, "Message must have a to and from set");
+ setError(messageNode, "Not an outbox");
+ }
+ if (!messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
+ messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX,
+ MessageConstants.BOX_SENT);
}
- } else {
- setError(messageNode, "Not an outbox");
}
- if (!messageNode.hasProperty(MessageConstants.PROP_SAKAI_MESSAGEERROR)) {
- messageNode.setProperty(MessageConstants.PROP_SAKAI_MESSAGEBOX,
- MessageConstants.BOX_SENT);
+ } else {
+ String retval = "null";
+ if (objRcpt != null) {
+ retval = objRcpt.getClass().toString();
}
+ setError(messageNode, "Expected recipients to be String or List<String>. Found " + retval);
}
} catch (JMSException e) {
LOGGER.error(e.getMessage(), e);
@@ -181,18 +203,19 @@ public void onMessage(Message message) {
}
}
- private MultiPartEmail constructMessage(Node messageNode, String[] recipients) throws EmailException,
+ private MultiPartEmail constructMessage(Node messageNode, List<String> recipients)
+ throws EmailException,
RepositoryException, PathNotFoundException, ValueFormatException {
MultiPartEmail email = new MultiPartEmail();
//TODO: the SAKAI_TO may make no sense in an email context
// and there does not appear to be any distinction between Bcc and To in java mail.
-
+
Set<String> toRecipients = new HashSet<String>();
Set<String> bccRecipients = new HashSet<String>();
for ( String r : recipients ) {
bccRecipients.add(r.trim());
}
-
+
if ( messageNode.hasProperty(MessageConstants.PROP_SAKAI_TO) ) {
String[] tor = StringUtils.split(messageNode.getProperty(MessageConstants.PROP_SAKAI_TO).getString(),',');
for ( String r : tor ) {
@@ -209,10 +232,13 @@ private MultiPartEmail constructMessage(Node messageNode, String[] recipients) t
for ( String r : bccRecipients ) {
email.addBcc(r);
}
-
-
- email.setFrom(messageNode.getProperty(MessageConstants.PROP_SAKAI_FROM).getString());
+ if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_FROM)) {
+ String from = messageNode.getProperty(MessageConstants.PROP_SAKAI_FROM).getString();
+ email.setFrom(from);
+ } else {
+ throw new EmailException("Must provide a 'from' address.");
+ }
if (messageNode.hasProperty(MessageConstants.PROP_SAKAI_BODY)) {
email.setMsg(messageNode.getProperty(MessageConstants.PROP_SAKAI_BODY).getString());
@@ -0,0 +1,58 @@
+package org.sakaiproject.kernel.email.outgoing;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.sakaiproject.kernel.api.message.MessageConstants;
+import org.sakaiproject.kernel.api.message.MessageRoutes;
+import org.sakaiproject.kernel.message.listener.MessageRoutesImpl;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+
+public class EmailMessageHandlerTest {
+
+ private EmailMessageHandler emh;
+
+ @Before
+ public void setup() {
+ EventAdmin eventAdmin = createMock(EventAdmin.class);
+ eventAdmin.postEvent(isA(Event.class));
+ expectLastCall();
+
+ replay(eventAdmin);
+
+ emh = new EmailMessageHandler();
+ emh.bindEventAdmin(eventAdmin);
+ }
+
+ @Test
+ public void testSend() throws Exception {
+ Property prop = createMock(Property.class);
+ expect(prop.getString()).andReturn("smtp:foo@localhost");
+
+ Node node = createMock(Node.class);
+ expect(node.getProperty(MessageConstants.PROP_SAKAI_TO)).andReturn(prop);
+ expect(node.getPath()).andReturn("/foo");
+
+ replay(prop, node);
+ MessageRoutes routes = new MessageRoutesImpl(node);
+
+ emh.send(routes, null, node);
+ verify(prop, node);
+ }
+
+ @Test
+ public void testGetType() {
+ assertEquals(MessageConstants.TYPE_SMTP, emh.getType());
+ }
+}
Oops, something went wrong.

0 comments on commit 27578a7

Please sign in to comment.