Java Code Examples for org.springframework.messaging.converter.StringMessageConverter

The following examples show how to use org.springframework.messaging.converter.StringMessageConverter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);

	Method method = this.getClass().getDeclaredMethod("getData");
	this.subscribeEventReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getDataAndSendTo");
	this.subscribeEventSendToReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handle");
	this.messageMappingReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getJsonView");
	this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
 
Example 2
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	int port = SocketUtils.findAvailableTcpPort(61613);

	this.activeMQBroker = new BrokerService();
	this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port);
	this.activeMQBroker.setStartAsync(false);
	this.activeMQBroker.setPersistent(false);
	this.activeMQBroker.setUseJmx(false);
	this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5);
	this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5);
	this.activeMQBroker.start();

	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.afterPropertiesSet();

	this.client = new ReactorNettyTcpStompClient("127.0.0.1", port);
	this.client.setMessageConverter(new StringMessageConverter());
	this.client.setTaskScheduler(taskScheduler);
}
 
Example 3
@Test
public void configureMessageConvertersCustomAndDefault() {
	final MessageConverter testConverter = mock(MessageConverter.class);

	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
		@Override
		protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
			messageConverters.add(testConverter);
			return true;
		}
	};
	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();

	assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
	Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
	assertThat(iterator.next(), Matchers.is(testConverter));
	assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
 
Example 4
@Before
public void setup() throws Exception {
	this.resolver = new PayloadMethodArgumentResolver(new StringMessageConverter(), testValidator());

	Method payloadMethod = PayloadMethodArgumentResolverTests.class.getDeclaredMethod(
			"handleMessage", String.class, String.class, Locale.class,
			String.class, String.class, String.class, String.class);

	this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0);
	this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1);
	this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
	this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
	this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
	this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
	this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
}
 
Example 5
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	this.wac = new AnnotationConfigWebApplicationContext();
	this.wac.register(TestConfig.class);
	this.wac.refresh();

	this.server = new TomcatWebSocketTestServer();
	this.server.setup();
	this.server.deployConfig(this.wac);
	this.server.start();

	WebSocketClient webSocketClient = new StandardWebSocketClient();
	this.stompClient = new WebSocketStompClient(webSocketClient);
	this.stompClient.setMessageConverter(new StringMessageConverter());
}
 
Example 6
Source Project: WeEvent   Source File: StompTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
    log.info("=============================={}.{}==============================",
            this.getClass().getSimpleName(),
            this.testName.getMethodName());

    String brokerStomp = "ws://localhost:" + this.listenPort + "/weevent-broker/stomp";
    ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
    taskScheduler.initialize();

    this.stompClient = new WebSocketStompClient(new StandardWebSocketClient());

    // MappingJackson2MessageConverter
    stompClient.setMessageConverter(new StringMessageConverter());
    stompClient.setTaskScheduler(taskScheduler); // for heartbeats

    this.header.setDestination(topic);
    this.header.set("eventId", WeEvent.OFFSET_LAST);
    this.header.set("groupId", WeEvent.DEFAULT_GROUP_ID);

    this.failure = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    this.stompSession = this.stompClient.connect(brokerStomp, new MyStompSessionHandler(latch, this.failure)).get();
    latch.await();
    this.stompSession.setAutoReceipt(true);
}
 
Example 7
/**
 * Create an instance of SimpAnnotationMethodMessageHandler with the given
 * message channels and broker messaging template.
 * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
 * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
 * @param brokerTemplate a messaging template to send application messages to the broker
 */
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
		MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {

	Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
	Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
	Assert.notNull(brokerTemplate, "brokerTemplate must not be null");

	this.clientInboundChannel = clientInboundChannel;
	this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
	this.brokerTemplate = brokerTemplate;

	Collection<MessageConverter> converters = new ArrayList<>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}
 
Example 8
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);

	Method method = this.getClass().getDeclaredMethod("getData");
	this.subscribeEventReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getDataAndSendTo");
	this.subscribeEventSendToReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handle");
	this.messageMappingReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getJsonView");
	this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
 
