You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2006/10/26 20:31:24 UTC

svn commit: r468083 - in /cocoon/branches/BRANCH_2_1_X: ./ src/blocks/mail/java/org/apache/cocoon/mail/ src/blocks/mail/java/org/apache/cocoon/mail/datasource/ src/blocks/mail/java/org/apache/cocoon/mail/transformation/

Author: vgritsenko
Date: Thu Oct 26 11:31:24 2006
New Revision: 468083

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


Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/datasource/SourceDataSource.java
    cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
    cocoon/branches/BRANCH_2_1_X/status.xml

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java?view=diff&rev=468083&r1=468082&r2=468083
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/MailMessageSender.java Thu Oct 26 11:31:24 2006
@@ -68,14 +68,14 @@
  * <tr><th>smtp-password</th><td>Password for authentication</td><td>opt</td><td>String</td></tr>
  * </tbody></table>
  *
+ * @since 2.1
  * @author <a href="mailto:frank.ridderbusch@gmx.de">Frank Ridderbusch</a>
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @since 2.1
- * @version CVS $Id$
+ * @version $Id$
  */
-public class MailMessageSender
-        extends AbstractLogEnabled
-        implements MailSender, Configurable, Serviceable, Initializable, Component {
+public class MailMessageSender extends AbstractLogEnabled
+                               implements MailSender, Configurable, Serviceable,
+                                          Initializable, Component {
 
     private ServiceManager manager;
 
@@ -104,10 +104,10 @@
      * @since 2.1
      */
     private static class Attachment {
-        private Object obj = null;
-        private String type = null;
-        private String name = null;
-        protected boolean isURL = false;
+        private Object obj;
+        private String type;
+        private String name;
+        protected boolean isURL;
 
         /**
          * Create a new attachment object encapsulating obj.
@@ -139,10 +139,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;
+            }
         }
 
         /**
@@ -151,7 +153,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);
         }
 
         /**
@@ -188,6 +190,7 @@
         }
     }
 
+
     public MailMessageSender() {
     }
 
@@ -209,7 +212,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);
@@ -218,7 +221,7 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.avalon.framework.activity.Initializable#initialize()
+     * @see Initializable#initialize()
      */
     public void initialize() {
         initSession();
@@ -259,7 +262,6 @@
         setSmtpHost(hostname);
     }
 
-
     /**
      * Assemble the message from the defined fields and send it.
      * @throws AddressException when problems with email addresses are found
@@ -270,7 +272,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);
@@ -357,18 +359,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));
@@ -387,18 +386,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));
@@ -411,25 +407,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/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/datasource/SourceDataSource.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/datasource/SourceDataSource.java?view=diff&rev=468083&r1=468082&r2=468083
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/datasource/SourceDataSource.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/datasource/SourceDataSource.java Thu Oct 26 11:31:24 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,9 +33,10 @@
  * @see javax.activation.DataSource
  * @author <a href="mailto:frank.ridderbusch@gmx.de">Frank Ridderbusch</a>
  * @author <a href="mailto:haul@apache.org">Christian Haul</a>
- * @version CVS $Id$
+ * @version $Id$
  */
-public class SourceDataSource implements DataSource {
+public class SourceDataSource extends AbstractLogEnabled
+                              implements DataSource {
     private Source src;
     private String contentType;
     private String name;
@@ -56,8 +57,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;
+        }
     }
 
     /**
@@ -66,7 +71,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);
      }
 
     /**
@@ -81,10 +86,12 @@
         if (this.contentType != null) {
             return this.contentType;
         }
+
         String mimeType = src.getMimeType();
         if (isNullOrEmpty(mimeType)) {
             mimeType = "application/octet-stream";
         }
+
         return mimeType;
     }
 
@@ -96,7 +103,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;
+        }
     }
 
     /**
@@ -111,9 +126,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/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java?view=diff&rev=468083&r1=468082&r2=468083
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/mail/java/org/apache/cocoon/mail/transformation/SendMailTransformer.java Thu Oct 26 11:31:24 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>
@@ -590,20 +590,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 {

Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/status.xml?view=diff&rev=468083&r1=468082&r2=468083
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Thu Oct 26 11:31:24 2006
@@ -184,6 +184,10 @@
   <release version="@version@" date="@date@">
 -->
   <release version="2.1.10" date="TBD">
+    <action dev="VG" type="fix">
+      Mail: Log exceptions from mail attachments - JavaMail does not preserve
+      cause exception.
+    </action>
     <action dev="JH" type="fix" fixes-bug="COCOON-1936" due-to="Jeroen Reijn" due-to-email="j.reijn@hippo.nl">
       Lucene: Add <code>analyzer</code> parameter to <code>SearchGenerator</code>
       as stated by the docs.
@@ -196,7 +200,7 @@
       <code>javax.xml.XMLConstants</code>, which are not in the official API.
     </action>
     <action dev="AG" type="fix" fixes-bug="COCOON-1692" due-to="Suzan Foster" due-to-email="suzan.foster@nerocmediaware.nl">
-      Cforms: Tree widget not handling on-selection-change events correctly.
+      CForms: Tree widget not handling on-selection-change events correctly.
     </action>
     <action dev="JH" type="fix" fixes-bug="COCOON-1883" due-to="Fabian Linz" due-to-email="f.linz@gmx.de">
       XSP: SOAPHelper does no longer accept only replies with an XML declaration.
@@ -205,19 +209,22 @@
       Updated commons-lang to 2.2 and bsf to 2.4.0.
     </action>
     <action dev="JH" type="fix" fixes-bug="COCOON-1900" due-to="Gabriele Columbro" due-to-email="columbro@gmail.com">
-      CForms: Add a <code>name</code> attribute to a booleanfield in output mode to make it easily accessible in JavaScript.
+      CForms: Add a <code>name</code> attribute to a booleanfield in output mode to
+      make it easily accessible in JavaScript.
     </action>
     <action dev="AG" type="fix" fixes-bug="COCOON-1867" due-to="Gabriele Columbro" due-to-email="columbro@gmail.com">
-      Cforms: BeanConvertor uses a WeakHashMap in the wrong way.
+      CForms: BeanConvertor uses a WeakHashMap in the wrong way.
     </action>
     <action dev="AG" type="fix" due-to="Christofer Dutz" due-to-email="christofer.dutz@univativ.de">
       AJAX: Fix cocoon suggest sample.
     </action>
     <action dev="AG" type="update">
-      Deprecate method org.apache.cocoon.components.flow.FlowHelper.unwrap(Object). This method will be removed in 2.2 release. Use org.apache.cocoon.components.flow.util.PipelineUtil.unwrap(Object) instead.
+      Deprecate method org.apache.cocoon.components.flow.FlowHelper.unwrap(Object).
+      This method will be removed in 2.2 release. Use org.apache.cocoon.components.flow.util.PipelineUtil.unwrap(Object) instead.
     </action>
     <action dev="JH" type="fix" fixes-bug="COCOON-1196">
-      XSP: Use namespace-uri and not the namespace-prefix to select parameters in logicsheet-util.xsl.
+      XSP: Use namespace-uri and not the namespace-prefix to select parameters
+      in logicsheet-util.xsl.
     </action>
     <action dev="VG" type="fix" fixes-bug="COCOON-1462">
       Databases: Check for null LOBs.