From 16ff848321afa198955342a24b56280bdfa831de Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 2 Nov 2012 11:28:03 -0400 Subject: [PATCH] INT-2797 Document JSON Transformer content-type Add note about content-type for the and the caveat for when using AMQP adapters. INT-2797 Polishing Add alternative solutions, including setting a defaultType on an inbound JsonMessageConverter. --- src/reference/docbook/transformer.xml | 62 +++++++++++++++++++++++++++ src/reference/docbook/whats-new.xml | 8 ++++ 2 files changed, 70 insertions(+) diff --git a/src/reference/docbook/transformer.xml b/src/reference/docbook/transformer.xml index 4f6aa77a2d..c70041b94d 100644 --- a/src/reference/docbook/transformer.xml +++ b/src/reference/docbook/transformer.xml @@ -227,6 +227,68 @@ public class Kid { ]]> + + + Beginning with version 2.2, the object-to-json-transformer sets the content-type + header to application/json, by default. It can be overridden using the content-type + attribute. The default behavior has a side affect - causing applications with the following + sequence to fail: + + + ->object-to-json-transformer->amqp-outbound-adapter----> + + + ---->amqp-inbound-adapter->json-to-object-transformer-> + + + This is because the default SimpleMessageConverter used by the inbound adapter doesn't + recognize this content type and the adapter emits a message with a byte[] payload instead of + String, which was the case with earlier versions. + + + If you are using this pattern, there are a number of ways to configure the environment so that JSON + conversion will be performed correctly. + + + One solution is to set the content type to a text type, so the inbound converter will convert the JSON to + String. This solution requires a change to just the outbound application. + + + ]]> + + + The second solution is to eliminate the json transformers altogether and use an + org.springframework.amqp.support.converter.JsonMessageConverter on both the + outbound and inbound adapters. This configures the adapters to perform the JSON conversion and + the transformers are not necessary. The converter on the outbound adapter adds + type information to the message properties; the inbound converter uses this type information for the conversion. + The converter is provided to the adapters using the message-converter attribute. + This solution requires a change to both the inbound and outbound applications. + + + The third solution is to eliminate the json-to-object-transformer in just + the inbound application and use an + org.springframework.amqp.support.converter.JsonMessageConverter on the + inbound adapter. The converter + is provided to the adapter using the message-converter attribute. + However, because there will be no type information in the message properties, + this also requires adding the defaultType to the converter, using the + same type as currently configured on the json-to-object-transformer. + This solution requires a change to just the inbound application. The configuration below shows + how to configure the message converter; it requires spring-amqp 1.1.3 or + above. + + + + + + + + + +]]> +
diff --git a/src/reference/docbook/whats-new.xml b/src/reference/docbook/whats-new.xml index 1eaeb7b8e5..991d35d74e 100644 --- a/src/reference/docbook/whats-new.xml +++ b/src/reference/docbook/whats-new.xml @@ -173,6 +173,14 @@ replies. This can improve performance of the gateway.
+
+ object-to-json-transformer + + The ObjectToJsonTransformer now sets the + content-type header to application/json + by default. For more information see . + +