You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sa...@apache.org on 2007/04/06 10:24:05 UTC

svn commit: r526093 - in /webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail: Constants.java EMailSender.java MailToInfo.java MailTransportSender.java SimpleMailListener.java

Author: saminda
Date: Fri Apr  6 01:24:04 2007
New Revision: 526093

URL: http://svn.apache.org/viewvc?view=rev&rev=526093
Log:
Fix For JIRA AXIS2-2410

Modified:
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java?view=diff&rev=526093&r1=526092&r2=526093
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/Constants.java Fri Apr  6 01:24:04 2007
@@ -33,7 +33,7 @@
     public final static String STORE_PROTOCOL = "mail.store.protocol";
 
 
-    public final static String RAPLY_TO = "transport.mail.replyToAddress";
+    public final static String REPLY_TO = "transport.mail.replyToAddress";
 
     public final static String LISTENER_INTERVAL = "transport.listener.interval";
 
@@ -79,4 +79,5 @@
     public static final String X_SERVICE_PATH = "X-Service-Path";
     public static final String MAIL_SYNC = "_MAIL_SYNC_";
     public static final String IN_REPLY_TO = "In-Reply-To";
+    public static final String MAILTO = "mailto";
 }

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java?view=diff&rev=526093&r1=526092&r2=526093
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java Fri Apr  6 01:24:04 2007
@@ -56,6 +56,7 @@
     private OutputStream outputStream;
     private String inReplyTo;
     private EndpointReference from;
+    private OMOutputFormat format;
 
     protected static Log log = LogFactory.getLog(EMailSender.class);
 
@@ -90,7 +91,7 @@
         this.passwordAuthentication = passwordAuthentication;
     }
 
