use of org.springframework.integration.support.MutableMessageHeaders in project spring-integration by spring-projects.
the class MessageConvertingTcpMessageMapper method toMessage.
@Override
public Message<?> toMessage(TcpConnection connection, @Nullable Map<String, Object> headers) throws Exception {
Object data = connection.getPayload();
if (data != null) {
MessageHeaders messageHeaders = new MutableMessageHeaders(null, MessageHeaders.ID_VALUE_NONE, -1L) {
private static final long serialVersionUID = 3084692953798643018L;
};
addStandardHeaders(connection, messageHeaders);
addCustomHeaders(connection, messageHeaders);
if (headers != null) {
headers.forEach(messageHeaders::putIfAbsent);
}
return this.messageConverter.toMessage(data, messageHeaders);
} else {
if (logger.isWarnEnabled()) {
logger.warn("Null payload from connection " + connection.getConnectionId());
}
return null;
}
}
use of org.springframework.integration.support.MutableMessageHeaders in project spring-integration by spring-projects.
the class TcpMessageMapper method toMessage.
@SuppressWarnings("unchecked")
@Override
public Message<?> toMessage(TcpConnection connection, @Nullable Map<String, Object> headers) throws Exception {
Message<Object> message = null;
Object payload = connection.getPayload();
if (payload != null) {
AbstractIntegrationMessageBuilder<Object> messageBuilder;
if (this.bytesMessageMapper != null && payload instanceof byte[]) {
messageBuilder = (AbstractIntegrationMessageBuilder<Object>) getMessageBuilderFactory().fromMessage(this.bytesMessageMapper.toMessage((byte[]) payload));
} else {
messageBuilder = getMessageBuilderFactory().withPayload(payload);
}
MessageHeaders messageHeaders = new MutableMessageHeaders(null);
addStandardHeaders(connection, messageHeaders);
addCustomHeaders(connection, messageHeaders);
message = messageBuilder.copyHeaders(messageHeaders).copyHeadersIfAbsent(headers).build();
} else {
if (this.logger.isWarnEnabled()) {
this.logger.warn("Null payload from connection " + connection.getConnectionId());
}
}
return message;
}
use of org.springframework.integration.support.MutableMessageHeaders in project spring-cloud-stream by spring-cloud.
the class AvroMessageConverterSerializationTests method sourceWriteSameVersion.
@Test
public void sourceWriteSameVersion() throws Exception {
User specificRecord = new User();
specificRecord.setName("joe");
Schema v1 = new Schema.Parser().parse(AvroMessageConverterSerializationTests.class.getClassLoader().getResourceAsStream("schemas/user.avsc"));
GenericRecord genericRecord = new GenericData.Record(v1);
genericRecord.put("name", "joe");
SchemaRegistryClient client = new DefaultSchemaRegistryClient();
AvroSchemaRegistryClientMessageConverter converter = new AvroSchemaRegistryClientMessageConverter(client, new NoOpCacheManager());
converter.setSubjectNamingStrategy(new DefaultSubjectNamingStrategy());
converter.setDynamicSchemaGenerationEnabled(false);
converter.afterPropertiesSet();
Message specificMessage = converter.toMessage(specificRecord, new MutableMessageHeaders(Collections.<String, Object>emptyMap()), MimeTypeUtils.parseMimeType("application/*+avro"));
SchemaReference specificRef = extractSchemaReference(MimeTypeUtils.parseMimeType(specificMessage.getHeaders().get("contentType").toString()));
Message genericMessage = converter.toMessage(genericRecord, new MutableMessageHeaders(Collections.<String, Object>emptyMap()), MimeTypeUtils.parseMimeType("application/*+avro"));
SchemaReference genericRef = extractSchemaReference(MimeTypeUtils.parseMimeType(genericMessage.getHeaders().get("contentType").toString()));
Assert.assertEquals(genericRef, specificRef);
Assert.assertEquals(1, genericRef.getVersion());
}
use of org.springframework.integration.support.MutableMessageHeaders in project spring-integration by spring-projects.
the class EmbeddedJsonHeadersMessageMapper method decodeNativeFormat.
private Message<?> decodeNativeFormat(byte[] bytes, Map<String, Object> headersToAdd) throws Exception {
ByteBuffer buffer = ByteBuffer.wrap(bytes);
if (buffer.remaining() > 4) {
int headersLen = buffer.getInt();
if (headersLen >= 0 && headersLen < buffer.remaining() - 4) {
buffer.position(headersLen + 4);
int payloadLen = buffer.getInt();
if (payloadLen != buffer.remaining()) {
return null;
} else {
buffer.position(4);
@SuppressWarnings("unchecked") Map<String, Object> headers = this.objectMapper.readValue(bytes, buffer.position(), headersLen, HashMap.class);
buffer.position(buffer.position() + headersLen);
buffer.getInt();
Object payload;
byte[] payloadBytes = new byte[payloadLen];
buffer.get(payloadBytes);
payload = payloadBytes;
if (headersToAdd != null) {
headersToAdd.forEach(headers::putIfAbsent);
}
return new GenericMessage<>(payload, new MutableMessageHeaders(headers));
}
}
}
return null;
}
use of org.springframework.integration.support.MutableMessageHeaders in project spring-integration by spring-projects.
the class MessageJacksonDeserializer method convert.
@Override
public T convert(JsonNode root, DeserializationContext ctxt) throws IOException {
Map<String, Object> headers = this.mapper.readValue(root.get("headers").traverse(), TypeFactory.defaultInstance().constructMapType(HashMap.class, String.class, Object.class));
Object payload = this.mapper.readValue(root.get("payload").traverse(), this.payloadType);
return buildMessage(new MutableMessageHeaders(headers), payload, root, ctxt);
}
Aggregations