org.springframework.messaging.converter.GenericMessageConverter Java Examples

The following examples show how to use org.springframework.messaging.converter.GenericMessageConverter. 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: DefaultMessageHandlerMethodFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.messageConverter == null) {
		this.messageConverter = new GenericMessageConverter(this.conversionService);
	}
	if (this.argumentResolvers.getResolvers().isEmpty()) {
		this.argumentResolvers.addResolvers(initArgumentResolvers());
	}
}
 
Example #2
Source File: MessageReceivingTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void receiveAndConvertFailed() {
	Message<?> expected = new GenericMessage<>("not a number test");
	this.template.setReceiveMessage(expected);
	this.template.setMessageConverter(new GenericMessageConverter());

	assertThatExceptionOfType(MessageConversionException.class).isThrownBy(() ->
			this.template.receiveAndConvert("somewhere", Integer.class))
		.withCauseInstanceOf(ConversionFailedException.class);
}
 
Example #3
Source File: MessageReceivingTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void receiveAndConvertNoConverter() {
	Message<?> expected = new GenericMessage<>("payload");
	this.template.setDefaultDestination("home");
	this.template.setReceiveMessage(expected);
	this.template.setMessageConverter(new GenericMessageConverter());
	try {
		this.template.receiveAndConvert(Writer.class);
	}
	catch (MessageConversionException ex) {
		assertTrue("Invalid exception message '" + ex.getMessage() + "'", ex.getMessage().contains("payload"));
		assertSame(expected, ex.getFailedMessage());
	}
}
 
Example #4
Source File: JmsMessagingTemplateTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void receiveAndConvertWithConversion() {
	javax.jms.Message jmsMessage = createJmsTextMessage("123");
	given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);

	this.messagingTemplate.setMessageConverter(new GenericMessageConverter());

	Integer payload = this.messagingTemplate.receiveAndConvert("myQueue", Integer.class);
	assertEquals(Integer.valueOf(123), payload);
	verify(this.jmsTemplate).receive("myQueue");
}
 
Example #5
Source File: DefaultMessageHandlerMethodFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.messageConverter == null) {
		this.messageConverter = new GenericMessageConverter(this.conversionService);
	}
	if (this.argumentResolvers.getResolvers().isEmpty()) {
		this.argumentResolvers.addResolvers(initArgumentResolvers());
	}
}
 
Example #6
Source File: MessageReceivingTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void receiveAndConvertFailed() {
	Message<?> expected = new GenericMessage<>("not a number test");
	this.template.setReceiveMessage(expected);
	this.template.setMessageConverter(new GenericMessageConverter());

	thrown.expect(MessageConversionException.class);
	thrown.expectCause(isA(ConversionFailedException.class));
	this.template.receiveAndConvert("somewhere", Integer.class);
}
 
Example #7
Source File: MessageReceivingTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void receiveAndConvertNoConverter() {
	Message<?> expected = new GenericMessage<>("payload");
	this.template.setDefaultDestination("home");
	this.template.setReceiveMessage(expected);
	this.template.setMessageConverter(new GenericMessageConverter());
	try {
		this.template.receiveAndConvert(Writer.class);
	}
	catch (MessageConversionException ex) {
		assertTrue("Invalid exception message '" + ex.getMessage() + "'", ex.getMessage().contains("payload"));
		assertSame(expected, ex.getFailedMessage());
	}
}
 
Example #8
Source File: JmsMessagingTemplateTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void receiveAndConvertWithConversion() {
	javax.jms.Message jmsMessage = createJmsTextMessage("123");
	given(this.jmsTemplate.receive("myQueue")).willReturn(jmsMessage);

	this.messagingTemplate.setMessageConverter(new GenericMessageConverter());

	Integer payload = this.messagingTemplate.receiveAndConvert("myQueue", Integer.class);
	assertEquals(Integer.valueOf(123), payload);
	verify(this.jmsTemplate).receive("myQueue");
}
 
Example #9
Source File: DefaultMessageHandlerMethodFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void afterPropertiesSet() {
	if (this.messageConverter == null) {
		this.messageConverter = new GenericMessageConverter(this.conversionService);
	}
	if (this.argumentResolvers.getResolvers().isEmpty()) {
		this.argumentResolvers.addResolvers(initArgumentResolvers());
	}
}
 
Example #10
Source File: MessageReceivingTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void receiveAndConvertFailed() {
	Message<?> expected = new GenericMessage<Object>("not a number test");
	this.template.setReceiveMessage(expected);
	this.template.setMessageConverter(new GenericMessageConverter());

	thrown.expect(MessageConversionException.class);
	thrown.expectCause(isA(ConversionFailedException.class));
	this.template.receiveAndConvert("somewhere", Integer.class);
}
 
Example #11
Source File: MessageReceivingTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void receiveAndConvertNoConverter() {
	Message<?> expected = new GenericMessage<Object>("payload");
	this.template.setDefaultDestination("home");
	this.template.setReceiveMessage(expected);
	this.template.setMessageConverter(new GenericMessageConverter());
	try {
		this.template.receiveAndConvert(Writer.class);
	}
	catch (MessageConversionException ex) {
		assertTrue("Invalid exception message '" + ex.getMessage() + "'", ex.getMessage().contains("payload"));
		assertSame(expected, ex.getFailedMessage());
	}
}
 
Example #12
Source File: JmsMessagingTemplateTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void receiveAndConvertWithConversion() {
	javax.jms.Message jmsMessage = createJmsTextMessage("123");
	given(jmsTemplate.receive("myQueue")).willReturn(jmsMessage);

	messagingTemplate.setMessageConverter(new GenericMessageConverter());

	Integer payload = messagingTemplate.receiveAndConvert("myQueue", Integer.class);
	assertEquals(Integer.valueOf(123), payload);
	verify(jmsTemplate).receive("myQueue");
}