[kune-commits] r1536 - in trunk: . src/main/java/cc/kune/core/server src/main/java/cc/kune/core/server/mail src/main/java/cc/kune/core/server/manager/impl src/main/java/cc/kune/core/server/properties src/main/resources

Vicente J. Ruiz Jurado vjrj_ at ourproject.org
Tue Sep 27 00:39:07 CEST 2011


Author: vjrj_
Date: 2011-09-27 00:39:06 +0200 (Tue, 27 Sep 2011)
New Revision: 1536

Added:
   trunk/src/main/java/cc/kune/core/server/mail/MailService.java
   trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java
Removed:
   trunk/src/main/java/cc/kune/core/server/mail/MailManager.java
   trunk/src/main/java/cc/kune/core/server/mail/MailManagerDefault.java
Modified:
   trunk/.classpath
   trunk/INSTALL
   trunk/pom.xml
   trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java
   trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java
   trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java
   trunk/src/main/resources/kune.properties
Log:
NEW - # 128: Remove /ws/ prefix in kune URL 
http://kune.ourproject.org/issues/ticket/128
CLOSED - # 129: Add some simple mail lib utility in serverside 
http://kune.ourproject.org/issues/ticket/129

Modified: trunk/.classpath
===================================================================
--- trunk/.classpath	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/.classpath	2011-09-26 22:39:06 UTC (rev 1536)
@@ -3,13 +3,14 @@
   <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
   <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
   <classpathentry kind="output" path="target/kune-0.1.0-SNAPSHOT/WEB-INF/classes"/>
+  <classpathentry kind="var" path="M2_REPO/javax/activation/activation/1.1/activation-1.1.jar" sourcepath="M2_REPO/javax/activation/activation/1.1/activation-1.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar" sourcepath="M2_REPO/javax/inject/javax.inject/1/javax.inject-1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/javax/transaction/jta/1.1/jta-1.1.jar" sourcepath="M2_REPO/javax/transaction/jta/1.1/jta-1.1-sources.jar"/>
+  <classpathentry kind="var" path="M2_REPO/javax/mail/mail/1.4.4/mail-1.4.4.jar" sourcepath="M2_REPO/javax/mail/mail/1.4.4/mail-1.4.4-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/javax/persistence/persistence-api/1.0/persistence-api-1.0.jar" sourcepath="M2_REPO/javax/persistence/persistence-api/1.0/persistence-api-1.0-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5.jar" sourcepath="M2_REPO/javax/servlet/servlet-api/2.5/servlet-api-2.5-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6.jar" sourcepath="M2_REPO/antlr/antlr/2.7.6/antlr-2.7.6-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/com/google/appengine/appengine-api-1.0-sdk/1.3.1/appengine-api-1.0-sdk-1.3.1.jar"/>
   <classpathentry kind="var" path="M2_REPO/avalon-framework/avalon-framework/4.1.3/avalon-framework-4.1.3.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/waveprotocol/box/0.3.2/box-0.3.2.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/waveprotocol/box-src/0.3.2/box-src-0.3.2.jar"/>
@@ -34,7 +35,6 @@
   <classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1.jar" sourcepath="M2_REPO/commons-logging/commons-logging/1.1/commons-logging-1.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/waveprotocol/communication-src/0.3.2/communication-src-0.3.2.jar"/>
   <classpathentry kind="var" path="M2_REPO/org/waveprotocol/concurrencycontrol-src/0.3.2/concurrencycontrol-src-0.3.2.jar"/>
-  <classpathentry kind="var" path="M2_REPO/net/sourceforge/htmlunit/crawl_htmlunit/r5662-gae/crawl_htmlunit-r5662-gae.jar"/>
   <classpathentry kind="var" path="M2_REPO/net/sourceforge/cssparser/cssparser/0.9.5/cssparser-0.9.5.jar" sourcepath="M2_REPO/net/sourceforge/cssparser/cssparser/0.9.5/cssparser-0.9.5-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar" sourcepath="M2_REPO/dom4j/dom4j/1.6.1/dom4j-1.6.1-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/net/sf/dozer/dozer/4.0/dozer-4.0.jar" sourcepath="M2_REPO/net/sf/dozer/dozer/4.0/dozer-4.0-sources.jar"/>
@@ -59,7 +59,6 @@
   <classpathentry kind="var" path="M2_REPO/com/allen_sauer/gwt/voices/gwt-voices/gwt-voices/2.0.0/gwt-voices-2.0.0.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-all/0.5/gwtp-all-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-all/0.5/gwtp-all-0.5-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-clients-common/0.5/gwtp-clients-common-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-clients-common/0.5/gwtp-clients-common-0.5-sources.jar"/>