Example 9
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	int port = SocketUtils.findAvailableTcpPort(61613);

	this.activeMQBroker = new BrokerService();
	this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port);
	this.activeMQBroker.setStartAsync(false);
	this.activeMQBroker.setPersistent(false);
	this.activeMQBroker.setUseJmx(false);
	this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5);
	this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5);
	this.activeMQBroker.start();

	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.afterPropertiesSet();

	this.client = new ReactorNettyTcpStompClient("127.0.0.1", port);
	this.client.setMessageConverter(new StringMessageConverter());
	this.client.setTaskScheduler(taskScheduler);
}
 
Example 10
@Test
public void configureMessageConvertersCustomAndDefault() {
	final MessageConverter testConverter = mock(MessageConverter.class);

	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
		@Override
		protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
			messageConverters.add(testConverter);
			return true;
		}
	};
	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();

	assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
	Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
	assertThat(iterator.next(), Matchers.is(testConverter));
	assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
 
Example 11
@Before
public void setup() throws Exception {

	this.resolver = new PayloadArgumentResolver(new StringMessageConverter(), testValidator());

	Method payloadMethod = PayloadArgumentResolverTests.class.getDeclaredMethod(
			"handleMessage", String.class, String.class, Locale.class,
			String.class, String.class, String.class, String.class);

	this.paramAnnotated = new SynthesizingMethodParameter(payloadMethod, 0);
	this.paramAnnotatedNotRequired = new SynthesizingMethodParameter(payloadMethod, 1);
	this.paramAnnotatedRequired = new SynthesizingMethodParameter(payloadMethod, 2);
	this.paramWithSpelExpression = new SynthesizingMethodParameter(payloadMethod, 3);
	this.paramValidated = new SynthesizingMethodParameter(payloadMethod, 4);
	this.paramValidated.initParameterNameDiscovery(new LocalVariableTableParameterNameDiscoverer());
	this.paramValidatedNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 5);
	this.paramNotAnnotated = new SynthesizingMethodParameter(payloadMethod, 6);
}
 
Example 12
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	this.wac = new AnnotationConfigWebApplicationContext();
	this.wac.register(TestConfig.class);
	this.wac.refresh();

	this.server = new TomcatWebSocketTestServer();
	this.server.setup();
	this.server.deployConfig(this.wac);
	this.server.start();

	WebSocketClient webSocketClient = new StandardWebSocketClient();
	this.stompClient = new WebSocketStompClient(webSocketClient);
	this.stompClient.setMessageConverter(new StringMessageConverter());
}
 
Example 13
Source Project: rocketmq-spring   Source File: RocketMQMessageConverter.java    License: Apache License 2.0 6 votes vote down vote up
public RocketMQMessageConverter() {
    List<MessageConverter> messageConverters = new ArrayList<>();
    ByteArrayMessageConverter byteArrayMessageConverter = new ByteArrayMessageConverter();
    byteArrayMessageConverter.setContentTypeResolver(null);
    messageConverters.add(byteArrayMessageConverter);
    messageConverters.add(new StringMessageConverter());
    if (JACKSON_PRESENT) {
        messageConverters.add(new MappingJackson2MessageConverter());
    }
    if (FASTJSON_PRESENT) {
        try {
            messageConverters.add(
                (MessageConverter)ClassUtils.forName(
                    "com.alibaba.fastjson.support.spring.messaging.MappingFastJsonMessageConverter",
                    ClassUtils.getDefaultClassLoader()).newInstance());
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) {
            //ignore this exception
        }
    }
    messageConverter = new CompositeMessageConverter(messageConverters);
}
 
Example 14
/**
 * Create an instance of SimpAnnotationMethodMessageHandler with the given
 * message channels and broker messaging template.
 * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
 * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
 * @param brokerTemplate a messaging template to send application messages to the broker
 */
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
		MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {

	Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
	Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
	Assert.notNull(brokerTemplate, "brokerTemplate must not be null");

	this.clientInboundChannel = clientInboundChannel;
	this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
	this.brokerTemplate = brokerTemplate;

	Collection<MessageConverter> converters = new ArrayList<MessageConverter>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}
 
