You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by sa...@apache.org on 2007/03/21 16:11:55 UTC

svn commit: r520909 - in /webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail: EMailSender.java MailBasedOutTransportInfo.java MailTransportSender.java SimpleMailListener.java

Author: saminda
Date: Wed Mar 21 08:11:51 2007
New Revision: 520909

URL: http://svn.apache.org/viewvc?view=rev&rev=520909
Log:
Improvements to mail transport for handling sync, request/response at server side 

Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailBasedOutTransportInfo.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java?view=diff&rev=520909&r1=520908&r2=520909
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/EMailSender.java Wed Mar 21 08:11:51 2007
@@ -22,7 +22,10 @@
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.MessageContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.activation.CommandMap;
 import javax.activation.DataHandler;
@@ -51,6 +54,9 @@
     private PasswordAuthentication passwordAuthentication;
     private OutputStream outputStream;
     private String inReplyTo;
+    private EndpointReference from;
+
+    protected static Log log = LogFactory.getLog(EMailSender.class);
 
     static {
         //Initializing the proper mime types
@@ -95,19 +101,52 @@
             });
             MimeMessage msg = new MimeMessage(session);
 
-            /*from address is comming from mail.smtp.from property */
 
-            msg.addRecipient(Message.RecipientType.TO,
-                             new InternetAddress(mailToInfo.getEmailAddress()));
+            EndpointReference epr = null;
+
+            if (messageContext.getTo() != null && !messageContext.getTo().hasAnonymousAddress()) {
+                epr = messageContext.getTo();
+            }
+
+            if (epr != null) {
+                if (!epr.hasNoneAddress()) {
+                    msg.addRecipient(Message.RecipientType.TO,
+                                     new InternetAddress(mailToInfo.getEmailAddress()));
+
+                } else {
+                    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";
+                        log.error(error);
+                        throw new AxisFault(error);
+                    }
+                }
+            } 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);
+                    }
+
+                }
+            }
 
-//            Fix Subject TODO
             msg.setSubject("__ Axis2/Java Mail Message __");
 
             if (mailToInfo.isxServicePath()) {
                 msg.setHeader("X-Service-Path", "\"" + mailToInfo.getContentDescription() + "\"");
             }
 
