cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r468091 - in /cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail: MailMessageSender.java datasource/SourceDataSource.java transformation/SendMailTransformer.java
Date Thu, 26 Oct 2006 18:44:02 GMT
Author: vgritsenko
Date: Thu Oct 26 11:44:01 2006
New Revision: 468091

URL: http://svn.apache.org/viewvc?view=rev&rev=468091
Log:
merge:
    <action dev="VG" type="fix">
      Mail: Log exceptions from mail attachments - JavaMail does not preserve
      cause exception.
    </action>


Modified:
    cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/MailMessageSender.java
    cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/datasource/SourceDataSource.java
    cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java

Modified: cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/MailMessageSender.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/MailMessageSender.java?view=diff&rev=468091&r1=468090&r2=468091
==============================================================================
--- cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/MailMessageSender.java
(original)
+++ cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/MailMessageSender.java
Thu Oct 26 11:44:01 2006
@@ -70,9 +70,9 @@
  * @since 2.1
  * @version $Id$
  */
-public class MailMessageSender
-        extends AbstractLogEnabled
-        implements MailSender, Configurable, Serviceable, Initializable {
+public class MailMessageSender extends AbstractLogEnabled
+                               implements MailSender, Configurable, Serviceable,
+                                          Initializable {
 
     private ServiceManager manager;
 
@@ -102,7 +102,7 @@
         private Object obj;
         private String type;
         private String name;
-        protected boolean isURL = false;
+        protected boolean isURL;
 
         /**
          * Create a new attachment object encapsulating obj.
@@ -134,10 +134,12 @@
             this.type = type;
             this.name = name;
             this.isURL = isURI;
-            if (isNullOrEmpty(this.type))
+            if (isNullOrEmpty(this.type)) {
                 this.type = null;
-            if (isNullOrEmpty(this.name))
+            }
+            if (isNullOrEmpty(this.name)) {
                 this.name = null;
+            }
         }
 
         /**
@@ -146,7 +148,7 @@
          * @return true if str is null, empty string, or equals "null"
          */
         private boolean isNullOrEmpty(String str) {
-            return (str == null || "".equals(str) || "null".equals(str));
+            return str == null || "".equals(str) || "null".equals(str);
         }
 
         /**
@@ -183,6 +185,7 @@
         }
     }
 
+
     public MailMessageSender() {
     }
 
@@ -204,7 +207,7 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.avalon.framework.parameters.Parameterizable#parameterize(org.apache.avalon.framework.parameters.Parameters)
+     * @see Parameterizable#parameterize(Parameters)
      */
     public void configure(Configuration config) throws ConfigurationException {
         this.smtpHost = config.getChild("smtp-host").getValue(null);
@@ -213,7 +216,7 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     * @see Initializable#initialize()
      */
     public void initialize() {
         initSession();
@@ -254,7 +257,6 @@
         setSmtpHost(hostname);
     }
 
-
     /**
      * Assemble the message from the defined fields and send it.
      * @throws AddressException when problems with email addresses are found
@@ -265,7 +267,7 @@
         try {
             resolver = (SourceResolver) this.manager.lookup(SourceResolver.ROLE);
             doSend(resolver);
-        } catch(ServiceException se) {
+        } catch (ServiceException se) {
             throw new CascadingRuntimeException("Cannot get Source Resolver to send mail",
se);
         } finally {
             this.manager.release(resolver);
@@ -352,18 +354,15 @@
         try {
             if (this.attachments.isEmpty()) {
                 if (this.src != null) {
-                    DataSource ds = null;
+                    SourceDataSource ds = null;
 
                     Source source = resolver.resolveURI(this.src);
                     sourcesList.add(source);
                     if (source.exists()) {
-                        ds =
-                            new SourceDataSource(
-                                source,
-                                (this.srcMimeType == null
-                                    ? source.getMimeType()
-                                    : this.srcMimeType),
-                                this.src.substring(this.src.lastIndexOf('/') + 1));
+                        ds = new SourceDataSource(source,
+                                                  this.srcMimeType == null? source.getMimeType():
this.srcMimeType,
+                                                  this.src.substring(this.src.lastIndexOf('/')
+ 1));
+                        ds.enableLogging(getLogger());
                     }
 
                     message.setDataHandler(new DataHandler(ds));
@@ -382,18 +381,15 @@
                 message.setContent(multipart);
 
                 if (this.src != null) {
-                    DataSource ds = null;
+                    SourceDataSource ds = null;
 
                     Source source = resolver.resolveURI(this.src);
                     sourcesList.add(source);
                     if (source.exists()) {
-                        ds =
-                            new SourceDataSource(
-                                source,
-                                (this.srcMimeType == null
-                                    ? source.getMimeType()
-                                    : this.srcMimeType),
-                                this.src.substring(this.src.lastIndexOf('/') + 1));
+                        ds = new SourceDataSource(source,
+                                                  this.srcMimeType == null? source.getMimeType():
this.srcMimeType,
+                                                  this.src.substring(this.src.lastIndexOf('/')
+ 1));
+                        ds.enableLogging(getLogger());
                     }
 
                     bodypart.setDataHandler(new DataHandler(ds));
@@ -406,25 +402,23 @@
                 for (Iterator i = this.attachments.iterator(); i.hasNext();) {
                     a = (Attachment) i.next();
                     DataSource ds = null;
+
                     if (a.isURL) {
                         String name = (String) a.getObject();
                         Source src = resolver.resolveURI(name);
                         sourcesList.add(src);
                         if (src.exists()) {
-                            ds =
-                                new SourceDataSource(
-                                    src,
-                                    a.getType(src.getMimeType()),
-                                    a.getName(name.substring(name.lastIndexOf('/') + 1)));
+                            ds = new SourceDataSource(src,
+                                                      a.getType(src.getMimeType()),
+                                                      a.getName(name.substring(name.lastIndexOf('/')
+ 1)));
+                            ((SourceDataSource) ds).enableLogging(getLogger());
                         }
                     } else {
                         if (a.getObject() instanceof Part) {
                             Part part = (Part) a.getObject();
-                            ds =
-                                new FilePartDataSource(
-                                    part,
-                                    a.getType(part.getMimeType()),
-                                    a.getName(part.getUploadName()));
+                            ds = new FilePartDataSource(part,
+                                                        a.getType(part.getMimeType()),
+                                                        a.getName(part.getUploadName()));
                         } else {
                             // TODO: other classes?
                             throw new AddressException("Not yet supported: " + a.getObject());

Modified: cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/datasource/SourceDataSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/datasource/SourceDataSource.java?view=diff&rev=468091&r1=468090&r2=468091
==============================================================================
--- cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/datasource/SourceDataSource.java
(original)
+++ cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/datasource/SourceDataSource.java
Thu Oct 26 11:44:01 2006
@@ -19,9 +19,9 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-
 import javax.activation.DataSource;
 
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.excalibur.source.Source;
 
 /**
@@ -33,7 +33,8 @@
  * @see javax.activation.DataSource
  * @version $Id$
  */
-public class SourceDataSource implements DataSource {
+public class SourceDataSource extends AbstractLogEnabled
+                              implements DataSource {
     private Source src;
     private String contentType;
     private String name;
@@ -54,8 +55,12 @@
         this.src = src;
         this.contentType = type;
         this.name = name;
-        if (isNullOrEmpty(this.name)) this.name = null;
-        if (isNullOrEmpty(this.contentType)) this.contentType = null;
+        if (isNullOrEmpty(this.name)) {
+            this.name = null;
+        }
+        if (isNullOrEmpty(this.contentType)) {
+            this.contentType = null;
+        }
     }
 
     /**
@@ -64,7 +69,7 @@
      * @return true if str is null, empty string, or equals "null"
      */
      private boolean isNullOrEmpty(String str) {
-         return (str == null || "".equals(str) || "null".equals(str));
+         return str == null || "".equals(str) || "null".equals(str);
      }
 
     /**
@@ -79,10 +84,12 @@
         if (this.contentType != null) {
             return this.contentType;
         }
+
         String mimeType = src.getMimeType();
         if (isNullOrEmpty(mimeType)) {
             mimeType = "application/octet-stream";
         }
+
         return mimeType;
     }
 
@@ -94,7 +101,15 @@
      * @see org.apache.excalibur.source.Source#getInputStream()
      */
     public InputStream getInputStream() throws IOException {
-        return src.getInputStream();
+        try {
+            return src.getInputStream();
+        } catch (IOException e) {
+            // Sun's SMTPTransport looses cause exception. Log it now.
+            if (getLogger() != null) {
+                getLogger().warn("Unable to obtain input stream for '" + src.getURI() + "'",
e);
+            }
+            throw e;
+        }
     }
 
     /**
@@ -109,9 +124,10 @@
         if (this.name != null){
             return this.name;
         }
+
         String name = src.getURI();
         name = name.substring(name.lastIndexOf('/') + 1);
-        return ("".equals(name)? "attachment" : name);
+        return "".equals(name)? "attachment" : name;
     }
 
     /**

Modified: cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java?view=diff&rev=468091&r1=468090&r2=468091
==============================================================================
--- cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
(original)
+++ cocoon/trunk/blocks/cocoon-mail/cocoon-mail-impl/src/main/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
Thu Oct 26 11:44:01 2006
@@ -78,7 +78,7 @@
  *     &lt;from&gt;sender@localhost&lt;/from&gt;
  *  &lt;/map:transformer&gt;
  *  </pre>
- * 
+ *
  * where
  *  <ul>
  *   <li>
@@ -117,7 +117,7 @@
  *   </li>
  *  </ul>
  * </p>
- * 
+ *
  * <p>
  *   More configurations can be made in a specific configuration file, which
  *   can be retrieved with a
@@ -151,7 +151,7 @@
  *   </li>
  *  </ul>
  * </p>
- * 
+ *
  * <p>
  *  Input document sample:
  *  <pre>
@@ -601,20 +601,17 @@
             multipart.addBodyPart(messageBodyPart);
 
             // process attachments
-            Iterator iterAtt = this.attachments.iterator();
-    
-            while (iterAtt.hasNext()) {
-                AttachmentDescriptor aD = (AttachmentDescriptor) iterAtt.next();
+            Iterator i = this.attachments.iterator();
+            while (i.hasNext()) {
+                AttachmentDescriptor aD = (AttachmentDescriptor) i.next();
                 messageBodyPart = new MimeBodyPart();
     
                 if (!aD.isTextContent()) {
-                    Source inputSource = null;
-                    DataSource dataSource = null;
-    
-                    inputSource = resolver.resolveURI(aD.isURLSource() ? aD.strAttrSrc :
aD.strAttrFile);
+                    Source inputSource = resolver.resolveURI(aD.isURLSource() ? aD.strAttrSrc
: aD.strAttrFile);
                     this.usedSources.add(inputSource);
     
-                    dataSource = new SourceDataSource(inputSource, aD.strAttrMimeType, aD.strAttrName);
+                    DataSource dataSource = new SourceDataSource(inputSource, aD.strAttrMimeType,
aD.strAttrName);
+                    ((SourceDataSource) dataSource).enableLogging(getLogger());
     
                     messageBodyPart.setDataHandler(new DataHandler(dataSource));
                 } else {



Mime
View raw message