You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oozie.apache.org by as...@apache.org on 2019/07/18 06:22:38 UTC
[oozie] branch master updated: OOZIE-3024 Email action ignores
value of content_type attribute when attachment attribute is set (matijhs
via asalamon74)
This is an automated email from the ASF dual-hosted git repository.
asalamon74 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/oozie.git
The following commit(s) were added to refs/heads/master by this push:
new da012e3 OOZIE-3024 Email action ignores value of content_type attribute when attachment attribute is set (matijhs via asalamon74)
da012e3 is described below
commit da012e37dba16e1b01d3300e55e3f5789ec3f3f9
Author: Andras Salamon <as...@apache.org>
AuthorDate: Thu Jul 18 08:22:10 2019 +0200
OOZIE-3024 Email action ignores value of content_type attribute when attachment attribute is set (matijhs via asalamon74)
---
.../oozie/action/email/EmailActionExecutor.java | 9 +++---
.../action/email/TestEmailActionExecutor.java | 36 +++++++++++++++++++---
release-log.txt | 1 +
3 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java b/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
index a094d93..e5b5c7b 100644
--- a/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
+++ b/core/src/main/java/org/apache/oozie/action/email/EmailActionExecutor.java
@@ -253,10 +253,10 @@ public class EmailActionExecutor extends ActionExecutor {
if (attachments != null && attachments.length > 0 && ConfigurationService.getBoolean(EMAIL_ATTACHMENT_ENABLED)) {
Multipart multipart = new MimeMultipart();
- // Set body text
- MimeBodyPart bodyTextPart = new MimeBodyPart();
- bodyTextPart.setText(body);
- multipart.addBodyPart(bodyTextPart);
+ // Set body text/content
+ MimeBodyPart bodyPart = new MimeBodyPart();
+ bodyPart.setContent(body, contentType);
+ multipart.addBodyPart(bodyPart);
for (String attachment : attachments) {
URI attachUri = new URI(attachment);
@@ -279,6 +279,7 @@ public class EmailActionExecutor extends ActionExecutor {
}
message.setContent(body, contentType);
}
+ message.saveChanges();
}
catch (AddressException e) {
throw new ActionExecutorException(ErrorType.ERROR, "EM004", "Bad address format in <to> or <cc> or <bcc>.", e);
diff --git a/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java b/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
index b310e3c..c27dc80 100644
--- a/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
+++ b/core/src/test/java/org/apache/oozie/action/email/TestEmailActionExecutor.java
@@ -285,12 +285,33 @@ public class TestEmailActionExecutor extends ActionExecutorTestCase {
elem.append("<content_type>text/html</content_type>");
elem.append("<body><body> This is a test mail </body></body>");
elem.append("</email>");
- EmailActionExecutor emailContnetType = new EmailActionExecutor();
- emailContnetType.validateAndMail(createAuthContext("email-action"), XmlUtils.parseXml(elem.toString()));
+ EmailActionExecutor emailContentType = new EmailActionExecutor();
+ emailContentType.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"));
}
+ public void testContentTypeWithAttachment() throws Exception {
+ String file1 = "file1";
+ Path path1 = new Path(getFsTestCaseDir(), file1);
+ String content1 = "this is attachment content in file1";
+ FileSystem fs = getFileSystem();
+ Writer writer = new OutputStreamWriter(fs.create(path1, true), StandardCharsets.UTF_8);
+ writer.write(content1);
+ writer.close();
+ sendAndReceiveEmail(path1.toString(), "text/html");
+
+ Multipart retParts = (Multipart) (server.getReceivedMessages()[0].getContent());
+ BodyPart bp = retParts.getBodyPart(0);
+ assertTrue(bp.getContentType().contains("text/html"));
+ assertEquals("This is a test mail", IOUtils.toString(bp.getInputStream()));
+
+ sendAndReceiveEmail(path1.toString());
+ retParts = (Multipart) (server.getReceivedMessages()[1].getContent());
+ bp = retParts.getBodyPart(0);
+ assertTrue(bp.getContentType().contains("text/plain"));
+ }
+
public void testLocalFileAttachmentError() throws Exception {
File attachFile1 = new File(getTestCaseDir() + File.separator + "attachment1.txt");
String content1 = "this is attachment content in file1";
@@ -365,13 +386,20 @@ public class TestEmailActionExecutor extends ActionExecutorTestCase {
assertEquals(attachCount, numAttach);
}
- private void sendAndReceiveEmail(String attachtag) throws Exception {
+ private void sendAndReceiveEmail(String attachTag) throws Exception {
+ sendAndReceiveEmail(attachTag, null);
+ }
+
+ private void sendAndReceiveEmail(String attachTag, String contentType) throws Exception{
StringBuilder elem = new StringBuilder();
elem.append("<email xmlns=\"uri:oozie:email-action:0.2\">");
elem.append("<to>oozie@yahoo-inc.com</to>");
elem.append("<subject>sub</subject>");
elem.append("<body>This is a test mail</body>");
- elem.append("<attachment>").append(attachtag).append("</attachment>");
+ if(contentType != null){
+ elem.append("<content_type>").append(contentType).append("</content_type>");
+ }
+ elem.append("<attachment>").append(attachTag).append("</attachment>");
elem.append("</email>");
EmailActionExecutor emailExecutor = new EmailActionExecutor();
emailExecutor.validateAndMail(createAuthContext("email-action"), XmlUtils.parseXml(elem.toString()));
diff --git a/release-log.txt b/release-log.txt
index bd927d4..7f5609c 100644
--- a/release-log.txt
+++ b/release-log.txt
@@ -1,5 +1,6 @@
-- Oozie 5.2.0 release (trunk - unreleased)
+OOZIE-3024 Email action ignores value of content_type attribute when attachment attribute is set (matijhs via asalamon74)
OOZIE-3526 Global job-xml not being overwritten by job-xml specified for an action (mgogineni via rohini)
OOZIE-2755 Oozie HA: ZKJobsConcurrencyService throws runtime exception when numOozies is zero(asalamon74 via kmarton)
OOZIE-3527 Oozie stuck in waiting state if CoordPushDependencyCheckXCommand is not requeued (mgogineni via rohini)