[jboss-svn-commits] JBL Code SVN: r19028 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta: src/org/jboss/soa/esb/common and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Mar 16 17:32:35 EDT 2008


Author: mark.little at jboss.com
Date: 2008-03-16 17:32:35 -0400 (Sun, 16 Mar 2008)
New Revision: 19028

Modified:
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/JmsComposer.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
   labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1607

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/JmsComposer.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/JmsComposer.java	2008-03-16 21:29:08 UTC (rev 19027)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/couriers/helpers/JmsComposer.java	2008-03-16 21:32:35 UTC (rev 19028)
@@ -62,16 +62,15 @@
 
         if (!(incomingMessage instanceof ObjectMessage))
         {
-            LOGGER.error("Unsupported JMS message type: " + incomingMessage.getClass().getName()) ;
+            LOGGER.error("Unsupported JMS message type: " + incomingMessage.getClass().getName()+" for incoming ESB-aware message.");
             return null ;
         }
         try
         {
-            final ObjectMessage jmsMessage = (ObjectMessage)incomingMessage ;
-            
+            final ObjectMessage jmsMessage = (ObjectMessage)incomingMessage ;          
             final Serializable obj = (Serializable)jmsMessage.getObject() ;
-
             final Message composedMessage = Util.deserialize(obj) ;
+            
             propertiesSetter.setPropertiesFromJMSMessage(jmsMessage, composedMessage) ;
 
             /*

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java	2008-03-16 21:29:08 UTC (rev 19027)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/common/Environment.java	2008-03-16 21:32:35 UTC (rev 19028)
@@ -177,6 +177,7 @@
 	 */
 	
 	public static final String JMS_MESSAGE_ID = "org.jboss.soa.esb.message.transport.jms.messageID";
+	public static final String JMS_NATIVE_MESSAGE_TYPE = "org.jboss.soa.esb.message.transport.jms.nativeMessageType"; // Text or Object
 	
 	/*
 	 * Filter properties should be identified by:

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java	2008-03-16 21:29:08 UTC (rev 19027)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyFiles.java	2008-03-16 21:32:35 UTC (rev 19028)
@@ -34,6 +34,7 @@
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
+import java.io.Serializable;
 import java.net.URI;
 import java.net.URISyntaxException;
 
@@ -168,44 +169,57 @@
         final StringBuilder exceptions = new StringBuilder();
 		for (NotificationFile notificationFile : m_oaOutF)
 		{
-			try
+		    try
+		    {
+			fileOutStream = new FileOutputStream(notificationFile,
+				notificationFile.append);
+			Object obj = payloadProxy.getPayload(message);
+
+			/*
+			 * TODO
+			 * 
+			 * Hmmm, why was this keying off the ESB message type? Change it so
+			 * that if it's a byte[] or a String then we'll use the stringNotification.
+			 * Otherwise output as a generic Serializable. Slightly different to other
+			 * notifiers (except JMSNotifier), but probably the best we can do in the
+			 * situation.
+			 * 
+			 * http://jira.jboss.com/jira/browse/JBESB-1607
+			 */
+			
+			if ((obj instanceof Serializable) && !(obj instanceof byte[]) && !(obj instanceof String))
 			{
-				fileOutStream = new FileOutputStream(notificationFile,
-						notificationFile.append);
-				if (MessageType.JAVA_SERIALIZED.equals(message.getType()))
-				{
-                    objectNotification(fileOutStream, payloadProxy.getPayload(message));
-				}
-				else
-				{
-                    Object obj = payloadProxy.getPayload(message);
-                    String content=null;
-                    if (obj instanceof byte[]) {
-                        content = new String((byte[]) obj);
-                    } else {
-                        content = obj.toString();
-                    }
-                    stringNotification(fileOutStream, content);
-				}
+			    objectNotification(fileOutStream, payloadProxy.getPayload(message));
 			}
-			catch (IOException e)
+			else
 			{
-                handleException(notificationFile, e, exceptions);
+			    String content=null;
+			    if (obj instanceof byte[]) {
+				content = new String((byte[]) obj);
+			    } else {
+				content = obj.toString();
+			    }
+			    stringNotification(fileOutStream, content);
 			}
-            catch (MessageDeliverException e) {
-                handleException(notificationFile, e, exceptions);
-            } finally
+		    }
+		    catch (IOException e)
+		    {
+			handleException(notificationFile, e, exceptions);
+		    }
+		    catch (MessageDeliverException e) {
+			handleException(notificationFile, e, exceptions);
+		    } finally
+		    {
+			try
 			{
-				try
-				{
-					if ( fileOutStream != null )
-						fileOutStream.close();
-				}
-				catch (IOException eCl)
-				{
-					log.error( "IOException while closing fileOutStream: ", eCl );
-				}
+			    if ( fileOutStream != null )
+				fileOutStream.close();
 			}
+			catch (IOException eCl)
+			{
+			    log.error( "IOException while closing fileOutStream: ", eCl );
+			}
+		    }
 		}
 		if ( exceptions.length() > 0 )
 			throw new NotificationException( exceptions.toString() );

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java	2008-03-16 21:29:08 UTC (rev 19027)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/notification/NotifyJMS.java	2008-03-16 21:32:35 UTC (rev 19028)
@@ -22,6 +22,7 @@
 
 package org.jboss.soa.esb.notification;
 
