[jboss-svn-commits] JBL Code SVN: r34650 - in labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta: tests/src/org/jboss/soa/esb/actions and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 11 17:12:58 EDT 2010


Author: kevin.conner at jboss.com
Date: 2010-08-11 17:12:58 -0400 (Wed, 11 Aug 2010)
New Revision: 34650

Added:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/Aggregator_JBESB_3308_UnitTest.java
Modified:
   labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/Aggregator.java
Log:
Pulled across fix for ReplyTo EPR must be manually reset after Aggregator action is used: JBESB-3311

Modified: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/Aggregator.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/Aggregator.java	2010-08-11 20:08:44 UTC (rev 34649)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/src/org/jboss/soa/esb/actions/Aggregator.java	2010-08-11 21:12:58 UTC (rev 34650)
@@ -29,6 +29,8 @@
 
 import org.apache.log4j.Logger;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
 import org.jboss.soa.esb.client.ServiceInvoker;
 import org.jboss.soa.esb.common.ModulePropertyManager;
 
@@ -36,6 +38,7 @@
 import static org.jboss.soa.esb.client.ServiceInvoker.INTERNAL_SERVICE_CATEGORY;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.listeners.message.MessageDeliverException;
+import org.jboss.soa.esb.message.Header;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.message.format.MessageFactory;
 import org.jboss.soa.esb.services.registry.RegistryException;
@@ -366,14 +369,15 @@
         List<String> aggregatedMessageTags = copyAggregationTags(messageMap);
         setAggregatorTags(aggregatedMessage, aggregatedMessageTags, false);
 
