INT-2874 Fix JSON/JMS Incompatibility

2.2.0 changed ObjectToJsonTransformr to add content-type to
simplify AMQP applications.

However, in a JMS environment, the DefaultJmsHeaderMapper attempted
to map (and failed) to map the header, emitting a warning log entry.

JMS does not allow '-' in property names.

Add code such that:

1. If the ObjectToJsonTransformer is configured to use a
content-type of an empty String (after trimming), suppress the
addition of the header to the output message. For consistency, if
the inbound message already has a content type header, and the transformer
is configured with an empty String, remove the header.

2. Change the DefaultJmsHeaderMapper to map the MessageHeaders.CONTENT_TYPE
header (content-type) to/from a JMS compliant property name (content_type).

INT-2874 PR Comments

Move constant to JmsHeaderMapper interface and rename.

Fix failing test (explicit set content-type to "").

INT-2874 Documentation Updates

Add docbook and schema documentation clarifying the behavior
of the transformer with respect to setting the `content-type`
header.

INT-2874 Polishing - Remove Header Removal

After further discussion, we decided to not remove an
existing header, if 'content-type' is set to "".

This is because there was no way to handle the case of
NOT adding a header when none present, while retaining a
header if it was already present.

added test for empty content-type attrib and no existing header (while merging)
This commit is contained in:
Gary Russell
2013-01-08 15:28:42 -05:00
committed by Mark Fisher
parent ed3cfe0271
commit 3902c96a20
8 changed files with 117 additions and 38 deletions

View File

@@ -230,8 +230,18 @@ public class Kid {
<important>
<para>
Beginning with version 2.2, the <code>object-to-json-transformer</code> sets the <emphasis>content-type</emphasis>
header to <emphasis>application/json</emphasis>, by default. It can be overridden using the <code>content-type</code>
attribute. The default behavior has a side affect - causing applications with the following
header to <code>application/json</code>, by default, if the input message does not already have that header
present.
</para>
<para>
It you wish to set the <emphasis>content type</emphasis> header to some other value, or explicitly overwrite any existing header
with some value (including <code>application/json</code>), use the <code>content-type</code>
attribute. If you wish to suppress the setting of the header, set the <code>content-type</code>
attribute to an empty string (<code>""</code>). This will result in a message with no <code>content-type</code>
header, unless such a header was present on the input message.
</para>
<para>
The behavior of adding the default header has a side affect - causing applications with the following
sequence to fail:
</para>
<para>