[jboss-svn-commits] JBL Code SVN: r7526 - in labs/jbossesb/trunk/product/core: listeners/src/org/jboss/soa/esb/actions rosetta/src/org/jboss/soa/esb/couriers

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 9 15:56:36 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-11-09 15:56:35 -0500 (Thu, 09 Nov 2006)
New Revision: 7526

Modified:
   labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
Log:
Moving the getTemporaryReplyEpr out to the CourierUtil.

Modified: labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java
===================================================================
--- labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java	2006-11-09 20:46:15 UTC (rev 7525)
+++ labs/jbossesb/trunk/product/core/listeners/src/org/jboss/soa/esb/actions/CbrProxyAction.java	2006-11-09 20:56:35 UTC (rev 7526)
@@ -31,7 +31,6 @@
 import org.apache.log4j.Priority;
 import org.jboss.soa.esb.addressing.Call;
 import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.addressing.eprs.JMSEpr;
 import org.jboss.soa.esb.couriers.Courier;
 import org.jboss.soa.esb.couriers.CourierException;
 import org.jboss.soa.esb.couriers.CourierFactory;
@@ -124,32 +123,26 @@
 					//Just use the first EPR in the list.
 					EPR epr = eprIterator.next();
 					Courier courier = CourierFactory.getCourier(epr);
+					EPR replyEpr =  getReplyToEpr(epr);
+					if (message.getHeader().getCall()==null) {
+						Call call = new Call();
+						message.getHeader().setCall(call);
+					}
+					message.getHeader().getCall().setReplyTo(replyEpr);
 					//If not successful try the next EPR
-					if (epr instanceof JMSEpr) {
-						//Setting the replyTo to the queue we specific in the epr we are going to call
-						//The selectors will do the job.
-						EPR replyEpr =  getReplyToEpr(epr);
-						if (message.getHeader().getCall()==null) {
-							Call call = new Call();
-							message.getHeader().setCall(call);
+					if (courier.deliver(message)) 
+					{
+						courier.setReplyToEpr(replyEpr);
+						try { 
+							//wait for the reply.
+							replyMessage = courier.pickup(_replyListenerTimeout);
+					    } catch (CourierTimeoutException e) {
+							throw new MessageRouterException(e.getLocalizedMessage(),e);
 						}
-						message.getHeader().getCall().setReplyTo(replyEpr);
-						//Send the message and wait for the reply.
-						if (courier.deliver(message)) 
-						{
-							courier.setReplyToEpr(replyEpr);
-							try { 
-								replyMessage = courier.pickup(_replyListenerTimeout);
-						    } catch (CourierTimeoutException e) {
-								throw new MessageRouterException(e.getLocalizedMessage(),e);
-							}
-						    //if we get here we were successful so we can break from the loop and reply.
-							break;
-						} else {
-							_logger.warn("Could not deliver the message, maybe there is another JMS-EPR we can use.");
-						}
+					    //if we get here we were successful so we can break from the loop and reply.
+						break;
 					} else {
-						_logger.warn("Found a non-JMS based EPR, but since we want a reply we need a JMS-EPR");
+						_logger.warn("Could not deliver the message, maybe there is another JMS-EPR we can use.");
 					}
 				} catch (URISyntaxException e) {
 					_logger.error(e.getLocalizedMessage(), e);
@@ -162,10 +155,19 @@
     	}
         return replyMessage;
     }
-    
-    private EPR getReplyToEpr(EPR epr) throws URISyntaxException
+    /**
+     * Builds a temporary EPR to which we can reply to.
+     *  
+     * @param epr - the toEPR
+     * @return 
+     * @throws URISyntaxException
+     */
+    private EPR getReplyToEpr(EPR toEpr) throws URISyntaxException, CourierException
     {
-//    	ConfigTree replyArgs = _config.getFirstChild("replyToEpr");
+//      At a later date we may support replying to a service defined in the configuration. For
+//      now we leave this out. However this is a rough example of what that code would look like.
+//
+//    	ConfigTree replyArgs = _config.getFirstChild("replyToService");
 //    	if (null!=replyArgs)
 //    	{
 //    		String category = replyArgs.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG);
@@ -180,10 +182,8 @@
 //    		catch (RegistryException e) { }
 //    	}
 //    	
-    	JMSEpr jpr = (JMSEpr) epr;
-		return new JMSEpr(jpr.getDestinationType()  ,jpr.getDestinationName()
-            ,jpr.getConnectionFactory(),jpr.getJndiType()
-            ,jpr.getJndiURL()          ,CourierUtil.getReplySelector());
+    	EPR replyToEpr = CourierUtil.getTemporaryReplyToEpr(toEpr);
+    	return replyToEpr;
     }
     
     /**
@@ -217,9 +217,8 @@
 				EPR epr = eprIterator.next();
 				Courier courier = CourierFactory.getCourier(epr);
 				//If not successful try the next EPR
-				if (courier.deliver(message))
-				{
-					break;
+				if (courier.deliver(message)) {
+					break; //we were successful so we are done
 				}
 			}
     	} catch (CourierException ce) {

Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java	2006-11-09 20:46:15 UTC (rev 7525)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java	2006-11-09 20:56:35 UTC (rev 7526)
@@ -22,10 +22,13 @@
 
 package org.jboss.soa.esb.couriers;
 
+import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
 
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.util.Util;
 
@@ -71,4 +74,30 @@
 		.append(uuId).append("'").toString();
     	return uniqueReplySelector;
 	}
+	
+    /**
+     * Build a temporary replyToEPR, based on the toEpr, to which we can reply to.
+     * <ul>
+     * <li> for JMS we will use the toEpr, but change the message selector.
+     * </ul>
+     *  
+     * @param toEpr - the toEPR which will be used a basis to generate the replyToEPR.
+     * @return replyToEPR - the EPR to which the pickup will be delivered.
+     * @throws URISyntaxException, CourierException
+     */
+    public static EPR getTemporaryReplyToEpr(EPR toEpr) throws URISyntaxException, CourierException
+    {
+    	EPR replyToEpr = null;
+    	if (toEpr instanceof JMSEpr) {
+	    	JMSEpr jpr = (JMSEpr) toEpr;
+            //Setting the replyTo to the queue we specific in the epr we are going to call
+			//The selectors will do the job.
+			replyToEpr =  new JMSEpr(jpr.getDestinationType()  ,jpr.getDestinationName()
+	            ,jpr.getConnectionFactory(),jpr.getJndiType()
+	            ,jpr.getJndiURL()          ,getReplySelector());
+    	} else {
+    		throw new CourierException("Found a non-JMS based EPR, JMS-EPRs is all we support right now");
+    	}
+    	return replyToEpr;
+    }
 }




More information about the jboss-svn-commits mailing list