Uploaded image for project: 'ActiveMQ .Net'
  1. ActiveMQ .Net
  2. AMQNET-53

Marshaling NULL BytesMessage in StompWireFormat throws exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • None
    • ActiveMQ
    • None
    • Windows XP SP2, .NET 2.0

    • Patch Available

    Description

      When marshalling a BytesMessage that has a NULL message body (only properties are set on the message) an exception is thrown within the WriteMessage() function. Following is a replacement version that will work correctly. A NULL pointer check is added to the content of the message. This only occurs with the STOMP protocol. The OpenWire implementation correctly handles the NULL message body in a BytesMessage.

      StompWireFormat.cs Replacement for WriteMessage()
      protected virtual void WriteMessage(ActiveMQMessage command, StompFrameStream ss)
      {
      	ss.WriteCommand(command, "SEND");
      	ss.WriteHeader("destination", StompHelper.ToStomp(command.Destination));
      	if (command.ReplyTo != null)
      		ss.WriteHeader("reply-to", StompHelper.ToStomp(command.ReplyTo));
      	if (command.CorrelationId != null )
      		ss.WriteHeader("correlation-id", command.CorrelationId);
      	if (command.Expiration != 0)
      		ss.WriteHeader("expires", command.Expiration);
      	if (command.Priority != 4)
      		ss.WriteHeader("priority", command.Priority);
      	if (command.Type != null)
      		ss.WriteHeader("type", command.Type);            
      	if (command.TransactionId!=null)
      		ss.WriteHeader("transaction", StompHelper.ToStomp(command.TransactionId));
      		    
      	ss.WriteHeader("persistent", command.Persistent);
      			
      	// lets force the content to be marshalled
      			
      	command.BeforeMarshall(null);
      	if (command is ActiveMQTextMessage)
      	{
      		ActiveMQTextMessage textMessage = command as ActiveMQTextMessage;
      		ss.Content = encoding.GetBytes(textMessage.Text);
      	}
      	else
      	{
      		ss.Content = command.Content;
      		if (null != command.Content)
      		{
      			ss.ContentLength = command.Content.Length;
      		}
      		else
      		{
      			ss.ContentLength = 0;
      		}
      	}
      	
      	IPrimitiveMap map = command.Properties;
      	foreach (string key in map.Keys)
      	{
      		ss.WriteHeader(key, map[key]);
      	}
      	ss.Flush();
      }
      

      Attachments

        Activity

          People

            jstrachan James Strachan
            jgomes Jim Gomes
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 1.25h
                1.25h
                Remaining:
                Remaining Estimate - 1.25h
                1.25h
                Logged:
                Time Spent - Not Specified
                Not Specified