Make Message type pluggable
To improve compatibility between Spring's messaging classes and Spring Integration, the type of Message that is created has been made pluggable through the introduction of a factory abstraction; MessageFactory. By default a MessageFactory is provided that will create org.springframework.messaging.GenericMessage instances, however this can be replaced with an alternative implementation. For example, Spring Integration can provide an implementation that creates org.springframework.integration.message.GenericMessage instances. This control over the type of Message that's created allows messages to flow from Spring messaging code into Spring Integration code without any need for conversion. In further support of this goal, MessageChannel, MessageHandler, and SubscribableChannel have been genericized to make the Message type that they deal with more flexible.
This commit is contained in:
@@ -19,7 +19,9 @@ import java.util.Collections;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.messaging.GenericMessageFactory;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageFactory;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.web.messaging.MessageType;
|
||||
import org.springframework.web.messaging.stomp.StompCommand;
|
||||
@@ -35,19 +37,22 @@ public class StompMessageConverterTests {
|
||||
|
||||
private StompMessageConverter converter;
|
||||
|
||||
private MessageFactory messageFactory = new GenericMessageFactory();
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.converter = new StompMessageConverter();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void connectFrame() throws Exception {
|
||||
|
||||
String accept = "accept-version:1.1\n";
|
||||
String host = "host:github.org\n";
|
||||
String frame = "\n\n\nCONNECT\n" + accept + host + "\n";
|
||||
Message<byte[]> message = this.converter.toMessage(frame.getBytes("UTF-8"), "session-123");
|
||||
Message<byte[]> message = this.converter.toMessage(frame.getBytes("UTF-8"), "session-123", messageFactory);
|
||||
|
||||
assertEquals(0, message.getPayload().length);
|
||||
|
||||
@@ -71,13 +76,14 @@ public class StompMessageConverterTests {
|
||||
assertTrue(convertedBack.contains(host));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void connectWithEscapes() throws Exception {
|
||||
|
||||
String accept = "accept-version:1.1\n";
|
||||
String host = "ho\\c\\ns\\rt:st\\nomp.gi\\cthu\\b.org\n";
|
||||
String frame = "CONNECT\n" + accept + host + "\n";
|
||||
Message<byte[]> message = this.converter.toMessage(frame.getBytes("UTF-8"), "session-123");
|
||||
Message<byte[]> message = this.converter.toMessage(frame.getBytes("UTF-8"), "session-123", messageFactory);
|
||||
|
||||
assertEquals(0, message.getPayload().length);
|
||||
|
||||
@@ -93,13 +99,14 @@ public class StompMessageConverterTests {
|
||||
assertTrue(convertedBack.contains(host));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void connectCR12() throws Exception {
|
||||
|
||||
String accept = "accept-version:1.2\n";
|
||||
String host = "host:github.org\n";
|
||||
String test = "CONNECT\r\n" + accept.replaceAll("\n", "\r\n") + host.replaceAll("\n", "\r\n") + "\r\n";
|
||||
Message<byte[]> message = this.converter.toMessage(test.getBytes("UTF-8"), "session-123");
|
||||
Message<byte[]> message = this.converter.toMessage(test.getBytes("UTF-8"), "session-123", messageFactory);
|
||||
|
||||
assertEquals(0, message.getPayload().length);
|
||||
|
||||
@@ -115,13 +122,14 @@ public class StompMessageConverterTests {
|
||||
assertTrue(convertedBack.contains(host));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void connectWithEscapesAndCR12() throws Exception {
|
||||
|
||||
String accept = "accept-version:1.1\n";
|
||||
String host = "ho\\c\\ns\\rt:st\\nomp.gi\\cthu\\b.org\n";
|
||||
String test = "\n\n\nCONNECT\r\n" + accept.replaceAll("\n", "\r\n") + host.replaceAll("\n", "\r\n") + "\r\n";
|
||||
Message<byte[]> message = this.converter.toMessage(test.getBytes("UTF-8"), "session-123");
|
||||
Message<byte[]> message = this.converter.toMessage(test.getBytes("UTF-8"), "session-123", messageFactory);
|
||||
|
||||
assertEquals(0, message.getPayload().length);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user