Example 15
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SubscriptionMethodReturnValueHandler(messagingTemplate);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SubscriptionMethodReturnValueHandler(jsonMessagingTemplate);

	Method method = this.getClass().getDeclaredMethod("getData");
	this.subscribeEventReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getDataAndSendTo");
	this.subscribeEventSendToReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handle");
	this.messageMappingReturnType = new MethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("getJsonView");
	this.subscribeEventJsonViewReturnType = new MethodParameter(method, -1);
}
 
Example 16
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	int port = SocketUtils.findAvailableTcpPort(61613);

	this.activeMQBroker = new BrokerService();
	this.activeMQBroker.addConnector("stomp://127.0.0.1:" + port);
	this.activeMQBroker.setStartAsync(false);
	this.activeMQBroker.setPersistent(false);
	this.activeMQBroker.setUseJmx(false);
	this.activeMQBroker.getSystemUsage().getMemoryUsage().setLimit(1024 * 1024 * 5);
	this.activeMQBroker.getSystemUsage().getTempUsage().setLimit(1024 * 1024 * 5);
	this.activeMQBroker.start();

	ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
	taskScheduler.afterPropertiesSet();

	this.client = new Reactor2TcpStompClient("127.0.0.1", port);
	this.client.setMessageConverter(new StringMessageConverter());
	this.client.setTaskScheduler(taskScheduler);
}
 
Example 17
@Test
public void configureMessageConvertersCustomAndDefault() {
	final MessageConverter testConverter = mock(MessageConverter.class);

	AbstractMessageBrokerConfiguration config = new BaseTestMessageBrokerConfig() {
		@Override
		protected boolean configureMessageConverters(List<MessageConverter> messageConverters) {
			messageConverters.add(testConverter);
			return true;
		}
	};
	CompositeMessageConverter compositeConverter = config.brokerMessageConverter();

	assertThat(compositeConverter.getConverters().size(), Matchers.is(4));
	Iterator<MessageConverter> iterator = compositeConverter.getConverters().iterator();
	assertThat(iterator.next(), Matchers.is(testConverter));
	assertThat(iterator.next(), Matchers.instanceOf(StringMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(ByteArrayMessageConverter.class));
	assertThat(iterator.next(), Matchers.instanceOf(MappingJackson2MessageConverter.class));
}
 
Example 18
@Before
public void setUp() throws Exception {

	logger.debug("Setting up before '" + this.testName.getMethodName() + "'");

	this.wac = new AnnotationConfigWebApplicationContext();
	this.wac.register(TestConfig.class);
	this.wac.refresh();

	this.server = new TomcatWebSocketTestServer();
	this.server.setup();
	this.server.deployConfig(this.wac);
	this.server.start();

	WebSocketClient webSocketClient = new StandardWebSocketClient();
	this.stompClient = new WebSocketStompClient(webSocketClient);
	this.stompClient.setMessageConverter(new StringMessageConverter());
}
 
Example 19
Source Project: spring-cloud-aws   Source File: QueueMessageHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers() {
	List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
			getCustomArgumentResolvers());

	resolvers.add(new HeaderMethodArgumentResolver(null, null));
	resolvers.add(new SqsHeadersMethodArgumentResolver());

	resolvers.add(new NotificationSubjectArgumentResolver());
	resolvers.add(new AcknowledgmentHandlerMethodArgumentResolver(ACKNOWLEDGMENT));
	resolvers.add(new VisibilityHandlerMethodArgumentResolver(VISIBILITY));

	CompositeMessageConverter compositeMessageConverter = createPayloadArgumentCompositeConverter();
	resolvers.add(new NotificationMessageArgumentResolver(compositeMessageConverter));
	resolvers.add(new MessageMethodArgumentResolver(
			this.messageConverters.isEmpty() ? new StringMessageConverter()
					: new CompositeMessageConverter(this.messageConverters)));
	resolvers.add(new PayloadArgumentResolver(compositeMessageConverter,
			new NoOpValidator()));

	return resolvers;
}
 
