You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by ry...@apache.org on 2013/12/05 01:06:52 UTC

svn commit: r1547972 - in /oozie/trunk: ./ client/src/main/resources/ core/src/main/java/org/apache/oozie/action/email/ core/src/test/java/org/apache/oozie/action/email/ docs/src/site/twiki/

Author: ryota
Date: Thu Dec  5 00:06:51 2013
New Revision: 1547972

URL: http://svn.apache.org/r1547972
Log:
OOZIE-1598 enable html email in email action (puru via ryota)

Added:
    oozie/trunk/client/src/main/resources/email-action-0.2.xsd
Modified:
    oozie/trunk/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
    oozie/trunk/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
    oozie/trunk/docs/src/site/twiki/DG_EmailActionExtension.twiki
    oozie/trunk/release-log.txt

Added: oozie/trunk/client/src/main/resources/email-action-0.2.xsd
URL: http://svn.apache.org/viewvc/oozie/trunk/client/src/main/resources/email-action-0.2.xsd?rev=1547972&view=auto
==============================================================================
--- oozie/trunk/client/src/main/resources/email-action-0.2.xsd (added)
+++ oozie/trunk/client/src/main/resources/email-action-0.2.xsd Thu Dec  5 00:06:51 2013
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
+           xmlns:email="uri:oozie:email-action:0.2" elementFormDefault="qualified"
+           targetNamespace="uri:oozie:email-action:0.2">
+
+    <xs:element name="email" type="email:ACTION"/>
+
+    <xs:complexType name="ACTION">
+        <xs:sequence>
+            <xs:element name="to" type="xs:string" minOccurs="1" maxOccurs="1"/>
+            <xs:element name="cc" type="xs:string" minOccurs="0" maxOccurs="1"/>
+            <xs:element name="subject" type="xs:string" minOccurs="1" maxOccurs="1"/>
+            <xs:element name="body" type="xs:string" minOccurs="1" maxOccurs="1"/>
+            <xs:element name="content_type" type="xs:string" minOccurs="0" maxOccurs="1"/>
+        </xs:sequence>
+    </xs:complexType>
+</xs:schema>

Modified: oozie/trunk/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java?rev=1547972&r1=1547971&r2=1547972&view=diff
==============================================================================
--- oozie/trunk/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java (original)
+++ oozie/trunk/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java Thu Dec  5 00:06:51 2013
@@ -60,7 +60,9 @@ public class EmailActionExecutor extends
     private final static String SUB = "subject";
     private final static String BOD = "body";
     private final static String COMMA = ",";
+    private final static String CONTENT_TYPE = "content_type";
 
+    private final static String DEFAULT_CONTENT_TYPE = "text/plain";
     public EmailActionExecutor() {
         super("email");
     }
@@ -86,11 +88,12 @@ public class EmailActionExecutor extends
     @SuppressWarnings("unchecked")
     protected void validateAndMail(Context context, Element element) throws ActionExecutorException {
         // The XSD does the min/max occurrence validation for us.
-        Namespace ns = Namespace.getNamespace("uri:oozie:email-action:0.1");
+        Namespace ns = element.getNamespace();
         String tos[] = new String[0];
         String ccs[] = new String[0];
         String subject = "";
         String body = "";
+        String contentType;
         Element child = null;
 
         // <to> - One ought to exist.
@@ -114,11 +117,18 @@ public class EmailActionExecutor extends
         // <body> - One ought to exist.
         body = element.getChildTextTrim(BOD, ns);
 
+        contentType = element.getChildTextTrim(CONTENT_TYPE, ns);
+        if (contentType == null || contentType.isEmpty()) {
+            contentType = DEFAULT_CONTENT_TYPE;
+        }
+
+
         // All good - lets try to mail!
-        email(context, tos, ccs, subject, body);
+        email(context, tos, ccs, subject, body, contentType);
     }
 
-    protected void email(Context context, String[] to, String[] cc, String subject, String body) throws ActionExecutorException {
+    protected void email(Context context, String[] to, String[] cc, String subject, String body, String contentType)
+            throws ActionExecutorException {
         // Get mailing server details.
         String smtpHost = getOozieConf().get(EMAIL_SMTP_HOST, "localhost");
         String smtpPort = getOozieConf().get(EMAIL_SMTP_PORT, "25");
@@ -168,9 +178,9 @@ public class EmailActionExecutor extends
             }
             message.addRecipients(RecipientType.CC, ccAddrs.toArray(new InternetAddress[0]));
 
-            // Set subject, and plain-text body.
+            // Set subject
             message.setSubject(subject);
-            message.setContent(body, "text/plain");
+            message.setContent(body, contentType);
         } catch (AddressException e) {
             throw new ActionExecutorException(ErrorType.ERROR, "EM004", "Bad address format in <to> or <cc>.", e);
         } catch (MessagingException e) {

Modified: oozie/trunk/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
URL: http://svn.apache.org/viewvc/oozie/trunk/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java?rev=1547972&r1=1547971&r2=1547972&view=diff
==============================================================================
--- oozie/trunk/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java (original)
+++ oozie/trunk/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java Thu Dec  5 00:06:51 2013
@@ -159,6 +159,27 @@ public class TestEmailActionExecutor ext
         }
     }
 
