[jboss-svn-commits] JBL Code SVN: r13853 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/soa/esb/actions and 6 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 30 11:37:38 EDT 2007


Author: mark.little at jboss.com
Date: 2007-07-30 11:37:38 -0400 (Mon, 30 Jul 2007)
New Revision: 13853

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/util/DefaultReplyTo.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/BytesMessage.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/IncompatibleModeException.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/InvalidPayloadException.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/MapMessage.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/ObjectMessage.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/Payload.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/TextMessage.java
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/payload/
   labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/payload/PayloadUnitTest.java
Modified:
   labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/ContentBasedWiretap.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/MessageFilter.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java
Log:
http://jira.jboss.com/jira/browse/JBESB-684

Modified: labs/jbossesb/trunk/product/docs/ProgrammersGuide.odt
===================================================================
(Binary files differ)

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/ContentBasedWiretap.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/ContentBasedWiretap.java	2007-07-30 15:29:28 UTC (rev 13852)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/ContentBasedWiretap.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -58,144 +58,178 @@
     public static final String DEFAULT_CBR_CLASS = "org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter";
 
     public ContentBasedWiretap(ConfigTree config)
-        throws ConfigurationException, RegistryException,
-            MessageRouterException
+	    throws ConfigurationException, RegistryException,
+	    MessageRouterException
     {
-        _config = config;
-        checkMyParms();
-        _registry = RegistryFactory.getRegistry();
-        _cbr = ContentBasedRouterFactory.getRouter(_cbrClass);
-        _mapper = new ObjectMapper();
+	_config = config;
+	checkMyParms();
+	_registry = RegistryFactory.getRegistry();
+	_cbr = ContentBasedRouterFactory.getRouter(_cbrClass);
+	_mapper = new ObjectMapper();
     }
 
-    public void initialise()
+    public void initialise ()
     {
-        if (_destinations.size() < 1)
-        {
-            _logger.warn("Missing or empty destination list - This action class won't have any effect");
-        }
+	if (_destinations.size() < 1)
+	{
+	    _logger
+		    .warn("Missing or empty destination list - This action class won't have any effect");
+	}
     }
 
     /**
-     * Router the message to one or more destinations, using the
-     * ContentBasedRouter to figure out to which destinations it is going to be
-     * routed too.
-     * 
-     * @param message
-     * @return Message
-     * @throws ActionProcessingException
-     */
-    public Message process(Message message) throws ActionProcessingException
+         * Router the message to one or more destinations, using the
+         * ContentBasedRouter to figure out to which destinations it is going to
+         * be routed too.
+         * 
+         * @param message
+         * @return Message
+         * @throws ActionProcessingException
+         */
+    public Message process (Message message) throws ActionProcessingException
     {
-        try
-        {
-            List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
-            List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage,
-                _ruleReload, message, objectList);
-            Collection<String[]> outgoingDestinations = new ArrayList<String[]>();
-            for (String destination : destinations)
-            {
-                if (_destinations.containsKey(destination))
-                {
-                    outgoingDestinations.add(_destinations.get(destination));
-                }
-            }
-            if (outgoingDestinations.size() > 0)
-            {
-                MessageRouter.deliverMessages(outgoingDestinations, message);
-            }
-            else if (destinations.size() > 0)
-            {
-                _logger.error("The rule destination(s) " + destinations
-                    + " are  not in found in the destination names in the configuration "
-                    + _destinations.keySet() + ". Please fix your configuration.");
+	try
+	{
+	    routeMessage(message);
 
-                MessageRouter.deliverMessage(MessageRouter.INTERNAL_SERVICE_CATEGORY,
-                    MessageRouter.DEAD_LETTER_SERVICE_NAME, message);
-            }
-            return message;
-        }
-        catch (MessageRouterException mre)
-        {
-            throw new ActionProcessingException(mre.getMessage(), mre);
-        }
+	    return message;
+	}
+	catch (MessageRouterException mre)
+	{
+	    throw new ActionProcessingException(mre.getMessage(), mre);
+	}
     }
 