-  <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-crawler/0.5/gwtp-crawler-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-crawler/0.5/gwtp-crawler-0.5-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-dispatch-client/0.5/gwtp-dispatch-client-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-dispatch-client/0.5/gwtp-dispatch-client-0.5-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-dispatch-server/0.5/gwtp-dispatch-server-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-dispatch-server/0.5/gwtp-dispatch-server-0.5-sources.jar"/>
   <classpathentry kind="var" path="M2_REPO/com/gwtplatform/gwtp-dispatch-shared/0.5/gwtp-dispatch-shared-0.5.jar" sourcepath="M2_REPO/com/gwtplatform/gwtp-dispatch-shared/0.5/gwtp-dispatch-shared-0.5-sources.jar"/>

Modified: trunk/INSTALL
===================================================================
--- trunk/INSTALL	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/INSTALL	2011-09-26 22:39:06 UTC (rev 1536)
@@ -289,3 +289,16 @@
         Allow from all
     </Location>
 </VirtualHost>
+
+==Appendix C: Configure your SMTP mail server==
+
+You should configure a SMTP server for use by Kune. See kune.site.smtp.* in kune.properties and check that your email system works propertly. For instance test something like:
+
+ echo "Bests," | mailx -s "Testing mail in kune instalation" PUT_HERE at YOUR_EMAIL # or something similar 
+
+http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#ProtocolSMTP
+http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#JavaMailSending
+
+And: 
+http://javamail.kenai.com/nonav/javadocs/com/sun/mail/smtp/package-summary.html
+for more specific configuration parameters that maybe you need with your smtp server.
\ No newline at end of file

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/pom.xml	2011-09-26 22:39:06 UTC (rev 1536)
@@ -235,6 +235,14 @@
           <groupId>org.springframework</groupId>
           <artifactId>spring-web</artifactId>
         </exclusion>
+        <exclusion>
+          <groupId>com.gwtplatform</groupId>
+          <artifactId>gwtp-crawler-service</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>com.gwtplatform</groupId>
+          <artifactId>gwtp-crawler</artifactId>
+        </exclusion>
       </exclusions>
     </dependency>
     <dependency>
@@ -638,6 +646,12 @@
       <version>0.6.3-compat</version>
     </dependency>
     <!-- end gwtupload -->
+    <!-- others -->
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+      <version>1.4.4</version>
+    </dependency>
   </dependencies>
 
   <!-- <dependency> -->
@@ -958,7 +972,8 @@
           </modules>
           <copyWebapp>true</copyWebapp>
           <compileReport>false</compileReport>
-          <localWorkers>1</localWorkers><!-- Using all workers can temporarily hang the mouse and isn't much faster -->
+          <localWorkers>1</localWorkers><!-- Using all workers can temporarily
+            hang the mouse and isn't much faster -->
           <extraJvmArgs>-Xmx1024m</extraJvmArgs>
         </configuration>
         <executions>

Modified: trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/src/main/java/cc/kune/core/server/PlatformServerModule.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -49,6 +49,8 @@
 import cc.kune.core.server.content.CreationServiceDefault;
 import cc.kune.core.server.content.XMLActionReader;
 import cc.kune.core.server.i18n.I18nTranslationServiceDefault;
+import cc.kune.core.server.mail.MailService;
+import cc.kune.core.server.mail.MailServiceDefault;
 import cc.kune.core.server.manager.ExtMediaDescripManager;
 import cc.kune.core.server.manager.FileManager;
 import cc.kune.core.server.manager.GroupManager;
@@ -158,6 +160,7 @@
     bind(StateService.class).to(StateServiceDefault.class);
     bind(I18nTranslationService.class).to(I18nTranslationServiceDefault.class);
     bind(KuneWaveService.class).to(KuneWaveServiceDefault.class);
+    bind(MailService.class).to(MailServiceDefault.class);
     bind(XMLActionReader.class);
   }
 

Deleted: trunk/src/main/java/cc/kune/core/server/mail/MailManager.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/mail/MailManager.java	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/src/main/java/cc/kune/core/server/mail/MailManager.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -1,35 +0,0 @@
-package cc.kune.core.server.mail;
-
-import cc.kune.core.server.mail.MailManagerDefault.FormatedString;
-
-public interface MailManager {
-
-  /**
-   * @param subject
-   *          the email subject
-   * @param body
-   *          the body of the email in html format
-   * @param from
-   *          the sender
-   * @param to
-   *          the recipients
-   * @return true if sender (also we can change this interface if it's more
-   *         useful to return other thing)
-   */
-  boolean sendHtml(FormatedString subject, FormatedString body, String from, String... to);
-
-  /**
-   * @param subject
-   *          the email subject
-   * @param body
-   *          the body of the email in text format
-   * @param from
-   *          the sender
-   * @param to
-   *          the recipient
-   * @return true if sender (also we can change this interface if it's more
-   *         useful to return other thing)
-   */
-  boolean sendPlain(FormatedString subject, FormatedString body, String from, String... to);
-
-}

