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/03 13:31:00 UTC

svn commit: r525139 - in /webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport: http/SimpleHTTPServer.java mail/Constants.java mail/EMailSender.java mail/SimpleMailListener.java mail/SynchronousMailListener.java

Author: saminda
Date: Tue Apr  3 04:30:59 2007
New Revision: 525139

URL: http://svn.apache.org/viewvc?view=rev&rev=525139
Log:
Improvements to mail transport to support simulated request/response 
based on Mail From and In-Reply-To headers. 

Added:
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java
Modified:
    webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
    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/SimpleMailListener.java

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java?view=diff&rev=525139&r1=525138&r2=525139
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java (original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/http/SimpleHTTPServer.java Tue Apr  3 04:30:59 2007
@@ -339,7 +339,7 @@
     }
 
 
-    public SessionContext getSessionContext(MessageContext messageContext) {
+    public SessionContext  getSessionContext(MessageContext messageContext) {
         String sessionKey = (String) messageContext.getProperty(HTTPConstants.COOKIE_STRING);
         return this.sessionManager.getSessionContext(sessionKey);
     }

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=525139&r1=525138&r2=525139
==============================================================================
--- 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 Tue Apr  3 04:30:59 2007
@@ -77,4 +77,6 @@
     public static final String MAIL_POP3 = "_MAIL_POP3_";
 
     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";
 }

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=525139&r1=525138&r2=525139
==============================================================================
--- 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 Tue Apr  3 04:30:59 2007
@@ -22,6 +22,7 @@
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.context.MessageContext;
 import org.apache.commons.logging.Log;
@@ -115,7 +116,7 @@
 
                 } else {
                     if (from != null) {
-                         msg.addRecipient(Message.RecipientType.TO,
+                        msg.addRecipient(Message.RecipientType.TO,
                                          new InternetAddress(from.getAddress()));
                     } else {
                         String error = EMailSender.class.getName() + "Couldn't countinue due to" +
@@ -143,15 +144,17 @@
             msg.setSubject("__ Axis2/Java Mail Message __");
 
             if (mailToInfo.isxServicePath()) {
-                msg.setHeader("X-Service-Path", "\"" + mailToInfo.getContentDescription() + "\"");
+                msg.setHeader(Constants.X_SERVICE_PATH, "\"" + mailToInfo.getContentDescription() + "\"");
             }
 
             if (inReplyTo != null) {
-                msg.setHeader("In-Reply-To", inReplyTo);
+                msg.setHeader(Constants.IN_REPLY_TO, inReplyTo);
             }
 
             createMailMimeMessage(msg, mailToInfo, format);
             Transport.send(msg);
+
+            sendReceive(messageContext,msg.getMessageID());
         } catch (AddressException e) {
             throw new AxisFault(e);
         } catch (MessagingException e) {
@@ -215,5 +218,18 @@
 
     public void setFrom(EndpointReference from) {
         this.from = from;
+    }
+
+    private void sendReceive(MessageContext msgContext, String msgId) throws AxisFault {
+        Object obj = msgContext.getProperty(Constants.MAIL_SYNC);
+        if (obj == null) {
+            return;
+        }
+
+        Options options = msgContext.getOptions();
+
+        SynchronousMailListener listener =
+                new SynchronousMailListener(options.getTimeOutInMilliSeconds());
+        listener.sendReceive(msgContext,msgId);
     }
 }

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=525139&r1=525138&r2=525139
==============================================================================
--- 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 Tue Apr  3 04:30:59 2007
@@ -91,6 +91,15 @@
     public SimpleMailListener() {
     }
 
+    /**
+     * This constructor will be used in when Mail simulate the request/response
+     *
+     * @param messageQueue
+     */
+    public SimpleMailListener(LinkedBlockingQueue messageQueue) {
+        this.messageQueue = messageQueue;
+    }
+
     public void init(ConfigurationContext configurationContext, TransportInDescription transportIn)
             throws AxisFault {
         this.configurationContext = configurationContext;
@@ -280,6 +289,11 @@
             if (smtpMessageId != null) {
                 transportInfo.setInReplyTo(smtpMessageId);
             }
+            String inReplyTo =
+                    getMailHeader(msg, org.apache.axis2.transport.mail.Constants.IN_REPLY_TO);
+            if (inReplyTo != null) {
+                transportInfo.setInReplyTo(inReplyTo);
+            }
             msgContext.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO, transportInfo);
 
             buildSOAPEnvelope(msg, msgContext);
@@ -435,5 +449,9 @@
 
     public void destroy() {
         this.configurationContext = null;
+    }
+
+    public LinkedBlockingQueue getLinkedBlockingQueue() {
+        return messageQueue;
     }
 }

Added: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java?view=auto&rev=525139
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java (added)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/mail/SynchronousMailListener.java Tue Apr  3 04:30:59 2007
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.transport.mail;
+
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingQueue;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+/*
+ * 
+ */
+
+public class SynchronousMailListener {
+
+    private static Log log = LogFactory.getLog(SynchronousMailListener.class);
+
+    private long timeoutInMilliseconds = -1;
+
+    public SynchronousMailListener(long timeoutInMilliseconds) {
+        this.timeoutInMilliseconds = timeoutInMilliseconds;
+    }
+
+
+    public void sendReceive(final MessageContext msgContext, final String msgId) throws AxisFault {
+        /**
+         * This will be bloked invocation
+         */
+        SimpleMailListener listener = new SimpleMailListener(new LinkedBlockingQueue()) {
+            public void start() throws AxisFault {
+                long timeStatus;
+                LinkedBlockingQueue queue = getLinkedBlockingQueue();
+                while (true) {
+                    long startTime = System.currentTimeMillis();
+                    try {
+                        MessageContext msgCtx = (MessageContext) queue.take();
+                        MailBasedOutTransportInfo transportInfo = (MailBasedOutTransportInfo) msgCtx
+                                .getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO);
+                        if (transportInfo.getInReplyTo() == null) {
+                            String error = EMailSender.class.getName() +" Coudn't simulate request/response without In-Reply-To Mail header";
+                            log.error(error);
+                            throw new AxisFault(error);
+                        }
+                        if (transportInfo.getInReplyTo().equals(msgId)) {
+                            msgContext.getOperationContext()
+                                    .getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE)
+                                    .setEnvelope(msgCtx.getEnvelope());
+                            log.info(SynchronousMailListener.class.getName() + " found the required message.");
+                            break;
+                        }
+
+                    } catch (InterruptedException e) {
+                        log.warn(e);
+                        throw new AxisFault(e);
+                    }
+                    long endTime = System.currentTimeMillis();
+                    timeStatus = endTime - startTime;
+                    if (timeoutInMilliseconds != -1 && timeStatus > timeoutInMilliseconds) {
+                        /*TODO What should be the best default value for timeoutInMilliseconds ?*/
+                        /*log.info(SynchronousMailListener.class.getName() + " timeout");
+                        break;*/
+                    }
+
+                }
+
+
+            }
+        };
+
+        TransportInDescription transportIn = msgContext.getConfigurationContext()
+                .getAxisConfiguration().getTransportIn(org.apache.axis2.Constants.TRANSPORT_MAIL);
+
+        listener.init(msgContext.getConfigurationContext(), transportIn);
+        msgContext.getConfigurationContext().getThreadPool().execute(listener);
+        listener.start();
+
+    }
+
+    public long getTimeoutInMilliseconds() {
+        return timeoutInMilliseconds;
+    }
+
+    public void setTimeoutInMilliseconds(long timeoutInMilliseconds) {
+        this.timeoutInMilliseconds = timeoutInMilliseconds;
+    }
+}



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