+import java.io.Serializable;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Properties;
@@ -35,12 +36,14 @@
 import javax.naming.NamingException;
 
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.couriers.helpers.JmsComposer;
 import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
 import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPool;
 import org.jboss.internal.soa.esb.rosetta.pooling.JmsConnectionPoolContainer;
 import org.jboss.soa.esb.ConfigurationException;
 import org.jboss.soa.esb.listeners.message.MessageDeliverException;
 import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.KeyValuePair;
 import org.jboss.soa.esb.message.body.content.BytesBody;
@@ -64,6 +67,13 @@
  */
 public abstract class NotifyJMS extends NotificationTarget
 {
+    /*
+     * Value can be used to determine how the notification message
+     * will be represented on the JMS "wire".
+     */
+    
+    public static enum NativeMessage { text, object };
+    
     protected Logger log = Logger.getLogger(this.getClass());
 
 	/**
@@ -234,12 +244,37 @@
 	 */
 	public void sendNotification (org.jboss.soa.esb.message.Message esbMessage) throws NotificationException
 	{
+	    /*
+	     * Blah. We do this for backward compatibility.
+	     */
+	    
+	    NativeMessage defaultType = NativeMessage.text;
+	    
+	    if (esbMessage != null)
+	    {
+		if (esbMessage.getType().equals(MessageType.JAVA_SERIALIZED))
+		    defaultType = NativeMessage.object;
+	    }
+	    
+	    /*
+	     * http://jira.jboss.com/jira/browse/JBESB-1606
+	     * 
+	     * Prior to this, the JMS message type transmitted depended on the
+	     * ESB message type! That should be opaque and not affect how the contents
+	     * are transmitted. So we fixed it, but need to provide backward
+	     * compatibility for now. But the old approach/"feature" is essentially
+	     * deprecated.
+	     * 
+	     * http://jira.jboss.com/jira/browse/JBESB-1607
+	     */
+	    
 	    try
 	    {
 		Message jmsMessage = null;
 		Object obj = payloadProxy.getPayload(esbMessage);
-
-		if (MessageType.JAVA_SERIALIZED.equals(esbMessage.getType()))
+		NativeMessage type = (NativeMessage) esbMessage.getProperties().getProperty(Environment.JMS_NATIVE_MESSAGE_TYPE, defaultType);
+		
+		if (type == NativeMessage.object)
 		{
 		    if(obj == null) {
 			// create a null payload message...
@@ -247,7 +282,7 @@
 		    } else if(obj instanceof byte[]) {
 			jmsMessage = sessions[0].createObjectMessage((byte[]) obj);
 		    } else {
-			throw new NotificationException("Expected payload type for '" + MessageType.JAVA_SERIALIZED + "' is byte[].  Received '" + obj.getClass().getName() + "'.");
+			throw new NotificationException("Expected payload type for '" + esbMessage.getType() + "' is byte[].  Received '" + obj.getClass().getName() + "'.");
 		    }
 		}
 		else
@@ -260,7 +295,7 @@
 		    }
 		    jmsMessage = sessions[0].createTextMessage(content);
 		}
-
+		
 		setJMSProperties( esbMessage, jmsMessage );
 
 		for (Iterator II = m_oProps.keySet().iterator(); II.hasNext();)

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java	2008-03-16 21:29:08 UTC (rev 19027)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyQueuesUnitTest.java	2008-03-16 21:32:35 UTC (rev 19028)
@@ -43,8 +43,10 @@
 import junit.framework.JUnit4TestAdapter;
 
 import org.apache.log4j.Logger;
+import org.jboss.internal.soa.esb.couriers.helpers.JmsComposer;
 import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.NamingContextException;
 import org.jboss.soa.esb.helpers.NamingContextPool;
@@ -120,6 +122,7 @@
 	public void test_NonStringObj() throws Exception {
         org.jboss.soa.esb.message.Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
         message.getBody().add(((new Integer(123).toString().getBytes())));
+        message.getProperties().setProperty(Environment.JMS_NATIVE_MESSAGE_TYPE, NotifyJMS.NativeMessage.object);
 		notifyQueues.sendNotification(message);
 		
 		checkQueueObjectMessage(mockQueue1, 0, new Integer(123).toString().getBytes());
@@ -130,6 +133,7 @@
 	public void sendNotification_without_body() 
 	{
         org.jboss.soa.esb.message.Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+        message.getProperties().setProperty(Environment.JMS_NATIVE_MESSAGE_TYPE, NotifyJMS.NativeMessage.object);
 		try
 		{
 			notifyQueues.sendNotification(message);

Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java	2008-03-16 21:29:08 UTC (rev 19027)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/soa/esb/notification/NotifyTopicsUnitTest.java	2008-03-16 21:32:35 UTC (rev 19028)
@@ -38,8 +38,10 @@
 
 import junit.framework.TestCase;
 
+import org.jboss.internal.soa.esb.couriers.helpers.JmsComposer;
 import org.jboss.internal.soa.esb.rosetta.pooling.ConnectionException;
 import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.common.Environment;
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.helpers.NamingContextException;
 import org.jboss.soa.esb.helpers.NamingContextPool;
@@ -96,6 +98,7 @@
 	
 	public void test_NonStringObj() throws Exception {
         org.jboss.soa.esb.message.Message message = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+        message.getProperties().setProperty(Environment.JMS_NATIVE_MESSAGE_TYPE, NotifyJMS.NativeMessage.object);
         message.getBody().add((new Integer(123).toString().getBytes()));
 		notifyTopics.sendNotification(message);
 		




More information about the jboss-svn-commits mailing list