-        for (Message attachmentMessage : messageMap.values()) {
+        Collection<Message> attachmentMessages = messageMap.values();
+        for (Message attachmentMessage : attachmentMessages) {
             //Add the individual messages as attachments
             try {
                 // Clear the aggregation tags from the attachment message. Any future aggregation
                 // on the payload of these messages should be done within the context of the
                 // outer/aggregated message and it's tags.
                 setAggregatorTags(attachmentMessage, null, false);
-                aggregatedMessage.getAttachment().addItem(Util.serialize(attachmentMessage));
+                aggregatedMessage.getAttachment().addItem(Util.serialize(attachmentMessage));                
             } catch (ParserConfigurationException e) {
                 throw new ActionProcessingException("Message attachment serialization failure", e);
             } catch (IOException e) {
@@ -381,6 +385,9 @@
             }
         }
         
+        // Map the call details from the attached messages...
+        mapCallDetails(attachmentMessages, aggregatedMessage, uuId);
+        
         synchronized (aggregatedMessageMap)
         {
         	aggregatedMessageMap.remove(uuId);
@@ -391,7 +398,43 @@
         return aggregatedMessage;
     }
 
-    private List<String> copyAggregationTags(Map<Integer, Message> messageMap) {
+	protected static void mapCallDetails(Collection<Message> attachmentMessages, Message aggregatedMessage, String uuId) {
+		Set<EPR> replyToEPRs = new HashSet<EPR>();
+		int eprCount = 0;
+
+        for (Message attachmentMessage : attachmentMessages) {
+        	Header header = attachmentMessage.getHeader();
+			if(header != null) {
+            	Call call = header.getCall();
+				if(call != null) {
+            		replyToEPRs.add(call.getReplyTo());
+            		eprCount++;
+            	}
+        	}
+        }
+		
+        // Only map the replyTo EPR if all attachments have the same replyTo EPR...
+        if(replyToEPRs.size() == 1 && eprCount == attachmentMessages.size()) {
+        	Call call = aggregatedMessage.getHeader().getCall();
+			if(call == null) {
+				call = new Call();
+				aggregatedMessage.getHeader().setCall(call);
+			}			
+			call.setReplyTo(replyToEPRs.iterator().next());
+        } else if(logger.isDebugEnabled()) {
+        	if(replyToEPRs.size() == 0) {
+        		logger.debug("Not mapping replyTo EPR for aggregate message '" + uuId + "'.  No replyTo EPR to be mapped.");
+        	} else if(replyToEPRs.size() > 1) {
+        		logger.debug("Not mapping replyTo EPR for aggregate message '" + uuId + "'.  Not all replyTo EPRs are the same: " + replyToEPRs);
+        	} else {
+        		logger.debug("Not mapping replyTo EPR for aggregate message '" + uuId + "'.  Not all attachment messages have a replyTo EPR.");
+        	}
+        }
+        
+        // TODO: How about mapping faultTo etc...
+	}
+
+	private List<String> copyAggregationTags(Map<Integer, Message> messageMap) {
         // Get the tags from the first message...
         List<String> nestedAggregationTags = getAggregatorTags(messageMap.values().iterator().next(), aggregatorOnProperties);
 

Copied: labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/Aggregator_JBESB_3308_UnitTest.java (from rev 33593, labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/actions/Aggregator_JBESB_3308_UnitTest.java)
===================================================================
--- labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/Aggregator_JBESB_3308_UnitTest.java	                        (rev 0)
+++ labs/jbossesb/branches/JBESB_4_7_CP/product/rosetta/tests/src/org/jboss/soa/esb/actions/Aggregator_JBESB_3308_UnitTest.java	2010-08-11 21:12:58 UTC (rev 34650)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.actions;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.soa.esb.addressing.Call;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+import junit.framework.TestCase;
+
+/**
+ * Test for https://jira.jboss.org/browse/JBESB-3308.
+ * 
+ * @author <a href="mailto:tom.fennelly at gmail.com">tom.fennelly at gmail.com</a>
+ */
+public class Aggregator_JBESB_3308_UnitTest extends TestCase {
+
+	public void test_not_all_same_01() {
+		List<Message> attachmentMessages = createMessages(5);
+		Message aggregatedMessage = MessageFactory.getInstance().getMessage();
+		
+		// Modify one of the replyTos...
+		attachmentMessages.get(4).getHeader().getCall().setReplyTo(new EPR(URI.create("xproto://someother/address")));
+		
+		// Map... shouldn't map a replyTo because they're not all the same...
+		Aggregator.mapCallDetails(attachmentMessages, aggregatedMessage, "blah");
+		
+		assertNull(aggregatedMessage.getHeader().getCall().getReplyTo());
+	}
+
+	public void test_not_all_same_02() {
+		List<Message> attachmentMessages = createMessages(5);
+		Message aggregatedMessage = MessageFactory.getInstance().getMessage();
+		
+		// Modify one of the replyTos...
+		attachmentMessages.get(4).getHeader().getCall().setReplyTo(null);
+		
+		// Map... shouldn't map a replyTo because they're not all the same...
+		Aggregator.mapCallDetails(attachmentMessages, aggregatedMessage, "blah");
+		
+		assertNull(aggregatedMessage.getHeader().getCall().getReplyTo());
+	}
+
+	public void test_all_same() {
+		List<Message> attachmentMessages = createMessages(5);
+		Message aggregatedMessage = MessageFactory.getInstance().getMessage();
+		
+		// Map... should map a replyTo because they are all the same...
+		Aggregator.mapCallDetails(attachmentMessages, aggregatedMessage, "blah");
+		
+		assertEquals(new EPR(URI.create("xproto://some/address")), aggregatedMessage.getHeader().getCall().getReplyTo());
+	}
+
+	
+	
+	private List<Message> createMessages(int numMessages) {
+		List<Message> messages = new ArrayList<Message>();
+		
+		for(int i = 0; i < numMessages; i++) {
+			messages.add(MessageFactory.getInstance().getMessage());
+			Call call = new Call();
+			call.setReplyTo(new EPR(URI.create("xproto://some/address")));
+			messages.get(i).getHeader().setCall(call);
+		}
+		
+		return messages;
+	}
+}



More information about the jboss-svn-commits mailing list