-    public void send(MailToInfo mailToInfo, OMOutputFormat format)
+    public void send()
             throws AxisFault {
 
         try {
@@ -104,6 +105,7 @@
 
 
             EndpointReference epr = null;
+            MailToInfo mailToInfo = null;
 
             if (messageContext.getTo() != null && !messageContext.getTo().hasAnonymousAddress()) {
                 epr = messageContext.getTo();
@@ -111,13 +113,15 @@
 
             if (epr != null) {
                 if (!epr.hasNoneAddress()) {
+                    mailToInfo = new MailToInfo(epr);
                     msg.addRecipient(Message.RecipientType.TO,
                                      new InternetAddress(mailToInfo.getEmailAddress()));
 
                 } else {
                     if (from != null) {
+                        mailToInfo = new MailToInfo(from);
                         msg.addRecipient(Message.RecipientType.TO,
-                                         new InternetAddress(from.getAddress()));
+                                         new InternetAddress(mailToInfo.getEmailAddress()));
                     } else {
                         String error = EMailSender.class.getName() + "Couldn't countinue due to" +
                                        " FROM addressing is NULL";
@@ -127,24 +131,24 @@
                 }
             } else {
                 // replyto : from : or reply-path;
-                if (messageContext.isServerSide()) {
-                    if (from != null) {
-                        msg.addRecipient(Message.RecipientType.TO,
-                                         new InternetAddress(from.getAddress()));
-                    } else {
-                        String error = EMailSender.class.getName() + "Couldn't countinue due to" +
-                                       " FROM addressing is NULL and EPR is NULL";
-                        log.error(error);
-                        throw new AxisFault(error);
-                    }
-
+                if (from != null) {
+                    mailToInfo = new MailToInfo(from);
+                    msg.addRecipient(Message.RecipientType.TO,
+                                     new InternetAddress(mailToInfo.getEmailAddress()));
+                } else {
+                    String error = EMailSender.class.getName() + "Couldn't countinue due to" +
+                                   " FROM addressing is NULL and EPR is NULL";
+                    log.error(error);
+                    throw new AxisFault(error);
                 }
+
             }
 
             msg.setSubject("__ Axis2/Java Mail Message __");
 
             if (mailToInfo.isxServicePath()) {
-                msg.setHeader(Constants.X_SERVICE_PATH, "\"" + mailToInfo.getContentDescription() + "\"");
+                msg.setHeader(Constants.X_SERVICE_PATH,
+                              "\"" + mailToInfo.getContentDescription() + "\"");
             }
 
             if (inReplyTo != null) {
@@ -154,7 +158,7 @@
             createMailMimeMessage(msg, mailToInfo, format);
             Transport.send(msg);
 
-            sendReceive(messageContext,msg.getMessageID());
+            sendReceive(messageContext, msg.getMessageID());
         } catch (AddressException e) {
             throw new AxisFault(e);
         } catch (MessagingException e) {
@@ -220,6 +224,10 @@
         this.from = from;
     }
 
+    public void setFormat(OMOutputFormat format) {
+        this.format = format;
+    }
+
     private void sendReceive(MessageContext msgContext, String msgId) throws AxisFault {
         Object obj = msgContext.getProperty(Constants.MAIL_SYNC);
         if (obj == null) {
@@ -230,6 +238,6 @@
 
         SynchronousMailListener listener =
                 new SynchronousMailListener(options.getTimeOutInMilliSeconds());
-        listener.sendReceive(msgContext,msgId);
+        listener.sendReceive(msgContext, msgId);
     }
 }

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java?view=diff&rev=526093&r1=526092&r2=526093
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailToInfo.java Fri Apr  6 01:24:04 2007
@@ -14,6 +14,8 @@
  * limitations under the License.
  */
 package org.apache.axis2.transport.mail;
+
+import org.apache.axis2.addressing.EndpointReference;
 /*
  * 
  */
@@ -22,7 +24,36 @@
     private String emailAddress;
     private String contentDescription;
     private boolean xServicePath;
-    private String fromAddress;
+
+    public MailToInfo(String eprAddress) {
+        //URl validation according to rfc :  http://www.ietf.org/rfc/rfc2368.txt
+
+        int mailToIndex = eprAddress.indexOf(Constants.MAILTO+":");
+        if (mailToIndex > -1) {
+            eprAddress = eprAddress.substring(mailToIndex + 7);
+        }
+        int index = eprAddress.indexOf('?');
+
+        if (index > -1) {
+            emailAddress = eprAddress.substring(0, index);
+        } else {
+            emailAddress = eprAddress;
+        }
+
+        if (eprAddress.indexOf(Constants.X_SERVICE_PATH) > -1) {
+            index = eprAddress.indexOf('=');
+            if (index > -1) {
+                xServicePath = true;
+                contentDescription = eprAddress.substring(index + 1);
+            }
+        } else {
+            contentDescription = eprAddress.substring(index + 1);
+
+        }
+    }
+    public MailToInfo(EndpointReference epr) {
+        this(epr.getAddress());
+    }
 
     public String getEmailAddress() {
         return emailAddress;
@@ -48,11 +79,4 @@
         this.xServicePath = xServicePath;
     }
 
-    public String getFromAddress() {
-        return fromAddress;
-    }
-
-    public void setFromAddress(String fromAddress) {
-        this.fromAddress = fromAddress;
-    }
 }

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java?view=diff&rev=526093&r1=526092&r2=526093
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java Fri Apr  6 01:24:04 2007
@@ -116,9 +116,6 @@
 
     private ByteArrayOutputStream byteArrayOutputStream;
     // assosiation with OMOutputFormat
-    private final OMOutputFormat format = new OMOutputFormat();
-
-    private final MailToInfo mailToInfo = new MailToInfo();
 
     private final static String NAME = "MailTransportSender";
 
@@ -152,9 +149,6 @@
             if (paramKey.equals(Constants.SMTP_USER_PASSWORD)) {
                 password = paramValue;
             }
-            if (paramKey.equals(Constants.RAPLY_TO)) {
-                mailToInfo.setFromAddress(paramValue);
-            }
 
         }
         passwordAuthentication = new PasswordAuthentication(username, password);
@@ -178,7 +172,7 @@
                 passwordAuthentication = new PasswordAuthentication(username, passwd);
             } else if (obj instanceof java.util.Properties) {
                 smtpProperties.clear();
-                java.util.Properties props = (java.util.Properties)obj;
+                java.util.Properties props = (java.util.Properties) obj;
                 smtpProperties.putAll(props);
             }
         }
@@ -201,14 +195,13 @@
                     (String) msgContext.getProperty(
                             org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING);
             if (charSet == null) {
-                charSet =
-                        MessageContext.DEFAULT_CHAR_SET_ENCODING;// Since we are deleaing only SOAP and XML messages here
+                charSet = MessageContext.DEFAULT_CHAR_SET_ENCODING;
             }
-            format.setSOAP11(msgContext.isSOAP11());
-            format.setCharSetEncoding(charSet);
 
-            parseMailToAddress(msgContext.getTo());
+            OMOutputFormat format = new OMOutputFormat();
 
+            format.setSOAP11(msgContext.isSOAP11());
+            format.setCharSetEncoding(charSet);
             // Check if msg is 'In-Reply-To' received message
             OutTransportInfo transportInfo = (OutTransportInfo) msgContext
                     .getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