Example 20
protected void initMessageConverter(MessageConverter messageConverter) {

		StringMessageConverter stringMessageConverter = new StringMessageConverter();
		stringMessageConverter.setSerializedPayloadClass(String.class);

		List<MessageConverter> messageConverters = new ArrayList<>();
		messageConverters.add(stringMessageConverter);

		if (messageConverter != null) {
			messageConverters.add(messageConverter);
		}
		else {
			MappingJackson2MessageConverter mappingJackson2MessageConverter = new MappingJackson2MessageConverter();
			mappingJackson2MessageConverter.setSerializedPayloadClass(String.class);
			messageConverters.add(mappingJackson2MessageConverter);
		}

		setMessageConverter(new CompositeMessageConverter(messageConverters));
	}
 
Example 21
@Test
void fromMessage_withMessageAndSubject_shouldReturnMessage() throws Exception {
	// Arrange
	ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
	jsonObject.put("Type", "Notification");
	jsonObject.put("Subject", "Hello");
	jsonObject.put("Message", "World");
	String payload = jsonObject.toString();

	// Act
	Object notificationRequest = new NotificationRequestConverter(
			new StringMessageConverter()).fromMessage(
					MessageBuilder.withPayload(payload).build(), String.class);

	// Assert
	assertThat(NotificationRequestConverter.NotificationRequest.class
			.isInstance(notificationRequest)).isTrue();
	assertThat(
			((NotificationRequestConverter.NotificationRequest) notificationRequest)
					.getSubject()).isEqualTo("Hello");
	assertThat(
			((NotificationRequestConverter.NotificationRequest) notificationRequest)
					.getMessage()).isEqualTo("World");
}
 
Example 22
@Test
void fromMessage_withMessageOnly_shouldReturnMessage() throws Exception {
	// Arrange
	ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
	jsonObject.put("Type", "Notification");
	jsonObject.put("Message", "World");
	String payload = jsonObject.toString();

	// Act
	Object notificationRequest = new NotificationRequestConverter(
			new StringMessageConverter()).fromMessage(
					MessageBuilder.withPayload(payload).build(), String.class);

	// Assert
	assertThat(NotificationRequestConverter.NotificationRequest.class
			.isInstance(notificationRequest)).isTrue();
	assertThat(
			((NotificationRequestConverter.NotificationRequest) notificationRequest)
					.getMessage()).isEqualTo("World");
}
 
Example 23
@Test
void fromMessage_withNumberAttribute_shouldReturnMessage() throws Exception {
	// Arrange
	ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
	jsonObject.put("Type", "Notification");
	jsonObject.put("Message", "World");
	ObjectNode messageAttributes = JsonNodeFactory.instance.objectNode();
	messageAttributes.set("number-attribute", JsonNodeFactory.instance.objectNode()
			.put("Value", "30").put("Type", "Number.long"));
	jsonObject.set("MessageAttributes", messageAttributes);
	String payload = jsonObject.toString();

	// Act
	Object notificationRequest = new NotificationRequestConverter(
			new StringMessageConverter()).fromMessage(
					MessageBuilder.withPayload(payload).build(), String.class);

	// Assert
	assertThat(notificationRequest).isNotNull();
}
 
Example 24
@Test
void testWrongTypeSupplied() throws Exception {
	ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
	jsonObject.put("Type", "Subscription");
	jsonObject.put("Message", "Hello World!");

	String payload = jsonObject.toString();

	assertThatThrownBy(
			() -> new NotificationRequestConverter(new StringMessageConverter())
					.fromMessage(MessageBuilder.withPayload(payload).build(),
							String.class))
									.isInstanceOf(MessageConversionException.class)
									.hasMessageContaining(
											"is not a valid notification");
}
 
Example 25
@Test
void supportsParameter_withNotificationMessageMethodParameter_shouldReturnTrue()
		throws Exception {
	// Arrange
	NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
			new StringMessageConverter());
	Method methodWithNotificationMessageArgument = this.getClass()
			.getDeclaredMethod("methodWithNotificationMessageArgument", String.class);
	MethodParameter methodParameter = new MethodParameter(
			methodWithNotificationMessageArgument, 0);

	// Act
	boolean result = notificationMessageArgumentResolver
			.supportsParameter(methodParameter);

	// Assert
	assertThat(result).isTrue();
}
 
