Search in sources :

Example 1 with MappingJackson2MessageConverter

use of org.springframework.jms.support.converter.MappingJackson2MessageConverter in project spring-integration by spring-projects.

the class DefaultJmsHeaderMapperTests method testJsonHeaderMapping.

@Test
public void testJsonHeaderMapping() throws JMSException {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("javatype");
    Session session = Mockito.mock(Session.class);
    Mockito.doAnswer(invocation -> new StubTextMessage(invocation.getArgument(0))).when(session).createTextMessage(Mockito.anyString());
    javax.jms.Message request = converter.toMessage(new Foo(), session);
    DefaultJmsHeaderMapper mapper = new DefaultJmsHeaderMapper();
    Map<String, Object> headers = mapper.toHeaders(request);
    javax.jms.Message reply = converter.toMessage("foo", session);
    mapper.fromHeaders(new MessageHeaders(headers), reply);
    Object result = converter.fromMessage(reply);
    assertThat(result, instanceOf(String.class));
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) MessageHeaders(org.springframework.messaging.MessageHeaders) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with MappingJackson2MessageConverter

use of org.springframework.jms.support.converter.MappingJackson2MessageConverter in project av-service by dvoraka.

the class JmsBridgeOutputConfig method outMessageConverter.

@Bean
public MessageConverter outMessageConverter() {
    MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
    messageConverter.setTypeIdPropertyName("typeId");
    return messageConverter;
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) Bean(org.springframework.context.annotation.Bean)

Example 3 with MappingJackson2MessageConverter

use of org.springframework.jms.support.converter.MappingJackson2MessageConverter in project av-service by dvoraka.

the class JmsServerConfig method fileServerMessageConverter.

@Bean
public MessageConverter fileServerMessageConverter() {
    MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
    messageConverter.setTypeIdPropertyName("typeId");
    return messageConverter;
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) Bean(org.springframework.context.annotation.Bean)

Example 4 with MappingJackson2MessageConverter

use of org.springframework.jms.support.converter.MappingJackson2MessageConverter in project spring-framework by spring-projects.

the class MessagingMessageListenerAdapterTests method testReplyWithJackson.

public TextMessage testReplyWithJackson(String methodName, String replyContent) throws JMSException {
    Queue replyDestination = mock(Queue.class);
    Session session = mock(Session.class);
    MessageProducer messageProducer = mock(MessageProducer.class);
    TextMessage responseMessage = mock(TextMessage.class);
    given(session.createTextMessage(replyContent)).willReturn(responseMessage);
    given(session.createProducer(replyDestination)).willReturn(messageProducer);
    MessagingMessageListenerAdapter listener = getPayloadInstance("Response", methodName, Message.class);
    MappingJackson2MessageConverter messageConverter = new MappingJackson2MessageConverter();
    messageConverter.setTargetType(MessageType.TEXT);
    listener.setMessageConverter(messageConverter);
    listener.setDefaultResponseDestination(replyDestination);
    listener.onMessage(mock(jakarta.jms.Message.class), session);
    verify(session, times(0)).createQueue(anyString());
    verify(session).createTextMessage(replyContent);
    verify(messageProducer).send(responseMessage);
    verify(messageProducer).close();
    return responseMessage;
}
Also used : MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) StubTextMessage(org.springframework.jms.StubTextMessage) Message(org.springframework.messaging.Message) TextMessage(jakarta.jms.TextMessage) MessageProducer(jakarta.jms.MessageProducer) Queue(jakarta.jms.Queue) StubTextMessage(org.springframework.jms.StubTextMessage) TextMessage(jakarta.jms.TextMessage) Session(jakarta.jms.Session)

Example 5 with MappingJackson2MessageConverter

use of org.springframework.jms.support.converter.MappingJackson2MessageConverter in project cas by apereo.

the class JmsTicketRegistryConfiguration method jacksonJmsMessageTicketRegistryConverter.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public MessageConverter jacksonJmsMessageTicketRegistryConverter() {
    val converter = new MappingJackson2MessageConverter();
    val mapper = JacksonObjectMapperFactory.builder().defaultTypingEnabled(true).defaultViewInclusion(false).writeDatesAsTimestamps(true).build().toObjectMapper();
    converter.setObjectMapper(mapper);
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("@class");
    return converter;
}
Also used : lombok.val(lombok.val) MappingJackson2MessageConverter(org.springframework.jms.support.converter.MappingJackson2MessageConverter) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

MappingJackson2MessageConverter (org.springframework.jms.support.converter.MappingJackson2MessageConverter)9 Bean (org.springframework.context.annotation.Bean)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MessageProducer (jakarta.jms.MessageProducer)1 Queue (jakarta.jms.Queue)1 Session (jakarta.jms.Session)1 TextMessage (jakarta.jms.TextMessage)1 Session (javax.jms.Session)1 lombok.val (lombok.val)1 StringBean (org.apereo.cas.StringBean)1 AbstractJacksonBackedStringSerializer (org.apereo.cas.util.serialization.AbstractJacksonBackedStringSerializer)1 Test (org.junit.Test)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 StubTextMessage (org.springframework.jms.StubTextMessage)1 Message (org.springframework.messaging.Message)1 MessageHeaders (org.springframework.messaging.MessageHeaders)1