1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -109,40 +109,41 @@ protected Map<String, Object> extractStandardHeaders(MessageProperties amqpMessa
109
109
Map <String , Object > headers = new HashMap <>();
110
110
try {
111
111
JavaUtils .INSTANCE
112
- .acceptIfNotNull (AmqpHeaders .APP_ID , amqpMessageProperties .getAppId (), headers ::put )
113
- .acceptIfNotNull (AmqpHeaders .CLUSTER_ID , amqpMessageProperties .getClusterId (), headers ::put )
114
- .acceptIfNotNull (AmqpHeaders .CONTENT_ENCODING , amqpMessageProperties .getContentEncoding (),
115
- headers ::put );
112
+ .acceptIfNotNull (AmqpHeaders .APP_ID , amqpMessageProperties .getAppId (), headers ::put )
113
+ .acceptIfNotNull (AmqpHeaders .CLUSTER_ID , amqpMessageProperties .getClusterId (), headers ::put )
114
+ .acceptIfNotNull (AmqpHeaders .CONTENT_ENCODING , amqpMessageProperties .getContentEncoding (),
115
+ headers ::put );
116
116
long contentLength = amqpMessageProperties .getContentLength ();
117
117
JavaUtils .INSTANCE
118
- .acceptIfCondition (contentLength > 0 , AmqpHeaders .CONTENT_LENGTH , contentLength , headers ::put )
119
- .acceptIfHasText (AmqpHeaders .CONTENT_TYPE , amqpMessageProperties .getContentType (), headers ::put )
120
- .acceptIfHasText (AmqpHeaders .CORRELATION_ID , amqpMessageProperties .getCorrelationId (), headers ::put )
121
- .acceptIfNotNull (AmqpHeaders .RECEIVED_DELIVERY_MODE , amqpMessageProperties . getReceivedDeliveryMode () ,
122
- headers ::put );
118
+ .acceptIfCondition (contentLength > 0 , AmqpHeaders .CONTENT_LENGTH , contentLength , headers ::put )
119
+ .acceptIfHasText (AmqpHeaders .CONTENT_TYPE , amqpMessageProperties .getContentType (), headers ::put )
120
+ .acceptIfHasText (AmqpHeaders .CORRELATION_ID , amqpMessageProperties .getCorrelationId (), headers ::put )
121
+ .acceptIfNotNull (AmqpHeaders .RECEIVED_DELIVERY_MODE ,
122
+ amqpMessageProperties . getReceivedDeliveryMode (), headers ::put );
123
123
long deliveryTag = amqpMessageProperties .getDeliveryTag ();
124
124
JavaUtils .INSTANCE
125
- .acceptIfCondition (deliveryTag > 0 , AmqpHeaders .DELIVERY_TAG , deliveryTag , headers ::put )
126
- .acceptIfHasText (AmqpHeaders .EXPIRATION , amqpMessageProperties .getExpiration (), headers ::put );
125
+ .acceptIfCondition (deliveryTag > 0 , AmqpHeaders .DELIVERY_TAG , deliveryTag , headers ::put )
126
+ .acceptIfHasText (AmqpHeaders .EXPIRATION , amqpMessageProperties .getExpiration (), headers ::put );
127
127
Integer messageCount = amqpMessageProperties .getMessageCount ();
128
128
JavaUtils .INSTANCE
129
- .acceptIfCondition (messageCount != null && messageCount > 0 , AmqpHeaders .MESSAGE_COUNT , messageCount ,
130
- headers ::put )
131
- .acceptIfHasText (AmqpHeaders .MESSAGE_ID , amqpMessageProperties .getMessageId (), headers ::put );
129
+ .acceptIfCondition (messageCount != null && messageCount > 0 , AmqpHeaders .MESSAGE_COUNT ,
130
+ messageCount , headers ::put )
131
+ .acceptIfHasText (AmqpHeaders .MESSAGE_ID , amqpMessageProperties .getMessageId (), headers ::put );
132
132
Integer priority = amqpMessageProperties .getPriority ();
133
133
JavaUtils .INSTANCE
134
- .acceptIfCondition (priority != null && priority > 0 , IntegrationMessageHeaderAccessor .PRIORITY ,
135
- priority , headers ::put )
136
- .acceptIfNotNull (AmqpHeaders .RECEIVED_DELAY , amqpMessageProperties .getReceivedDelay (), headers ::put )
137
- .acceptIfNotNull (AmqpHeaders .RECEIVED_EXCHANGE , amqpMessageProperties .getReceivedExchange (),
138
- headers ::put )
139
- .acceptIfHasText (AmqpHeaders .RECEIVED_ROUTING_KEY , amqpMessageProperties .getReceivedRoutingKey (),
140
- headers ::put )
141
- .acceptIfNotNull (AmqpHeaders .REDELIVERED , amqpMessageProperties .isRedelivered (), headers ::put )
142
- .acceptIfNotNull (AmqpHeaders .REPLY_TO , amqpMessageProperties .getReplyTo (), headers ::put )
143
- .acceptIfNotNull (AmqpHeaders .TIMESTAMP , amqpMessageProperties .getTimestamp (), headers ::put )
144
- .acceptIfHasText (AmqpHeaders .TYPE , amqpMessageProperties .getType (), headers ::put )
145
- .acceptIfHasText (AmqpHeaders .RECEIVED_USER_ID , amqpMessageProperties .getReceivedUserId (), headers ::put );
134
+ .acceptIfCondition (priority != null && priority > 0 , IntegrationMessageHeaderAccessor .PRIORITY ,
135
+ priority , headers ::put )
136
+ .acceptIfNotNull (AmqpHeaders .RECEIVED_DELAY , amqpMessageProperties .getReceivedDelay (), headers ::put )
137
+ .acceptIfNotNull (AmqpHeaders .RECEIVED_EXCHANGE , amqpMessageProperties .getReceivedExchange (),
138
+ headers ::put )
139
+ .acceptIfHasText (AmqpHeaders .RECEIVED_ROUTING_KEY , amqpMessageProperties .getReceivedRoutingKey (),
140
+ headers ::put )
141
+ .acceptIfNotNull (AmqpHeaders .REDELIVERED , amqpMessageProperties .isRedelivered (), headers ::put )
142
+ .acceptIfNotNull (AmqpHeaders .REPLY_TO , amqpMessageProperties .getReplyTo (), headers ::put )
143
+ .acceptIfNotNull (AmqpHeaders .TIMESTAMP , amqpMessageProperties .getTimestamp (), headers ::put )
144
+ .acceptIfHasText (AmqpHeaders .TYPE , amqpMessageProperties .getType (), headers ::put )
145
+ .acceptIfHasText (AmqpHeaders .RECEIVED_USER_ID ,
146
+ amqpMessageProperties .getReceivedUserId (), headers ::put );
146
147
147
148
for (String jsonHeader : JsonHeaders .HEADERS ) {
148
149
Object value = amqpMessageProperties .getHeaders ().get (jsonHeader .replaceFirst (JsonHeaders .PREFIX , "" ));
@@ -151,6 +152,7 @@ protected Map<String, Object> extractStandardHeaders(MessageProperties amqpMessa
151
152
}
152
153
}
153
154
155
+ createJsonResolvableTypHeaderInAny (headers );
154
156
}
155
157
catch (Exception e ) {
156
158
if (logger .isWarnEnabled ()) {
@@ -160,6 +162,15 @@ protected Map<String, Object> extractStandardHeaders(MessageProperties amqpMessa
160
162
return headers ;
161
163
}
162
164
165
+ private void createJsonResolvableTypHeaderInAny (Map <String , Object > headers ) {
166
+ Object typeIdHeader = headers .get (JsonHeaders .TYPE_ID );
167
+ if (typeIdHeader != null ) {
168
+ headers .put (JsonHeaders .RESOLVABLE_TYPE ,
169
+ JsonHeaders .buildResolvableType (getClassLoader (), typeIdHeader ,
170
+ headers .get (JsonHeaders .CONTENT_TYPE_ID ), headers .get (JsonHeaders .KEY_TYPE_ID )));
171
+ }
172
+ }
173
+
163
174
/**
164
175
* Extract user-defined headers from an AMQP MessageProperties instance.
165
176
*/
@@ -186,28 +197,28 @@ protected void populateStandardHeaders(@Nullable Map<String, Object> allHeaders,
186
197
MessageProperties amqpMessageProperties ) {
187
198
188
199
JavaUtils .INSTANCE
189
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .APP_ID , String .class ),
190
- amqpMessageProperties ::setAppId )
191
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .CLUSTER_ID , String .class ),
192
- amqpMessageProperties ::setClusterId )
193
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .CONTENT_ENCODING , String .class ),
194
- amqpMessageProperties ::setContentEncoding )
195
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .CONTENT_LENGTH , Long .class ),
196
- amqpMessageProperties ::setContentLength )
197
- .acceptIfHasText (this .extractContentTypeAsString (headers ),
198
- amqpMessageProperties ::setContentType )
199
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .CORRELATION_ID , String .class ),
200
- amqpMessageProperties ::setCorrelationId )
201
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .DELAY , Integer .class ),
202
- amqpMessageProperties ::setDelay )
203
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .DELIVERY_MODE , MessageDeliveryMode .class ),
204
- amqpMessageProperties ::setDeliveryMode )
205
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .DELIVERY_TAG , Long .class ),
206
- amqpMessageProperties ::setDeliveryTag )
207
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .EXPIRATION , String .class ),
208
- amqpMessageProperties ::setExpiration )
209
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .MESSAGE_COUNT , Integer .class ),
210
- amqpMessageProperties ::setMessageCount );
200
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .APP_ID , String .class ),
201
+ amqpMessageProperties ::setAppId )
202
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .CLUSTER_ID , String .class ),
203
+ amqpMessageProperties ::setClusterId )
204
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .CONTENT_ENCODING , String .class ),
205
+ amqpMessageProperties ::setContentEncoding )
206
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .CONTENT_LENGTH , Long .class ),
207
+ amqpMessageProperties ::setContentLength )
208
+ .acceptIfHasText (this .extractContentTypeAsString (headers ),
209
+ amqpMessageProperties ::setContentType )
210
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .CORRELATION_ID , String .class ),
211
+ amqpMessageProperties ::setCorrelationId )
212
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .DELAY , Integer .class ),
213
+ amqpMessageProperties ::setDelay )
214
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .DELIVERY_MODE , MessageDeliveryMode .class ),
215
+ amqpMessageProperties ::setDeliveryMode )
216
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .DELIVERY_TAG , Long .class ),
217
+ amqpMessageProperties ::setDeliveryTag )
218
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .EXPIRATION , String .class ),
219
+ amqpMessageProperties ::setExpiration )
220
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .MESSAGE_COUNT , Integer .class ),
221
+ amqpMessageProperties ::setMessageCount );
211
222
String messageId = getHeaderIfAvailable (headers , AmqpHeaders .MESSAGE_ID , String .class );
212
223
if (StringUtils .hasText (messageId )) {
213
224
amqpMessageProperties .setMessageId (messageId );
@@ -219,16 +230,17 @@ else if (allHeaders != null) {
219
230
}
220
231
}
221
232
JavaUtils .INSTANCE
222
- .acceptIfNotNull (getHeaderIfAvailable (headers , IntegrationMessageHeaderAccessor .PRIORITY , Integer .class ),
223
- amqpMessageProperties ::setPriority )
224
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .RECEIVED_EXCHANGE , String .class ),
225
- amqpMessageProperties ::setReceivedExchange )
226
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .RECEIVED_ROUTING_KEY , String .class ),
227
- amqpMessageProperties ::setReceivedRoutingKey )
228
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .REDELIVERED , Boolean .class ),
229
- amqpMessageProperties ::setRedelivered )
230
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .REPLY_TO , String .class ),
231
- amqpMessageProperties ::setReplyTo );
233
+ .acceptIfNotNull (getHeaderIfAvailable (headers , IntegrationMessageHeaderAccessor .PRIORITY ,
234
+ Integer .class ),
235
+ amqpMessageProperties ::setPriority )
236
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .RECEIVED_EXCHANGE , String .class ),
237
+ amqpMessageProperties ::setReceivedExchange )
238
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .RECEIVED_ROUTING_KEY , String .class ),
239
+ amqpMessageProperties ::setReceivedRoutingKey )
240
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .REDELIVERED , Boolean .class ),
241
+ amqpMessageProperties ::setRedelivered )
242
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .REPLY_TO , String .class ),
243
+ amqpMessageProperties ::setReplyTo );
232
244
Date timestamp = getHeaderIfAvailable (headers , AmqpHeaders .TIMESTAMP , Date .class );
233
245
if (timestamp != null ) {
234
246
amqpMessageProperties .setTimestamp (timestamp );
@@ -240,18 +252,19 @@ else if (allHeaders != null) {
240
252
}
241
253
}
242
254
JavaUtils .INSTANCE
243
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .TYPE , String .class ),
244
- amqpMessageProperties ::setType )
245
- .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .USER_ID , String .class ),
246
- amqpMessageProperties ::setUserId );
255
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .TYPE , String .class ),
256
+ amqpMessageProperties ::setType )
257
+ .acceptIfNotNull (getHeaderIfAvailable (headers , AmqpHeaders .USER_ID , String .class ),
258
+ amqpMessageProperties ::setUserId );
247
259
248
260
mapJsonHeaders (headers , amqpMessageProperties );
249
261
250
262
JavaUtils .INSTANCE
251
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .SPRING_REPLY_CORRELATION , String .class ),
252
- replyCorrelation -> amqpMessageProperties .setHeader ("spring_reply_correlation" , replyCorrelation ))
253
- .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .SPRING_REPLY_TO_STACK , String .class ),
254
- replyToStack -> amqpMessageProperties .setHeader ("spring_reply_to" , replyToStack ));
263
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .SPRING_REPLY_CORRELATION , String .class ),
264
+ replyCorrelation -> amqpMessageProperties
265
+ .setHeader ("spring_reply_correlation" , replyCorrelation ))
266
+ .acceptIfHasText (getHeaderIfAvailable (headers , AmqpHeaders .SPRING_REPLY_TO_STACK , String .class ),
267
+ replyToStack -> amqpMessageProperties .setHeader ("spring_reply_to" , replyToStack ));
255
268
}
256
269
257
270
private void mapJsonHeaders (Map <String , Object > headers , MessageProperties amqpMessageProperties ) {
0 commit comments