use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class MethodInvokingSplitterTests method headerForMessageReturnValues.
@Test
public void headerForMessageReturnValues() throws Exception {
GenericMessage<String> message = new GenericMessage<String>("foo.bar");
MethodInvokingSplitter splitter = this.getSplitter("messageToMessageList");
QueueChannel replyChannel = new QueueChannel();
splitter.setOutputChannel(replyChannel);
splitter.handleMessage(message);
List<Message<?>> replies = replyChannel.clear();
Message<?> reply1 = replies.get(0);
assertNotNull(reply1);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply1).getSequenceSize());
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply1).getCorrelationId());
Message<?> reply2 = replies.get(1);
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceSize());
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(reply2).getCorrelationId());
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class JmsSendingMessageHandler method handleMessageInternal.
@Override
protected void handleMessageInternal(final Message<?> message) throws Exception {
if (message == null) {
throw new IllegalArgumentException("message must not be null");
}
Object destination = this.determineDestination(message);
Object objectToSend = (this.extractPayload) ? message.getPayload() : message;
MessagePostProcessor messagePostProcessor = new HeaderMappingMessagePostProcessor(message, this.headerMapper);
try {
DynamicJmsTemplateProperties.setPriority(new IntegrationMessageHeaderAccessor(message).getPriority());
this.send(destination, objectToSend, messagePostProcessor);
} finally {
DynamicJmsTemplateProperties.clearPriority();
}
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class MessageBuilderTests method testSequenceNumberAsLong.
@Test
public void testSequenceNumberAsLong() {
Message<String> message = MessageBuilder.withPayload("foo").setHeader(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Long.MAX_VALUE).build();
@SuppressWarnings("unused") Integer sequenceNumber = new IntegrationMessageHeaderAccessor(message).getSequenceNumber();
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class TcpMessageMapperTests method testToMessageSequenceNewWithCustomHeader.
@Test
public void testToMessageSequenceNewWithCustomHeader() throws Exception {
TcpMessageMapper mapper = new TcpMessageMapper() {
@Override
protected Map<String, ?> supplyCustomHeaders(TcpConnection connection) {
return Collections.singletonMap("foo", "bar");
}
};
mapper.setApplySequence(true);
Socket socket = SocketFactory.getDefault().createSocket();
TcpConnection connection = new TcpConnectionSupport(socket, false, false, null, null) {
@Override
public void run() {
}
@Override
public void send(Message<?> message) throws Exception {
}
@Override
public boolean isOpen() {
return false;
}
@Override
public int getPort() {
return 1234;
}
@Override
public Object getPayload() throws Exception {
return TEST_PAYLOAD.getBytes();
}
@Override
public String getHostName() {
return "MyHost";
}
@Override
public String getHostAddress() {
return "1.1.1.1";
}
@Override
public String getConnectionId() {
return "anId";
}
@Override
public Object getDeserializerStateKey() {
return null;
}
@Override
public SSLSession getSslSession() {
return null;
}
};
Message<?> message = mapper.toMessage(connection);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
IntegrationMessageHeaderAccessor headerAccessor = new IntegrationMessageHeaderAccessor(message);
assertEquals(1, headerAccessor.getSequenceNumber());
assertEquals(message.getHeaders().get(IpHeaders.CONNECTION_ID), headerAccessor.getCorrelationId());
message = mapper.toMessage(connection);
headerAccessor = new IntegrationMessageHeaderAccessor(message);
assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload()));
assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME));
assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS));
assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT));
assertEquals(2, headerAccessor.getSequenceNumber());
assertEquals(message.getHeaders().get(IpHeaders.CONNECTION_ID), headerAccessor.getCorrelationId());
assertNotNull(message.getHeaders().get("foo"));
assertEquals("bar", message.getHeaders().get("foo"));
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class StreamingInboundTests method testAllDataMaxFetch.
@SuppressWarnings("unchecked")
@Test
public void testAllDataMaxFetch() throws Exception {
StringSessionFactory sessionFactory = new StringSessionFactory();
Streamer streamer = new Streamer(new StringRemoteFileTemplate(sessionFactory), null);
streamer.setBeanFactory(mock(BeanFactory.class));
streamer.setRemoteDirectory("/foo");
streamer.setMaxFetchSize(1);
streamer.setFilter(new AcceptOnceFileListFilter<>());
streamer.afterPropertiesSet();
Message<byte[]> received = (Message<byte[]>) this.transformer.transform(streamer.receive());
assertEquals("foo\nbar", new String(received.getPayload()));
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
assertEquals("foo", received.getHeaders().get(FileHeaders.REMOTE_FILE));
// close after list, transform
verify(StaticMessageHeaderAccessor.getCloseableResource(received), times(2)).close();
received = (Message<byte[]>) this.transformer.transform(streamer.receive());
assertEquals("baz\nqux", new String(received.getPayload()));
assertEquals("/foo", received.getHeaders().get(FileHeaders.REMOTE_DIRECTORY));
assertEquals("bar", received.getHeaders().get(FileHeaders.REMOTE_FILE));
// close after list, transform
verify(new IntegrationMessageHeaderAccessor(received).getCloseableResource(), times(4)).close();
verify(sessionFactory.getSession(), times(2)).list("/foo");
}
Aggregations