-            if( inReplyTo != null ) {
+            if (inReplyTo != null) {
                 msg.setHeader("In-Reply-To", inReplyTo);
             }
 
@@ -144,7 +183,7 @@
                 .addHeader("Content-Description", "\"" + mailToInfo.getContentDescription() + "\"");
 
         String contentType = format.getContentType() != null ? format.getContentType() :
-                Constants.DEFAULT_CONTENT_TYPE;
+                             Constants.DEFAULT_CONTENT_TYPE;
         if (contentType.indexOf(SOAP11Constants.SOAP_11_CONTENT_TYPE) > -1) {
             if (messageContext.getSoapAction() != null) {
                 messageBodyPart.setHeader(Constants.HEADER_SOAP_ACTION,
@@ -156,8 +195,8 @@
             if (messageContext.getSoapAction() != null) {
                 messageBodyPart.setHeader("Content-Type",
                                           contentType + "; charset=" + format.getCharSetEncoding() +
-                                                  " ; action=\"" + messageContext.getSoapAction() +
-                                                  "\"");
+                                          " ; action=\"" + messageContext.getSoapAction() +
+                                          "\"");
             }
         } else {
             messageBodyPart.setHeader("Content-Type",
@@ -172,5 +211,9 @@
 
     public void setInReplyTo(String inReplyTo) {
         this.inReplyTo = inReplyTo;
+    }
+
+    public void setFrom(EndpointReference from) {
+        this.from = from;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailBasedOutTransportInfo.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailBasedOutTransportInfo.java?view=diff&rev=520909&r1=520908&r2=520909
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailBasedOutTransportInfo.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailBasedOutTransportInfo.java Wed Mar 21 08:11:51 2007
@@ -18,10 +18,12 @@
 package org.apache.axis2.transport.mail;
 
 import org.apache.axis2.transport.OutTransportInfo;
+import org.apache.axis2.addressing.EndpointReference;
 
 public class MailBasedOutTransportInfo implements OutTransportInfo {
     protected String contentType;
     protected String inReplyTo;
+    protected EndpointReference from;
 
     public void setContentType(String contentType) {
         this.contentType = contentType;
@@ -30,8 +32,16 @@
     public void setInReplyTo(String messageId) {
         this.inReplyTo = messageId;
     }
-    
+
     public String getInReplyTo() {
         return this.inReplyTo;
+    }
+
+    public EndpointReference getFrom() {
+        return from;
+    }
+
+    public void setFrom(EndpointReference from) {
+        this.from = from;
     }
 }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java?view=diff&rev=520909&r1=520908&r2=520909
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/MailTransportSender.java Wed Mar 21 08:11:51 2007
@@ -204,14 +204,17 @@
             format.setCharSetEncoding(charSet);
 
             parseMailToAddress(msgContext.getTo());
-            
+
             // Check if msg is 'In-Reply-To' received message
-            OutTransportInfo transportInfo = (OutTransportInfo) msgContext.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
-            
+            OutTransportInfo transportInfo = (OutTransportInfo) msgContext
+                    .getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
+
             if (transportInfo != null && transportInfo instanceof MailBasedOutTransportInfo) {
-                MailBasedOutTransportInfo mailTransportInfo = (MailBasedOutTransportInfo) transportInfo;
+                MailBasedOutTransportInfo mailTransportInfo =
+                        (MailBasedOutTransportInfo) transportInfo;
 
-                sender.setInReplyTo( mailTransportInfo.getInReplyTo() );
+                sender.setInReplyTo(mailTransportInfo.getInReplyTo());
+                sender.setFrom(mailTransportInfo.getFrom());
             }
 
             sender.send(mailToInfo, format);
@@ -287,28 +290,10 @@
         msgContext.setDoingMTOM(HTTPTransportUtils.doWriteMTOM(msgContext));
         msgContext.setDoingSwA(HTTPTransportUtils.doWriteSwA(msgContext));
 
-        EndpointReference epr = null;
-
-        if (msgContext.getTo() != null && !msgContext.getTo().hasAnonymousAddress()) {
-            epr = msgContext.getTo();
-        }
-
-        if (epr != null) {
-            if (!epr.hasNoneAddress()) {
-
-                byteArrayOutputStream = new ByteArrayOutputStream();
+        byteArrayOutputStream = new ByteArrayOutputStream();
+        writeMimeMessage(msgContext, byteArrayOutputStream);
 
-                writeMimeMessage(msgContext, byteArrayOutputStream);
-
-                sendMimeMessage(msgContext);
-            }
-        } else {
-            // TODO If epr is null or anonymous, then the flow shold be as
-            // replyto : from : or reply-path;
-            if (msgContext.isServerSide()) {
-
-            }
-        }
+        sendMimeMessage(msgContext);
 
         return InvocationResponse.CONTINUE;
     }

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java?view=diff&rev=520909&r1=520908&r2=520909
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/mail/SimpleMailListener.java Wed Mar 21 08:11:51 2007
@@ -149,7 +149,7 @@
 
         }
         if (password.length() == 0 || user.length() == 0 || host.length() == 0 ||
-                protocol.length() == 0) {
+            protocol.length() == 0) {
             throw new AxisFault(
                     "One or more of Password, User, Host and Protocol are null or empty");
         }
@@ -194,7 +194,7 @@
             if (transportIn != null) {
                 sas.init(configurationContext, transportIn);
                 log.info("Starting the SimpleMailListener with repository "
-                        + new File(args[0]).getAbsolutePath());
+                         + new File(args[0]).getAbsolutePath());
                 sas.start();
             } else {
                 log.info(
@@ -235,7 +235,7 @@
                                 messageQueue.add(mc);
                             }
                         } catch (Exception e) {
-                            log.error("Error in SimpleMailListener - processing mail " + e );
+                            log.error("Error in SimpleMailListener - processing mail " + e);
                         } finally {
                             // delete mail in any case
                             msg.setFlag(Flags.Flag.DELETED, true);
@@ -278,17 +278,20 @@
             msgContext.setProperty(org.apache.axis2.transport.mail.Constants.CONTENT_TYPE,
                                    msg.getContentType());
             msgContext.setIncomingTransportName(org.apache.axis2.Constants.TRANSPORT_MAIL);
+
+            MailBasedOutTransportInfo transportInfo = new MailBasedOutTransportInfo();
             if (msg.getFrom() != null && msg.getFrom().length > 0) {
-                msgContext.setFrom(new EndpointReference((msg.getFrom()[0]).toString()));
+                EndpointReference fromEPR = new EndpointReference((msg.getFrom()[0]).toString());
+                msgContext.setFrom(fromEPR);
+                transportInfo.setFrom(fromEPR);
             }
 
             // Save Message-Id to set as In-Reply-To on reply
             String smtpMessageId = msg.getMessageID();
-            if( smtpMessageId != null ) {
-                MailBasedOutTransportInfo transportInfo = new MailBasedOutTransportInfo();
-                transportInfo.setInReplyTo( smtpMessageId );
-                msgContext.setProperty( org.apache.axis2.Constants.OUT_TRANSPORT_INFO, transportInfo ) ;
+            if (smtpMessageId != null) {
+                transportInfo.setInReplyTo(smtpMessageId);
             }
+            msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, transportInfo);
 
             buildSOAPEnvelope(msg, msgContext);
         }
@@ -308,7 +311,6 @@
 
                     if (disposition != null && disposition.equals(Part.ATTACHMENT)) {
                         String soapAction = "";
-                        String soapNamespaceURI = "";
 
                         /* Set the Charactorset Encoding */
                         if (BuilderUtil.getCharSetEncoding(part.getContentType()) != null) {
@@ -337,7 +339,7 @@
                         }
 
                         if (part.getContentType().indexOf(SOAP12Constants.SOAP_12_CONTENT_TYPE) >
-                                -1) {
+                            -1) {
                             TransportUtils
                                     .processContentTypeForAction(part.getContentType(), msgContext);
                         }
@@ -428,7 +430,7 @@
 
     public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault {
         return new EndpointReference[]{new EndpointReference(Constants.TRANSPORT_MAIL + ":" +
-                replyTo + "?" + configurationContext
+                                                             replyTo + "?" + configurationContext
                 .getServiceContextPath() + "/" + serviceName)};
     }
 



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