Java Code Examples for org.springframework.messaging.simp.SimpMessagingTemplate#setMessageConverter()

The following examples show how to use org.springframework.messaging.simp.SimpMessagingTemplate#setMessageConverter() . 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
Source File: SubscriptionMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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
Source File: UserRegistryMessageHandlerTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	given(this.brokerChannel.send(any())).willReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
Example 3
Source File: SubscriptionMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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 4
Source File: UserRegistryMessageHandlerTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	when(this.brokerChannel.send(any())).thenReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
Example 5
Source File: SubscriptionMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: UserRegistryMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	MockitoAnnotations.initMocks(this);

	when(this.brokerChannel.send(any())).thenReturn(true);
	this.converter = new MappingJackson2MessageConverter();

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.brokerChannel);
	brokerTemplate.setMessageConverter(this.converter);

	this.localRegistry = mock(SimpUserRegistry.class);
	this.multiServerRegistry = new MultiServerUserRegistry(this.localRegistry);

	this.handler = new UserRegistryMessageHandler(this.multiServerRegistry, brokerTemplate,
			"/topic/simp-user-registry", this.taskScheduler);
}
 
Example 7
Source File: AbstractMessageBrokerConfiguration.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Bean
public SimpMessagingTemplate brokerMessagingTemplate() {
	SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel());
	String prefix = getBrokerRegistry().getUserDestinationPrefix();
	if (prefix != null) {
		template.setUserDestinationPrefix(prefix);
	}
	template.setMessageConverter(brokerMessageConverter());
	return template;
}
 
Example 8
Source File: SimpAnnotationMethodMessageHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setup() {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
	brokerTemplate.setMessageConverter(this.converter);

	this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, this.channel, this.channel);
	this.messageHandler.setApplicationContext(new StaticApplicationContext());
	this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
	this.messageHandler.afterPropertiesSet();

	this.testController = new TestController();
}
 
Example 9
Source File: SendToMethodReturnValueHandlerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
	this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
}
 
Example 10
Source File: AbstractMessageBrokerConfiguration.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public SimpMessagingTemplate brokerMessagingTemplate() {
	SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel());
	String prefix = getBrokerRegistry().getUserDestinationPrefix();
	if (prefix != null) {
		template.setUserDestinationPrefix(prefix);
	}
	template.setMessageConverter(brokerMessageConverter());
	return template;
}
 
Example 11
Source File: SimpAnnotationMethodMessageHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
	brokerTemplate.setMessageConverter(this.converter);

	this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, this.channel, this.channel);
	this.messageHandler.setApplicationContext(new StaticApplicationContext());
	this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
	this.messageHandler.afterPropertiesSet();

	this.testController = new TestController();
}
 
Example 12
Source File: SendToMethodReturnValueHandlerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
	this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);
}
 
Example 13
Source File: AbstractMessageBrokerConfiguration.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpMessagingTemplate brokerMessagingTemplate() {
	SimpMessagingTemplate template = new SimpMessagingTemplate(brokerChannel());
	String prefix = getBrokerRegistry().getUserDestinationPrefix();
	if (prefix != null) {
		template.setUserDestinationPrefix(prefix);
	}
	template.setMessageConverter(brokerMessageConverter());
	return template;
}
 
Example 14
Source File: SimpAnnotationMethodMessageHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate brokerTemplate = new SimpMessagingTemplate(this.channel);
	brokerTemplate.setMessageConverter(this.converter);

	this.messageHandler = new TestSimpAnnotationMethodMessageHandler(brokerTemplate, this.channel, this.channel);
	this.messageHandler.setApplicationContext(new StaticApplicationContext());
	this.messageHandler.setValidator(new StringTestValidator(TEST_INVALID_VALUE));
	this.messageHandler.afterPropertiesSet();

	this.testController = new TestController();
}
 
Example 15
Source File: SendToMethodReturnValueHandlerTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws Exception {
	MockitoAnnotations.initMocks(this);

	SimpMessagingTemplate messagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	messagingTemplate.setMessageConverter(new StringMessageConverter());
	this.handler = new SendToMethodReturnValueHandler(messagingTemplate, true);
	this.handlerAnnotationNotRequired = new SendToMethodReturnValueHandler(messagingTemplate, false);

	SimpMessagingTemplate jsonMessagingTemplate = new SimpMessagingTemplate(this.messageChannel);
	jsonMessagingTemplate.setMessageConverter(new MappingJackson2MessageConverter());
	this.jsonHandler = new SendToMethodReturnValueHandler(jsonMessagingTemplate, true);

	Method method = this.getClass().getDeclaredMethod("handleNoAnnotations");
	this.noAnnotationsReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToDefaultDestination");
	this.sendToDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendTo");
	this.sendToReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToWithPlaceholders");
	this.sendToWithPlaceholdersReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToUser");
	this.sendToUserReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToUserSingleSession");
	this.sendToUserSingleSessionReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToUserDefaultDestination");
	this.sendToUserDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToUserDefaultDestinationSingleSession");
	this.sendToUserSingleSessionDefaultDestReturnType = new SynthesizingMethodParameter(method, -1);

	method = this.getClass().getDeclaredMethod("handleAndSendToJsonView");
	this.jsonViewReturnType = new SynthesizingMethodParameter(method, -1);
}