+    protected void noDestinations ()
+    {
+	// nothing by default
+    }
+
+    protected void invalidRuleConfiguration (Message message,
+	    List<String> destinations) throws MessageRouterException
+    {
+	_logger
+		.error("The rule destination(s) "
+			+ destinations
+			+ " was not found in the destination names in the configuration "
+			+ _destinations.keySet()
+			+ ". Please fix your configuration.");
+
+	MessageRouter.deliverMessage(MessageRouter.INTERNAL_SERVICE_CATEGORY,
+		MessageRouter.DEAD_LETTER_SERVICE_NAME, message);
+    }
+
+    protected final void routeMessage (Message message)
+	    throws MessageRouterException
+    {
+	List<Object> objectList = _mapper.createObjectList(message,
+		_messagePathList);
+	List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage,
+		_ruleReload, message, objectList);
+	Collection<String[]> outgoingDestinations = new ArrayList<String[]>();
+	for (String destination : destinations)
+	{
+	    if (_destinations.containsKey(destination))
+	    {
+		outgoingDestinations.add(_destinations.get(destination));
+	    }
+	}
+	if (outgoingDestinations.size() > 0)
+	{
+	    MessageRouter.deliverMessages(outgoingDestinations, message);
+	}
+	else
+	{
+	    noDestinations();
+
+	    if (destinations.size() > 0)
+		invalidRuleConfiguration(message, destinations);
+	}
+    }
+
     /**
-     * Reading the piece of configTree specific to the CBR, and setting the
-     * configuration.
-     * 
-     * @throws ConfigurationException
-     */
-    protected void checkMyParms() throws ConfigurationException
+         * Reading the piece of configTree specific to the CBR, and setting the
+         * configuration.
+         * 
+         * @throws ConfigurationException
+         */
+    protected void checkMyParms () throws ConfigurationException
     {
-        if (_config.getAttribute(ListenerTagNames.RULE_SET_TAG) == null)
-        {
-            _logger.error("Required attribute " + ListenerTagNames.RULE_SET_TAG
-                + " not found in " + _config.getName() + ".");
-            throw new ConfigurationException("Required attribute"
-                + ListenerTagNames.RULE_SET_TAG + " not found.");
-        }
-        else
-        {
-            _ruleSet = _config.getAttribute(ListenerTagNames.RULE_SET_TAG);
-            if (_ruleSet == null)
-            {
-                throw new ConfigurationException("Required attribute "
-                    + ListenerTagNames.RULE_SET_TAG + " not found.");
-            }
-            _ruleLanguage = _config.getAttribute(ListenerTagNames.RULE_LANGUAGE_TAG);
-            String ruleReload = _config.getAttribute(ListenerTagNames.RULE_RELOAD_TAG);
-            if (ruleReload != null && "true".equals(ruleReload))
-            {
-                _ruleReload = true;
-            }
-        }
-        if (_config.getAttribute(ListenerTagNames.CBR_CLASS) != null)
-        {
-            _cbrClass = _config.getAttribute(ListenerTagNames.CBR_CLASS);
-        }
-        else
-        {
-            _cbrClass = DEFAULT_CBR_CLASS;
-        }
+	if (_config.getAttribute(ListenerTagNames.RULE_SET_TAG) == null)
+	{
+	    _logger.error("Required attribute " + ListenerTagNames.RULE_SET_TAG
+		    + " not found in " + _config.getName() + ".");
+	    throw new ConfigurationException("Required attribute"
+		    + ListenerTagNames.RULE_SET_TAG + " not found.");
+	}
+	else
+	{
+	    _ruleSet = _config.getAttribute(ListenerTagNames.RULE_SET_TAG);
+	    if (_ruleSet == null)
+	    {
+		throw new ConfigurationException("Required attribute "
+			+ ListenerTagNames.RULE_SET_TAG + " not found.");
+	    }
+	    _ruleLanguage = _config
+		    .getAttribute(ListenerTagNames.RULE_LANGUAGE_TAG);
+	    String ruleReload = _config
+		    .getAttribute(ListenerTagNames.RULE_RELOAD_TAG);
+	    if (ruleReload != null && "true".equals(ruleReload))
+	    {
+		_ruleReload = true;
+	    }
+	}
+	if (_config.getAttribute(ListenerTagNames.CBR_CLASS) != null)
+	{
+	    _cbrClass = _config.getAttribute(ListenerTagNames.CBR_CLASS);
+	}
+	else
+	{
+	    _cbrClass = DEFAULT_CBR_CLASS;
+	}
 
-        _destinations = new HashMap<String, String[]>();
-        ConfigTree[] destList = _config.getChildren(ROUTE_TO_TAG);
-        if (destList != null)
-        {
-            for (ConfigTree curr : destList)
-            {
-                try
-                {
-                    String key = curr.getRequiredAttribute(ListenerTagNames.DESTINATION_NAME_TAG);
-                    String category = curr.getAttribute(ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, "");
-                    String name = curr.getRequiredAttribute(ListenerTagNames.SERVICE_NAME_TAG);
-                    _destinations.put(key, new String[] { category, name });
-                }
-                catch (Exception e)
-                {
-                    throw new ConfigurationException("Problems with destination list", e);
-                }
-            }
-        }
-        _messagePathList = new ArrayList<String>();
-        ConfigTree[] objectList = _config.getChildren(OBJECT_PATH_TAG);
-        if (objectList != null)
-        {
-            for (ConfigTree curr : objectList)
-            {
-                try
-                {
-                    String objectPath = curr.getRequiredAttribute(OBJECT_PATH);
-                    _messagePathList.add(objectPath);
-                }
-                catch (Exception e)
-                {
-                    throw new ConfigurationException("Problems with object path list", e);
-                }
-            }
-        }
+	_destinations = new HashMap<String, String[]>();
+	ConfigTree[] destList = _config.getChildren(ROUTE_TO_TAG);
+	if (destList != null)
+	{
+	    for (ConfigTree curr : destList)
+	    {
+		try
+		{
+		    String key = curr
+			    .getRequiredAttribute(ListenerTagNames.DESTINATION_NAME_TAG);
+		    String category = curr.getAttribute(
+			    ListenerTagNames.SERVICE_CATEGORY_NAME_TAG, "");
+		    String name = curr
+			    .getRequiredAttribute(ListenerTagNames.SERVICE_NAME_TAG);
+		    _destinations.put(key, new String[]
+		    { category, name });
+		}
+		catch (Exception e)
+		{
+		    throw new ConfigurationException(
+			    "Problems with destination list", e);
+		}
+	    }
+	}
+	_messagePathList = new ArrayList<String>();
+	ConfigTree[] objectList = _config.getChildren(OBJECT_PATH_TAG);
+	if (objectList != null)
+	{
+	    for (ConfigTree curr : objectList)
+	    {
+		try
+		{
+		    String objectPath = curr.getRequiredAttribute(OBJECT_PATH);
+		    _messagePathList.add(objectPath);
+		}
+		catch (Exception e)
+		{
+		    throw new ConfigurationException(
+			    "Problems with object path list", e);
+		}
+	    }
+	}
 
     }
 
