You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by "Jim Gomes (JIRA)" <ji...@apache.org> on 2007/09/05 20:55:22 UTC

[jira] Created: (AMQNET-53) Marshaling NULL BytesMessage in StompWireFormat throws exception

Marshaling NULL BytesMessage in StompWireFormat throws exception
----------------------------------------------------------------

                 Key: AMQNET-53
                 URL: https://issues.apache.org/activemq/browse/AMQNET-53
             Project: ActiveMQ .Net
          Issue Type: Bug
          Components: Stomp
         Environment: Windows XP SP2, .NET 2.0
            Reporter: Jim Gomes
            Assignee: James Strachan


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.

{code:java|title=StompWireFormat.cs Replacement for WriteMessage()|borderStyle=solid}
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();
}
{code}


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (AMQNET-53) Marshaling NULL BytesMessage in StompWireFormat throws exception

Posted by "Jim Gomes (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/AMQNET-53?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_40080 ] 

Jim Gomes commented on AMQNET-53:
---------------------------------

A correlating change must be made in order to get empty BytesMessages to work correctly in the STOMP protocol implementation.  The StompFrameStream.Flush() method in StompFrameStream.cs file should be changed to the following.  The check for zero content length should be a less-than or equal comparison, not just a less-than comparison.

{code:java|title=StompFrameStream.cs|borderStyle=solid}
public void Flush()
{
	builder.Append(NEWLINE);
	ds.Write(encoding.GetBytes(builder.ToString()));

	if (content != null)
	{
		ds.Write(content);
	}

	// if no content length then lets write a null
	if (contentLength <= 0)
	{
		ds.Write(NULL);
	}
}
{code}


> Marshaling NULL BytesMessage in StompWireFormat throws exception
> ----------------------------------------------------------------
>
>                 Key: AMQNET-53
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-53
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: Stomp
>         Environment: Windows XP SP2, .NET 2.0
>            Reporter: Jim Gomes
>            Assignee: James Strachan
>   Original Estimate: 15 minutes
>  Remaining Estimate: 15 minutes
>
> 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.
> {code:java|title=StompWireFormat.cs Replacement for WriteMessage()|borderStyle=solid}
> 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();
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (AMQNET-53) Marshaling NULL BytesMessage in StompWireFormat throws exception

Posted by "Jim Gomes (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/AMQNET-53?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jim Gomes closed AMQNET-53.
---------------------------

    Resolution: Fixed

> Marshaling NULL BytesMessage in StompWireFormat throws exception
> ----------------------------------------------------------------
>
>                 Key: AMQNET-53
>                 URL: https://issues.apache.org/activemq/browse/AMQNET-53
>             Project: ActiveMQ .Net
>          Issue Type: Bug
>          Components: Stomp
>         Environment: Windows XP SP2, .NET 2.0
>            Reporter: Jim Gomes
>            Assignee: James Strachan
>   Original Estimate: 15 minutes
>  Remaining Estimate: 15 minutes
>
> 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.
> {code:java|title=StompWireFormat.cs Replacement for WriteMessage()|borderStyle=solid}
> 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();
> }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.