@@ -220,50 +213,15 @@
                 sender.setInReplyTo(mailTransportInfo.getInReplyTo());
                 sender.setFrom(mailTransportInfo.getFrom());
             }
+            sender.setFormat(format);
 
-            sender.send(mailToInfo, format);
+            sender.send();
 
         } catch (IOException e) {
             throw new AxisFault(e);
         }
     }
 
-    private void parseMailToAddress(EndpointReference epr) {
-        String eprAddress = epr.getAddress();
-        //TODO URl validation according to rfc :  http://www.ietf.org/rfc/rfc2368.txt
-
-        int mailToIndex = eprAddress.indexOf("mailto:");
-        if (mailToIndex > -1) {
-            eprAddress = eprAddress.substring(mailToIndex + 7);
-        }
-        int index = eprAddress.indexOf('?');
-        String contentDescription = "";
-        String email;
-        boolean xServicePath = false;
-
-
-        if (index > -1) {
-            email = eprAddress.substring(0, index);
-        } else {
-            email = eprAddress;
-        }
-
-        if (eprAddress.indexOf(Constants.X_SERVICE_PATH) > -1) {
-            index = eprAddress.indexOf('=');
-            if (index > -1) {
-                xServicePath = true;
-                contentDescription = eprAddress.substring(index + 1);
-            }
-        } else {
-            contentDescription = eprAddress.substring(index + 1);
-
-        }
-        mailToInfo.setContentDescription(contentDescription);
-        mailToInfo.setEmailAddress(email);
-        mailToInfo.setxServicePath(xServicePath);
-
-    }
-
     public void writeMimeMessage(MessageContext msgContext, OutputStream out) throws AxisFault {
         try {
             OMOutputFormat format = new OMOutputFormat();
@@ -283,7 +241,6 @@
     }
 
     /**
-     *
      * @param msgContext
      * @return
      * @throws AxisFault

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java?view=diff&rev=526093&r1=526092&r2=526093
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java Fri Apr  6 01:24:04 2007
@@ -140,7 +140,7 @@
             }
 
             //Transport specific
-            if (paramKey.equals(org.apache.axis2.transport.mail.Constants.RAPLY_TO)) {
+            if (paramKey.equals(org.apache.axis2.transport.mail.Constants.REPLY_TO)) {
                 replyTo = paramValue;
             }
             if (paramKey.equals(org.apache.axis2.transport.mail.Constants.LISTENER_INTERVAL)) {
@@ -169,10 +169,10 @@
 
     }
 
-    public void initFromRuntime(Properties properties,MessageContext msgContext) throws AxisFault {
+    public void initFromRuntime(Properties properties, MessageContext msgContext) throws AxisFault {
 
         this.configurationContext = msgContext.getConfigurationContext();
-        
+
         String password = "";
         String host = "";
         String protocol = "";
@@ -187,7 +187,7 @@
         host = properties.getProperty(org.apache.axis2.transport.mail.Constants.POP3_HOST);
         protocol = properties.getProperty(org.apache.axis2.transport.mail.Constants.STORE_PROTOCOL);
         port = properties.getProperty(org.apache.axis2.transport.mail.Constants.POP3_PORT);
-        replyTo = properties.getProperty(org.apache.axis2.transport.mail.Constants.RAPLY_TO);
+        replyTo = properties.getProperty(org.apache.axis2.transport.mail.Constants.REPLY_TO);
         String value =
                 properties.getProperty(org.apache.axis2.transport.mail.Constants.LISTENER_INTERVAL);
         if (value != null) {
@@ -197,7 +197,7 @@
         if (password.length() == 0 || user.length() == 0 || host.length() == 0 ||
             protocol.length() == 0) {
             String error = SimpleMailListener.class.getName() + " one or more of Password, User," +
-                    " Host and Protocol are null or empty" + "in runtime settings";
+                           " Host and Protocol are null or empty" + "in runtime settings";
             log.error(error);
             throw new AxisFault(error);
         }
@@ -324,9 +324,11 @@
             msgContext.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
 
             MailBasedOutTransportInfo transportInfo = new MailBasedOutTransportInfo();
-            if (msg.getFrom() != null && msg.getFrom().length > 0) {
-                EndpointReference fromEPR = new EndpointReference((msg.getFrom()[0]).toString());
-                msgContext.setFrom(fromEPR);
+            Address[] mimefroms = msg.getFrom();
+            if (mimefroms != null && mimefroms.length > 0) {
+                EndpointReference fromEPR = new EndpointReference(
+                        org.apache.axis2.transport.mail.Constants.MAILTO + ":" +
+                        msg.getFrom()[0].toString());
                 transportInfo.setFrom(fromEPR);
             }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org