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 ra...@apache.org on 2007/05/28 05:52:49 UTC

svn commit: r542099 - in /webservices/axis2/trunk/java/modules/kernel: src/org/apache/axis2/util/MessageContextBuilder.java test/org/apache/axis2/transport/jms/ test/org/apache/axis2/transport/jms/CorrelationIdPropagationTest.java

Author: rajith
Date: Sun May 27 20:52:48 2007
New Revision: 542099

URL: http://svn.apache.org/viewvc?view=rev&rev=542099
Log:
This is a fix for AXIS2-2681. If the jms correlation id is present, then it will be copied from the in message context to the out message ctx.
It will also be copied to a fault message context in case of an error. There is also a test case checked in to ensure the functionality is preserved during modifications.

Added:
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/jms/
    webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/jms/CorrelationIdPropagationTest.java
Modified:
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java?view=diff&rev=542099&r1=542098&r2=542099
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/MessageContextBuilder.java Sun May 27 20:52:48 2007
@@ -49,7 +49,10 @@
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.i18n.Messages;
 import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.jms.JMSConstants;
 import org.apache.axis2.wsdl.WSDLConstants;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
 import java.net.URI;
@@ -58,6 +61,8 @@
 import java.util.List;
 
 public class MessageContextBuilder {
+	
+	protected static final Log log = LogFactory.getLog(MessageContextBuilder.class);
 
     /**
      * Creates a new 'response' message context based on a 'request' message context
@@ -107,6 +112,7 @@
         newmsgCtx.setProperty(Constants.OUT_TRANSPORT_INFO,
                               inMessageContext.getProperty(Constants.OUT_TRANSPORT_INFO));
 
+        handleCorrelationID(inMessageContext,newmsgCtx);
         return newmsgCtx;
     }
 
@@ -183,8 +189,29 @@
 
         // Ensure transport settings match the scheme for the To EPR
         setupCorrectTransportOut(newmsgCtx);
-
         return newmsgCtx;
+    }
+
+    /**
+     * Copies the correlation id (jms) from the in message ctx
+     * to the out message ctx. Currently this check is for jms 
+     * only, but can be expanded to other transports if the need
+     * arises.
+     */
+    private static void handleCorrelationID(MessageContext inMessageContext,MessageContext outMessageContext)    
+    {
+    	if (inMessageContext.getIncomingTransportName()!= null &&
+    	    inMessageContext.getIncomingTransportName().equals(Constants.TRANSPORT_JMS))
+    	{
+    		log.debug("Incoming Transport is JMS, lets check for JMS correlation id");
+    		
+	    	String correlationId =
+	            (String) inMessageContext.getProperty(JMSConstants.JMS_COORELATION_ID);
+	    	log.debug("Correlation id is " + correlationId);
+	        if (correlationId != null && correlationId.length() > 0) {
+	        	outMessageContext.setProperty(JMSConstants.JMS_COORELATION_ID, correlationId);
+	        }
+    	}
     }
 
     /**

Added: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/jms/CorrelationIdPropagationTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/jms/CorrelationIdPropagationTest.java?view=auto&rev=542099
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/jms/CorrelationIdPropagationTest.java (added)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/transport/jms/CorrelationIdPropagationTest.java Sun May 27 20:52:48 2007
@@ -0,0 +1,48 @@
+package org.apache.axis2.transport.jms;
+
+import org.apache.axis2.Constants;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.util.MessageContextBuilder;
+
+import junit.framework.TestCase;
+
+/**
+ * A simple test added to check the copy of correlation
+ * id from the inMessageContext to the outMessageContext.
+ * 
+ * This simple test will serve as check in case the copying is
+ * broken during modifications.
+ */
+public class CorrelationIdPropagationTest extends TestCase {
+
+	public CorrelationIdPropagationTest(String arg0){
+		super(arg0);
+	}
+	
+	public void testCorrelationIdPropagation()throws Exception{
+		MessageContext inMsgCtx = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null).createMessageContext();
+		inMsgCtx.setIncomingTransportName(Constants.TRANSPORT_JMS);
+		String correlationId = "123Test";
+		inMsgCtx.setProperty(JMSConstants.JMS_COORELATION_ID, correlationId);
+		
+		MessageContext outMsgCtx = MessageContextBuilder.createOutMessageContext(inMsgCtx);
+		String corrId = (String)outMsgCtx.getProperty(JMSConstants.JMS_COORELATION_ID);
+		assertEquals("Correlation Id is not copied from in message ctx to out message ctx",correlationId,corrId);
+		
+		MessageContext faultMsgCtx = MessageContextBuilder.createFaultMessageContext(inMsgCtx, new Exception());
+		corrId = (String)faultMsgCtx.getProperty(JMSConstants.JMS_COORELATION_ID);
+		assertEquals("Correlation Id is not copied properly to fault message ctx",correlationId,corrId);
+	}
+	
+	public static void main(String[] args)
+	 {
+		 CorrelationIdPropagationTest t = new CorrelationIdPropagationTest("S");
+		 try{
+		 	t.testCorrelationIdPropagation();
+		 }catch(Exception e)
+		 {
+			 e.printStackTrace();
+		 }
+	 }
+}



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