Deleted: trunk/src/main/java/cc/kune/core/server/mail/MailManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/mail/MailManagerDefault.java	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/src/main/java/cc/kune/core/server/mail/MailManagerDefault.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -1,34 +0,0 @@
-package cc.kune.core.server.mail;
-
-public class MailManagerDefault implements MailManager {
-
-  public static class FormatedString {
-
-    private final String string;
-
-    public FormatedString(final String template, final Object... args) {
-      string = String.format(template, args);
-    }
-
-    public String getString() {
-      return string;
-    }
-  }
-
-  public MailManagerDefault(final String mailServer, final String otherConfigurableMailServerParams) {
-  }
-
-  @Override
-  public boolean sendHtml(final FormatedString subject, final FormatedString body, final String from,
-      final String... to) {
-    // TODO Auto-generated method stub
-    return false;
-  }
-
-  @Override
-  public boolean sendPlain(final FormatedString subject, final FormatedString body, final String from,
-      final String... to) {
-    // TODO Auto-generated method stub
-    return false;
-  }
-}

Copied: trunk/src/main/java/cc/kune/core/server/mail/MailService.java (from rev 1534, trunk/src/main/java/cc/kune/core/server/mail/MailManager.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/mail/MailService.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/mail/MailService.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -0,0 +1,60 @@
+package cc.kune.core.server.mail;
+
+import cc.kune.core.server.mail.MailServiceDefault.FormatedString;
+
+public interface MailService {
+
+  /**
+   * Sends html email with default site "from"
+   * 
+   * @param subject
+   *          the email subject
+   * @param body
+   *          the body of the email in html format
+   * @param to
+   *          the recipient
+   */
+  void sendHtml(FormatedString subject, FormatedString body, String to);
+
+  /**
+   * Sends html email
+   * 
+   * @param subject
+   *          the email subject
+   * @param body
+   *          the body of the email in html format
+   * @param from
+   *          the sender
+   * @param tos
+   *          the recipients
+   */
+  void sendHtml(FormatedString subject, FormatedString body, String from, String... tos);
+
+  /**
+   * 
+   * Sends email with default site "from"
+   * 
+   * @param subject
+   *          the email subject
+   * @param body
+   *          the body of the email in text format
+   * @param to
+   *          the recipient
+   */
+  void sendPlain(FormatedString subject, FormatedString body, String to);
+
+  /**
+   * Sends plain email
+   * 
+   * @param subject
+   *          the email subject
+   * @param body
+   *          the body of the email in text format
+   * @param from
+   *          the sender
+   * @param tos
+   *          the recipients
+   */
+  void sendPlain(FormatedString subject, FormatedString body, String from, String... tos);
+
+}

Copied: trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java (from rev 1534, trunk/src/main/java/cc/kune/core/server/mail/MailManagerDefault.java)
===================================================================
--- trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java	                        (rev 0)
+++ trunk/src/main/java/cc/kune/core/server/mail/MailServiceDefault.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -0,0 +1,106 @@
+package cc.kune.core.server.mail;
+
+import java.util.Properties;
+
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import cc.kune.core.client.errors.DefaultException;
+import cc.kune.core.server.properties.KuneProperties;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+
+ at Singleton
+public class MailServiceDefault implements MailService {
+
+  public static class FormatedString {
+
+    private final String string;
+
+    public FormatedString(final String template, final Object... args) {
+      string = String.format(template, args);
+    }
+
+    public String getString() {
+      return string;
+    }
+  }
+
+  Log log = LogFactory.getLog(MailServiceDefault.class);
+  private final Properties props;
+  private final String smtpDefaultFrom;
+  private final boolean smtpSkip;
+
+  @Inject
+  public MailServiceDefault(final KuneProperties kuneProperties) {
+    final String smtpServer = kuneProperties.get(KuneProperties.SITE_SMTP_HOST);
+    smtpDefaultFrom = kuneProperties.get(KuneProperties.SITE_SMTP_DEFAULT_FROM);
+    smtpSkip = kuneProperties.getBoolean(KuneProperties.SITE_SMTP_SKIP);
+    props = System.getProperties();
+    props.put("mail.smtp.host", smtpServer);
+  }
+
+  private void send(final FormatedString subject, final FormatedString body, final boolean isHtml,
+      final String from, final String... tos) {
+    if (smtpSkip) {
+      return;
+    }
+
+    // Get session
+    final Session session = Session.getDefaultInstance(props, null);
+
+    // Define message
+    final MimeMessage message = new MimeMessage(session);
+    try {
+      message.setFrom(new InternetAddress(from));
+      for (final String to : tos) {
+        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
+      }
+      final String formatedSubject = subject.getString();
+      message.setSubject(formatedSubject);
+      final String formatedBody = body.getString();
+      if (isHtml) {
+        message.setContent(formatedBody, "text/html");
+      } else {
+        message.setText(formatedBody);
+      }
+      // Send message
+      Transport.send(message);
+    } catch (final AddressException e) {
+    } catch (final MessagingException e) {
+      log.error("Error sending the email", e);
+      throw new DefaultException("Error sending an email");
+    }
+  }
+
+  @Override
+  public void sendHtml(final FormatedString subject, final FormatedString body, final String to) {
+    send(subject, body, true, smtpDefaultFrom, to);
+  }
+
+  @Override
+  public void sendHtml(final FormatedString subject, final FormatedString body, final String from,
+      final String... tos) {
+    send(subject, body, true, from, tos);
+  }
+
+  @Override
+  public void sendPlain(final FormatedString subject, final FormatedString body, final String to) {
+    send(subject, body, false, smtpDefaultFrom, to);
+  }
+
+  @Override
+  public void sendPlain(final FormatedString subject, final FormatedString body, final String from,
+      final String... tos) {
+    send(subject, body, false, from, tos);
+  }
+}

Modified: trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/src/main/java/cc/kune/core/server/manager/impl/UserManagerDefault.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -44,6 +44,8 @@
 import cc.kune.core.client.errors.GroupShortNameInUseException;
 import cc.kune.core.client.errors.I18nNotFoundException;
 import cc.kune.core.client.errors.UserRegistrationException;
+import cc.kune.core.server.mail.MailService;
+import cc.kune.core.server.mail.MailServiceDefault.FormatedString;
 import cc.kune.core.server.manager.GroupManager;
 import cc.kune.core.server.manager.I18nCountryManager;
 import cc.kune.core.server.manager.I18nLanguageManager;
@@ -80,6 +82,7 @@
   private final I18nTranslationService i18n;
   private final KuneWaveService kuneWaveManager;
   private final I18nLanguageManager languageManager;
+  private final MailService mailService;
   private final ParticipantUtils participantUtils;
   private final KuneBasicProperties properties;
   private final UserFinder userFinder;
@@ -94,7 +97,7 @@
       final I18nTranslationService i18n, final CustomUserRegistrationServlet waveUserRegister,
       final AccountStore waveAccountStore, final KuneWaveService kuneWaveManager,
       final ParticipantUtils participantUtils, final KuneBasicProperties properties,
-      final GroupManager groupManager) {
+      final GroupManager groupManager, final MailService mailService) {
     super(provider, User.class);
     this.userFinder = finder;
     this.languageManager = languageManager;
@@ -108,6 +111,7 @@
     this.participantUtils = participantUtils;
     this.properties = properties;
     this.groupManager = groupManager;
+    this.mailService = mailService;
   }
 
   private void checkIfEmailAreInUse(final String email) {
@@ -174,6 +178,7 @@
       // Is this necessary? try to remove (used when we were setting the def
       // content
       // contentManager.save(userGroup.getDefaultContent());
+      mailService.sendPlain(new FormatedString("Welcome", ""), new FormatedString("welcome"), email);
       return user;
     } catch (final RuntimeException e) {
       try {

Modified: trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java
===================================================================
--- trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/src/main/java/cc/kune/core/server/properties/KuneProperties.java	2011-09-26 22:39:06 UTC (rev 1536)
@@ -49,6 +49,9 @@
   String SITE_LOGO_URL = "kune.sitelogourl";
   String SITE_NAME = "kune.default.site.name";
   String SITE_SHORTNAME = "kune.default.site.shortName";
+  String SITE_SMTP_DEFAULT_FROM = "kune.site.smtp.defaultfrom";
+  String SITE_SMTP_HOST = "kune.site.smtp.host";
+  String SITE_SMTP_SKIP = "kune.site.smtp.skip";
   String SITE_URL = "kune.siteurl";
   String SITE_USER_AVAILABLE_TOOLS = "kune.tools.userSiteAvailableTools";
   String SITE_USER_REGIST_ENABLED_TOOLS = "kune.tools.userRegisEnabledTools";

Modified: trunk/src/main/resources/kune.properties
===================================================================
--- trunk/src/main/resources/kune.properties	2011-09-26 20:24:14 UTC (rev 1535)
+++ trunk/src/main/resources/kune.properties	2011-09-26 22:39:06 UTC (rev 1536)
@@ -12,6 +12,12 @@
 kune.default.site.shortName = site
 kune.site.domain = localhost
 
+# Email
+kune.site.smtp.host = localhost
+kune.site.smtp.defaultfrom = noreply at localhost
+# If we should avoid the use of smtp (use only for avoid emails during development)
+kune.site.smtp.skip = true
+
 ### licenses
 
 kune.default.license = by-sa-v3.0




More information about the kune-commits mailing list