@@ -219,6 +253,7 @@
 
     protected org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter _cbr;
 
-    protected static Logger _logger = Logger.getLogger(ContentBasedWiretap.class);
+    protected static Logger _logger = Logger
+	    .getLogger(ContentBasedWiretap.class);
 
 }

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/MessageFilter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/MessageFilter.java	2007-07-30 15:29:28 UTC (rev 13852)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/actions/MessageFilter.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -27,8 +27,6 @@
  */
 package org.jboss.soa.esb.actions;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 
 import org.apache.log4j.Logger;
@@ -36,48 +34,53 @@
 import org.jboss.soa.esb.helpers.ConfigTree;
 import org.jboss.soa.esb.message.Message;
 import org.jboss.soa.esb.services.registry.RegistryException;
-import org.jboss.soa.esb.services.routing.MessageRouter;
 import org.jboss.soa.esb.services.routing.MessageRouterException;
 
 public class MessageFilter extends ContentBasedRouter
 {
-	public static final String ROUTE_TO_TAG = "route-to";
-	private Logger log = Logger.getLogger(this.getClass());
+    public static final String ROUTE_TO_TAG = "route-to";
 
-	public MessageFilter(ConfigTree config) throws ConfigurationException, RegistryException, MessageRouterException
+    private Logger log = Logger.getLogger(this.getClass());
+
+    public MessageFilter(ConfigTree config) throws ConfigurationException,
+	    RegistryException, MessageRouterException
+    {
+	super(config);
+    }
+
+    /**
+         * Inspect the content of the message using a rule set Router the
+         * message to one or more destinations, using the ContentBasedRouter to
+         * figure out to which destinations it is going to be routed too.
+         * 
+         * @param message
+         * @return Message
+         * @throws ActionProcessingException
+         */
+    public Message process (Message message) throws ActionProcessingException
+    {
+	try
 	{
-        super(config);
+	    
+	    routeMessage(message);
 	}
-	/** 
-     * Inspect the content of the message using a rule set 
-     * Router the message to one or more destinations, using the ContentBasedRouter to figure out
-     * to which destinations it is going to be routed too. 
-     *  
-     * @param message
-     * @return Message
-     * @throws ActionProcessingException
-	 */
-	public Message process(Message message) throws ActionProcessingException
+	catch (MessageRouterException mre)
 	{
-        try {
-            List<Object> objectList = _mapper.createObjectList(message, _messagePathList);
-            List<String> destinations = _cbr.route(_ruleSet, _ruleLanguage, _ruleReload, message, objectList);
-            Collection<String[]> outgoingDestinations = new ArrayList<String[]>();
-    		for (String destination : destinations) {
-                if (_destinations.containsKey(destination)) {
-                    outgoingDestinations.add(_destinations.get(destination));
-                }
-    		}
-            if (outgoingDestinations.size()>0) {
-                MessageRouter.deliverMessages(outgoingDestinations, message); 
-            } else {
-                log.debug("No destinations where found, the Message is filtered"); 
-            }
-        } catch (MessageRouterException mre) {
-            throw new ActionProcessingException(mre.getMessage(), mre);
-        }
-		return null;
+	    throw new ActionProcessingException(mre.getMessage(), mre);
 	}
-    
-    
+	
+	return null;
+    }
+
+    protected void noDestinations ()
+    {
+	log
+	.debug("No destinations where found, the Message is filtered");
+    }
+
+    protected void invalidRuleConfiguration (Message message,
+	    List<String> destinations) throws MessageRouterException
+    {
+	// do nothing
+    }
 }

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/util/DefaultReplyTo.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/util/DefaultReplyTo.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/addressing/util/DefaultReplyTo.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,96 @@
+package org.jboss.soa.esb.addressing.util;
+
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+
+import org.jboss.internal.soa.esb.addressing.eprs.DefaultFileReplyToEpr;
+import org.jboss.internal.soa.esb.addressing.eprs.DefaultFtpReplyToEpr;
+import org.jboss.internal.soa.esb.addressing.eprs.DefaultHibernateReplyToEpr;
+import org.jboss.internal.soa.esb.addressing.eprs.DefaultJdbcReplyToEpr;
+import org.jboss.internal.soa.esb.addressing.eprs.DefaultJmsReplyToEpr;
+import org.jboss.internal.soa.esb.addressing.eprs.DefaultSftpReplyToEpr;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.MalformedEPRException;
+import org.jboss.soa.esb.addressing.eprs.FTPEpr;
+import org.jboss.soa.esb.addressing.eprs.FileEpr;
+import org.jboss.soa.esb.addressing.eprs.HibernateEpr;
+import org.jboss.soa.esb.addressing.eprs.JDBCEpr;
+import org.jboss.soa.esb.addressing.eprs.JMSEpr;
+import org.jboss.soa.esb.addressing.eprs.SFTPEpr;
+import org.jboss.soa.esb.couriers.CourierException;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Provide some helper routines for common requirements.
+ */
+
+public class DefaultReplyTo
+{
+    /**
+         * Obtain a default replyToEPR (based on the toEpr) to which we can
+         * reply to.
+         * 
+         * @param toEpr -
+         *                the toEPR which will be used a basis to generate the
+         *                replyToEPR.
+         * @return EPR - the EPR to which the pickup will be delivered.
+         * @throws URISyntaxException,
+         *                 CourierException
+         */
+    
+    public static EPR getReplyTo (EPR toEpr) throws CourierException,
+	    MalformedEPRException
+    {
+	try
+	{
+	    if (null == toEpr)
+		throw new IllegalArgumentException("toEpr must not be null");
+	    if (toEpr instanceof JMSEpr)
+		return new DefaultJmsReplyToEpr((JMSEpr) toEpr);
+	    // Check for SFTPEpr first, as it extends FTPEpr
+	    if (toEpr instanceof SFTPEpr)
+		return new DefaultSftpReplyToEpr((SFTPEpr) toEpr);
+	    // Check for FTPEpr first, as it extends FileEpr
+	    if (toEpr instanceof FTPEpr)
+		return new DefaultFtpReplyToEpr((FTPEpr) toEpr);
+	    if (toEpr instanceof FileEpr)
+		return new DefaultFileReplyToEpr((FileEpr) toEpr);
+	    if (toEpr instanceof JDBCEpr)
+		return new DefaultJdbcReplyToEpr((JDBCEpr) toEpr);
+	    if (toEpr instanceof HibernateEpr)
+		return new DefaultHibernateReplyToEpr((HibernateEpr) toEpr);
+	}
+	catch (MalformedURLException ex)
+	{
+	    throw new MalformedEPRException(ex);
+	}
+	catch (URISyntaxException ex)
+	{
+	    throw new MalformedEPRException(ex);
+	}
+
+	throw new CourierException("Unsupported default reply to EPR "
+		+ toEpr.getClass().getSimpleName());
+    }
+
+}
\ No newline at end of file

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java	2007-07-30 15:29:28 UTC (rev 13852)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/format/MessageFactory.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -31,6 +31,10 @@
  * suitable for the service (hopefully you've got that contractual information a priori, but
  * maybe not) and in which case some translation/transformation may be necessary.
  * 