Example 26
@Test
void supportsParameter_withWrongMethodParameter_shouldReturnFalse() throws Exception {
	// Arrange
	NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
			new StringMessageConverter());
	Method methodWithMissingAnnotation = this.getClass()
			.getDeclaredMethod("methodWithMissingAnnotation", String.class);
	MethodParameter methodParameter = new MethodParameter(methodWithMissingAnnotation,
			0);

	// Act
	boolean result = notificationMessageArgumentResolver
			.supportsParameter(methodParameter);

	// Assert
	assertThat(result).isFalse();
}
 
Example 27
@Test
void supportsParameter_withNonStringParameterType_shouldReturnTrue()
		throws Exception {
	// Arrange
	NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
			new StringMessageConverter());
	Method methodWithWrongParameterType = this.getClass()
			.getDeclaredMethod("methodWithWrongParameterType", Long.class);
	MethodParameter methodParameter = new MethodParameter(
			methodWithWrongParameterType, 0);

	// Act
	boolean result = notificationMessageArgumentResolver
			.supportsParameter(methodParameter);

	// Assert
	assertThat(result).isTrue();
}
 
Example 28
@Test
void resolveArgument_withValidMessagePayload_shouldReturnNotificationMessage()
		throws Exception {
	// Arrange
	NotificationMessageArgumentResolver notificationMessageArgumentResolver = new NotificationMessageArgumentResolver(
			new StringMessageConverter());
	Method methodWithNotificationMessageArgument = this.getClass()
			.getDeclaredMethod("methodWithNotificationMessageArgument", String.class);
	MethodParameter methodParameter = new MethodParameter(
			methodWithNotificationMessageArgument, 0);

	ObjectNode jsonObject = JsonNodeFactory.instance.objectNode();
	jsonObject.put("Type", "Notification");
	jsonObject.put("Message", "Hello World!");
	String payload = jsonObject.toString();
	Message<String> message = MessageBuilder.withPayload(payload).build();

	// Act
	Object result = notificationMessageArgumentResolver
			.resolveArgument(methodParameter, message);

	// Assert
	assertThat(String.class.isInstance(result)).isTrue();
	assertThat(result).isEqualTo("Hello World!");
}
 
Example 29
Source Project: rqueue   Source File: RqueueMessageSenderImpl.java    License: Apache License 2.0 5 votes vote down vote up
private List<MessageConverter> getMessageConverters(
    boolean addDefault, List<MessageConverter> messageConverters) {
  List<MessageConverter> messageConverterList = new ArrayList<>();
  StringMessageConverter stringMessageConverter = new StringMessageConverter();
  stringMessageConverter.setSerializedPayloadClass(String.class);
  messageConverterList.add(stringMessageConverter);
  if (addDefault) {
    messageConverterList.add(new GenericMessageConverter());
  }
  messageConverterList.addAll(messageConverters);
  return messageConverterList;
}
 
Example 30
/**
 * Create an instance of SimpAnnotationMethodMessageHandler with the given
 * message channels and broker messaging template.
 * @param clientInboundChannel the channel for receiving messages from clients (e.g. WebSocket clients)
 * @param clientOutboundChannel the channel for messages to clients (e.g. WebSocket clients)
 * @param brokerTemplate a messaging template to send application messages to the broker
 */
public SimpAnnotationMethodMessageHandler(SubscribableChannel clientInboundChannel,
		MessageChannel clientOutboundChannel, SimpMessageSendingOperations brokerTemplate) {

	Assert.notNull(clientInboundChannel, "clientInboundChannel must not be null");
	Assert.notNull(clientOutboundChannel, "clientOutboundChannel must not be null");
	Assert.notNull(brokerTemplate, "brokerTemplate must not be null");

	this.clientInboundChannel = clientInboundChannel;
	this.clientMessagingTemplate = new SimpMessagingTemplate(clientOutboundChannel);
	this.brokerTemplate = brokerTemplate;

	Collection<MessageConverter> converters = new ArrayList<>();
	converters.add(new StringMessageConverter());
	converters.add(new ByteArrayMessageConverter());
	this.messageConverter = new CompositeMessageConverter(converters);
}