+    public void testContentTypeDefault() throws Exception {
+        EmailActionExecutor email = new EmailActionExecutor();
+        email.validateAndMail(createAuthContext("email-action"), prepareEmailElement(true));
+        assertEquals("bod", GreenMailUtil.getBody(server.getReceivedMessages()[0]));
+        assertTrue(server.getReceivedMessages()[0].getContentType().contains("text/plain"));
+    }
+
+    public void testContentType() throws Exception {
+        StringBuilder elem = new StringBuilder();
+        elem.append("<email xmlns=\"uri:oozie:email-action:0.2\">");
+        elem.append("<to>purushah@yahoo-inc.com</to>");
+        elem.append("<subject>sub</subject>");
+        elem.append("<content_type>text/html</content_type>");
+        elem.append("<body>&lt;body&gt; This is a test mail &lt;/body&gt;</body>");
+        elem.append("</email>");
+        EmailActionExecutor emailContnetType = new EmailActionExecutor();
+        emailContnetType.validateAndMail(createAuthContext("email-action"), XmlUtils.parseXml(elem.toString()));
+        assertEquals("<body> This is a test mail </body>", GreenMailUtil.getBody(server.getReceivedMessages()[0]));
+        assertTrue(server.getReceivedMessages()[0].getContentType().contains("text/html"));
+    }
+
     @Override
     protected void tearDown() throws Exception {
         super.tearDown();

Modified: oozie/trunk/docs/src/site/twiki/DG_EmailActionExtension.twiki
URL: http://svn.apache.org/viewvc/oozie/trunk/docs/src/site/twiki/DG_EmailActionExtension.twiki?rev=1547972&r1=1547971&r2=1547972&view=diff
==============================================================================
--- oozie/trunk/docs/src/site/twiki/DG_EmailActionExtension.twiki (original)
+++ oozie/trunk/docs/src/site/twiki/DG_EmailActionExtension.twiki Thu Dec  5 00:06:51 2013
@@ -26,11 +26,12 @@ All values specified in the =email= acti
 <workflow-app name="[WF-DEF-NAME]" xmlns="uri:oozie:workflow:0.1">
     ...
     <action name="[NODE-NAME]">
-        <email xmlns="uri:oozie:email-action:0.1">
+        <email xmlns="uri:oozie:email-action:0.2">
             <to>[COMMA-SEPARATED-TO-ADDRESSES]</to>
             <cc>[COMMA-SEPARATED-CC-ADDRESSES]</cc> <!-- cc is optional -->
             <subject>[SUBJECT]</subject>
             <body>[BODY]</body>
+            <content_type>[CONTENT-TYPE]</content_type> <!-- content_type is optional -->
         </email>
         <ok to="[NODE-NAME]"/>
         <error to="[NODE-NAME]"/>
@@ -42,7 +43,10 @@ All values specified in the =email= acti
 The =to= and =cc= commands are used to specify reciepents who should get the mail. Multiple email reciepents can be provided
 using comma-separated values. Providing a =to= command is necessary, while the =cc= may optionally be used along.
 
-The =subject= and =body= commands are used to specify the plain-text subject and body of the mail.
+The =subject= and =body= commands are used to specify subject and body of the mail.
+From uri:oozie:email-action:0.2 one can also specify mail content type as <content_type>text/html</content_type>.
+"text/plain" is default.
+
 
 *Configuration*
 
@@ -82,8 +86,8 @@ with the subject and body both containin
 
 <verbatim>
 <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
-           xmlns:email="uri:oozie:email-action:0.1" elementFormDefault="qualified"
-           targetNamespace="uri:oozie:email-action:0.1">
+           xmlns:email="uri:oozie:email-action:0.2" elementFormDefault="qualified"
+           targetNamespace="uri:oozie:email-action:0.2">
 .
     <xs:element name="email" type="email:ACTION"/>
 .
@@ -93,6 +97,7 @@ with the subject and body both containin
             <xs:element name="cc" type="xs:string" minOccurs="0" maxOccurs="1"/>
             <xs:element name="subject" type="xs:string" minOccurs="1" maxOccurs="1"/>
             <xs:element name="body" type="xs:string" minOccurs="1" maxOccurs="1"/>
+            <xs:element name="content_type" type="xs:string" minOccurs="0" maxOccurs="1"/>
         </xs:sequence>
     </xs:complexType>
 </xs:schema>

Modified: oozie/trunk/release-log.txt
URL: http://svn.apache.org/viewvc/oozie/trunk/release-log.txt?rev=1547972&r1=1547971&r2=1547972&view=diff
==============================================================================
--- oozie/trunk/release-log.txt (original)
+++ oozie/trunk/release-log.txt Thu Dec  5 00:06:51 2013
@@ -1,5 +1,6 @@
 -- Oozie 4.1.0 release (trunk - unreleased)
 
+OOZIE-1598 enable html email in email action (puru via ryota)
 OOZIE-1631 Tools module should have a direct dependency on mockito (rkanter)
 OOZIE-1491 Make sure HA works with a secure ZooKeeper (rkanter)
 OOZIE-1615 shell action cannot find script file and fails in uber mode (ryota)