+ * Different ways of viewing and manipulating the Message Body (payload) are available separately
+ * via the Payload class. In future releases it will be possible to define the payload type at
+ * creation time.
+ * 
  * @author Mark Little
  *
  */

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/BytesMessage.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/BytesMessage.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/BytesMessage.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,263 @@
+package org.jboss.soa.esb.message.payload;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.jboss.internal.soa.esb.message.format.serialized.BodyImpl;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.payload.BytesMessage;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * The Message payload contains an arbitrary byte array that can be interpreted
+ * by the application as basic Java types.
+ * 
+ * The instance must be placed into either a read mode or write mode. You can switch
+ * between the two modes per instance, but each time you do it will reset the buffer.
+ * 
+ * When finished, you <i>must</i> flush the instance to the underlying payload implementation.
+ */
+
+public class BytesMessage
+{
+    private static final long serialVersionUID = 0xdeadbeef;
+    
+    public boolean readBoolean () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readBoolean();
+    }
+
+    public int readInt () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readInt();
+    }
+    
+    public long readLong () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readLong();
+    }
+    
+    public char readChar () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readChar();
+    }
+    
+    public double readDouble () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readDouble();
+    }
+    
+    public float readFloat () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readFloat();
+    }
+    
+    public short readShort () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readShort();
+    }
+    
+    public String readUTFString () throws IncompatibleModeException, IOException
+    {
+	if (!_readMode)
+	    throw new IncompatibleModeException();
+	
+	return _inputStream.readUTF();
+    }
+    
+    public void writeBoolean (boolean b) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeBoolean(b);
+    }
+    
+    public void writeInt (int i) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeInt(i);
+    }
+    
+    public void writeLong (long l) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeLong(l);
+    }
+    
+    public void writeChar (char c) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeChar(c);
+    }
+    
+    public void writeDouble (double d) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeDouble(d);
+    }
+    
+    public void writeFloat (float f) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeFloat(f);
+    }
+    
+    public void writeShort (short s) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeShort(s);
+    }
+    
+    public void writeUTFString (String s) throws IncompatibleModeException, IOException
+    {
+	if (_readMode)
+	    throw new IncompatibleModeException();
+	
+	_outputStream.writeUTF(s);
+    }
+    
+    /**
+     * Place the instance into read mode, so that the information within the
+     * byte stream can be retrieved.
+     * 
+     * @throws IOException
+     */
+    
+    public void readMode () throws IOException
+    {
+	flush();
+	
+	_readMode = true;
+	_inputStream = new ObjectInputStream(new ByteArrayInputStream(_payload.getByteArray()));
+	_outputStream = null;
+	_byteStream = null;
+    }
+    
+    /**
+     * Plce the instance into write mode, so that information may be placed within
+     * the byte stream.
+     * 
+     * @throws IOException
+     */
+    
+    public void writeMode () throws IOException
+    {
+	flush();
+	
+	_readMode = false;
+	_byteStream = new ByteArrayOutputStream();
+	_outputStream = new ObjectOutputStream(_byteStream);
+	_inputStream = null;
+    }
+    
+    /**
+     * Reset the internal buffer. The mode will remain the same.
+     * @throws IOException
+     */
+    
+    public void reset () throws IOException
+    {
+	if (_readMode)
+	    readMode();
+	else
+	    writeMode();
+    }
+    
+    /**
+     * Flush the internal byte array through to the payload.
+     * 
+     * @throws IOException
+     */
+    
+    public void flush () throws IOException
+    {
+	if (_outputStream != null)
+	{
+	    _outputStream.flush();
+	    _outputStream.close();
+	    
+	    _payload.setByteArray(_byteStream.toByteArray());
+	}
+	else
+	{
+	    if (_inputStream != null)
+		_inputStream.close();
+	}
+    }
+    
+    BytesMessage (Body payload) throws IOException
+    {
+	_payload = payload;
+	
+	if (payload.getByteArray() != null)
+	    readMode();
+	else
+	    writeMode();
+    }
+	
+    private Body _payload;
+    
+    private boolean _readMode;
+    
+    private ObjectOutputStream _outputStream;
+    private ObjectInputStream _inputStream;
+    private ByteArrayOutputStream _byteStream;
+
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/IncompatibleModeException.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/IncompatibleModeException.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/IncompatibleModeException.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,51 @@
+package org.jboss.soa.esb.message.payload;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Thrown if trying to read on a write-only buffer, or vice versa.
+ */
+
+public class IncompatibleModeException extends Exception
+{
+	private static final long serialVersionUID = 0xE124;
+	
+	public IncompatibleModeException()
+	{
+		super();
+	}
+
+	public IncompatibleModeException(String s)
+	{
+		super(s);
+	}
+
+	public IncompatibleModeException (Exception ex)
+	{
+		super(ex);
+	}
+
+	public IncompatibleModeException (String message, Exception ex)
+	{
+		super(ex);
+	}
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/InvalidPayloadException.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/InvalidPayloadException.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/InvalidPayloadException.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,51 @@
+package org.jboss.soa.esb.message.payload;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Thrown if unmarshalling fails.
+ */
+
+public class InvalidPayloadException extends Exception
+{
+	private static final long serialVersionUID = 0xE124;
+	
+	public InvalidPayloadException()
+	{
+		super();
+	}
+
+	public InvalidPayloadException(String s)
+	{
+		super(s);
+	}
+
+	public InvalidPayloadException (Exception ex)
+	{
+		super(ex);
+	}
+
+	public InvalidPayloadException (String message, Exception ex)
+	{
+		super(ex);
+	}
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/MapMessage.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/MapMessage.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/MapMessage.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,88 @@
+package org.jboss.soa.esb.message.payload;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.payload.InvalidPayloadException;
+import org.jboss.soa.esb.message.payload.MapMessage;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Tthe Message payload contains a Map of serializable Objects that can be
+ * inserted and retrieved as a Map.
+ */
+
+public class MapMessage
+{
+    private static final long serialVersionUID = 0xdeadbeef;
+
+    public void setMap (Map<String, Serializable> map)
+    {
+	if (map == null)
+	    throw new IllegalArgumentException();
+
+	Set<String> keys = map.keySet();
+	Iterator<String> iter = keys.iterator();
+
+	while (iter.hasNext())
+	{
+	    String key = iter.next();
+	    Serializable object = map.get(key);
+
+	    _payload.add(key, object);
+	}
+    }
+
+    public Map<String, Serializable> getMap () throws InvalidPayloadException
+    {
+	HashMap<String, Serializable> map = new HashMap<String, Serializable>();
+	String[] names = _payload.getNames();
+	
+	// assume all objects in message are from the map
+	
+	try
+	{
+        	for (int i = 0; i < names.length; i++)
+        	{
+        	    map.put(names[i], (Serializable) _payload.get(names[i]));
+        	}
+	}
+	catch (ClassCastException ex)
+	{
+	    throw new InvalidPayloadException(ex);
+	}
+	
+	return map;
+    }
+    
+    MapMessage (Body payload)
+    {
+	_payload = payload;
+    }
+    
+    private Body _payload;
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/ObjectMessage.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/ObjectMessage.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/ObjectMessage.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,81 @@
+package org.jboss.soa.esb.message.payload;
+
+import java.io.Serializable;
+
+import org.jboss.internal.soa.esb.message.format.serialized.BodyImpl;
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.payload.InvalidPayloadException;
+import org.jboss.soa.esb.message.payload.ObjectMessage;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Similar to JMS, the Message payload only contains a serializable Object.
+ */
+
+public class ObjectMessage
+{
+    public static final String ELEMENT_NAME = "org.jboss.soa.esb.message.payload.object";
+    
+    private static final long serialVersionUID = 0xdeadbeef;
+    
+    /**
+     * Add the Object element to the Body.
+     * 
+     * @param value the Object to add.
+     */
+    
+    public void setObject (Serializable value)
+    {
+	if (value == null)
+	    throw new IllegalArgumentException();
+	else
+	    _payload.add(ELEMENT_NAME, value);
+    }
+
+    /**
+     * Obtain the Object from the Body.
+     * 
+     * @return the Object.
+     */
+    
+    public Serializable getObject () throws InvalidPayloadException
+    {
+	try
+	{
+	    return (Serializable) _payload.get(ELEMENT_NAME);
+	}
+	catch (ClassCastException ex)
+	{
+	    // not serializable
+	    
+	    throw new InvalidPayloadException(ex);
+	}
+    }
+
+    ObjectMessage (Body payload)
+    {
+	_payload = payload;
+    }
+    
+    private Body _payload;
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/Payload.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/Payload.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/Payload.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,110 @@
+package org.jboss.soa.esb.message.payload;
+
+import java.io.IOException;
+
+import org.jboss.soa.esb.message.Message;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Different message formats represent views on the underlying Message Body,
+ * i.e., payload. They do not change how the content is represented on the wire,
+ * only how it can be more easily interpreted within the application. These are
+ * essentially helper classes.
+ */
+
+public class Payload
+{
+
+    /**
+     * View and manipulate the payload as an Object map.
+     * 
+     * @param msg the message.
+     * @return the MapMessage view.
+     */
+    
+    public static final MapMessage getAsMapMessage (Message msg)
+    {
+	if ((msg == null) || (msg.getBody() == null))
+	    return null;
+	else
+	    return new MapMessage(msg.getBody());
+    }
+    
+    /**
+     * View and manipulate the payload as an Object.
+     * 
+     * @param msg the message.
+     * @return the ObjectMessage view.
+     */
+    
+    public static final ObjectMessage getAsObjectMessage (Message msg)
+    {
+	if ((msg == null) || (msg.getBody() == null))
+	    return null;
+	else
+	    return new ObjectMessage(msg.getBody());
+    }
+    
+    /**
+     * View and manipulate the payload as Text.
+     * 
+     * @param msg the message.
+     * @return the TextMessage view.
+     */
+    
+    public static final TextMessage getAsTextMessage (Message msg)
+    {
+	if ((msg == null) || (msg.getBody() == null))
+	    return null;
+	else
+	    return new TextMessage(msg.getBody());
+    }
+    
+    /**
+     * View and manipulate the payload as a structured byte stream. When reading
+     * the BytesMessage, the byte array must already have been set on the Body or
+     * the instance is placed into a write-only mode.
+     * 
+     * @param msg the message.
+     * @param boolean <i>true</i> if the instance will be read from, <i>false</i> otherwise.
+     * @return the BytesMessage view.
+     */
+    
+    public static final BytesMessage getAsBytesMessage (Message msg, boolean readMode) throws IOException
+    {
+	if ((msg == null) || (msg.getBody() == null))
+	    return null;
+	else
+	{
+	    BytesMessage payload = new BytesMessage(msg.getBody());
+	    
+	    if (readMode)
+		payload.readMode();
+	    else
+		payload.writeMode();
+	    
+	    return payload;
+	}
+    }
+
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/TextMessage.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/TextMessage.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/message/payload/TextMessage.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,76 @@
+package org.jboss.soa.esb.message.payload;
+
+import org.jboss.soa.esb.message.Body;
+import org.jboss.soa.esb.message.payload.InvalidPayloadException;
+import org.jboss.soa.esb.message.payload.TextMessage;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated 
+ * by the @authors tag. All rights reserved. 
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors. 
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A 
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA  02110-1301, USA.
+ * 
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Similar to JMS, the Message payload only contains a String.
+ */
+
+public class TextMessage
+{
+    public static final String ELEMENT_NAME = "org.jboss.soa.esb.message.payload.text";
+    
+    private static final long serialVersionUID = 0xdeadbeef;
+    
+    /**
+     * Add the Text element to the Body.
+     * 
+     * @param value the String to add.
+     */
+    
+    public void setText (String value)
+    {
+	if (value == null)
+	    throw new IllegalArgumentException();
+	
+	_payload.add(ELEMENT_NAME, value);
+    }
+
+    /**
+     * Obtain the Text from the Body.
+     * 
+     * @return the String.
+     */
+    
+    public String getText () throws InvalidPayloadException
+    {
+	try
+	{
+	    return (String) _payload.get(ELEMENT_NAME);
+	}
+	catch (ClassCastException ex)
+	{
+	    throw new InvalidPayloadException(ex);
+	}
+    }
+
+    TextMessage (Body payload)
+    {
+	_payload = payload;
+    }
+    
+    private Body _payload;
+}
\ No newline at end of file

Added: labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/payload/PayloadUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/payload/PayloadUnitTest.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/tests/src/org/jboss/soa/esb/message/payload/PayloadUnitTest.java	2007-07-30 15:37:38 UTC (rev 13853)
@@ -0,0 +1,122 @@
+/*
+ * 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.message.payload;
+
+import java.io.Serializable;
+import java.util.Hashtable;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.format.MessageFactory;
+
+/**
+ * Unit tests for the Class class.
+ * 
+ * @author Mark Little
+ */
+
+public class PayloadUnitTest extends TestCase
+{
+    public void testMapMessage () throws Exception
+    {
+	Message msg = MessageFactory.getInstance().getMessage();
+
+	assertEquals((msg != null), true);
+	
+	MapMessage mapMessage = Payload.getAsMapMessage(msg);
+	Hashtable<String, Serializable> map = new Hashtable<String, Serializable>();
+	
+	map.put("foo", "bar");
+	map.put("hello", "world");
+	
+	mapMessage.setMap(map);
+	
+	Map<String, Serializable> payload = mapMessage.getMap();
+	
+	assertNotNull(payload);
+	
+	assertEquals(payload.get("foo"), "bar");
+	assertEquals(payload.get("hello"), "world");
+    }
+
+    public void testTextMessage () throws Exception
+    {
+	Message msg = MessageFactory.getInstance().getMessage();
+
+	assertEquals((msg != null), true);
+	
+	TextMessage mapMessage = Payload.getAsTextMessage(msg);
+	
+	mapMessage.setText("hello world");
+
+	assertEquals(mapMessage.getText(), "hello world");
+    }
+    
+    public void testObjectMessage () throws Exception
+    {
+	Message msg = MessageFactory.getInstance().getMessage();
+
+	assertEquals((msg != null), true);
+	
+	ObjectMessage mapMessage = Payload.getAsObjectMessage(msg);
+	
+	mapMessage.setObject("hello world");
+
+	assertEquals(mapMessage.getObject(), "hello world");
+    }
+    
+    public void testBytesMessage () throws Exception
+    {
+	Message msg = MessageFactory.getInstance().getMessage();
+
+	assertEquals((msg != null), true);
+	
+	BytesMessage mapMessage = Payload.getAsBytesMessage(msg, true);
+	
+	try
+	{
+	    mapMessage.writeBoolean(true);
+	    
+	    fail();
+	}
+	catch (IncompatibleModeException ex)
+	{
+	}
+	
+	mapMessage.writeMode();
+	
+	mapMessage.writeInt(12345);
+	mapMessage.writeUTFString("hello world");
+	mapMessage.writeShort((short) 10);
+	mapMessage.writeBoolean(true);
+	
+	mapMessage.readMode();
+	
+	assertEquals(mapMessage.readInt(), 12345);
+	assertEquals(mapMessage.readUTFString(), "hello world");
+	assertEquals(mapMessage.readShort(), (short) 10);
+	assertEquals(mapMessage.readBoolean(), true);
+    }
+}




More information about the jboss-svn-commits mailing list