本文整理汇总了Java中org.springframework.jms.support.converter.MessageConverter类的典型用法代码示例。如果您正苦于以下问题:Java MessageConverter类的具体用法?Java MessageConverter怎么用?Java MessageConverter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageConverter类属于org.springframework.jms.support.converter包,在下文中一共展示了MessageConverter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getConverterByConverterName
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
protected MessageConverter getConverterByConverterName(String converterName) {
try {
Class<?> converterClass = ClassUtils.forName(converterName, this.beanClassLoader);
for (JmsMessageConverter converter : messageConverters) {
if (ClassUtils.isAssignableValue(converterClass, converter)) {
return converter;
}
}
} catch (Throwable ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.warn("NOT FOUND the converter named {}", converterName);
}
LOGGER.warn("NOT FOUND the converter named {}", converterName, ex);
}
return defaultMessageConverter;
}
示例2: buildMessage
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
/**
* Build a JMS message to be sent as response based on the given result object.
* @param session the JMS Session to operate on
* @param result the content of the message, as returned from the listener method
* @return the JMS {@code Message} (never {@code null})
* @throws JMSException if thrown by JMS API methods
* @see #setMessageConverter
*/
protected Message buildMessage(Session session, Object result) throws JMSException {
Object content = (result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);
if (content instanceof org.springframework.messaging.Message) {
return this.messagingMessageConverter.toMessage(content, session);
}
MessageConverter converter = getMessageConverter();
if (converter != null) {
return converter.toMessage(content, session);
}
if (!(content instanceof Message)) {
throw new MessageConversionException(
"No MessageConverter specified - cannot handle message [" + content + "]");
}
return (Message) content;
}
示例3: syncRetrieve
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public T syncRetrieve() throws Exception
{
if (logger.isDebugEnabled())
{
Message msg = this.getTemplateConsumer().receive();
logger.debug("***** SYNC CONSUMING MESSAGE******");
traceMessage(msg);
MessageConverter mc = ((IJMSServiceConsumer<?>) this).getTemplateConsumer()
.getMessageConverter();
return (T) mc.fromMessage(msg);
}
else
return (T) ((IJMSServiceConsumer<?>) this).getTemplateConsumer()
.receiveAndConvert();
}
示例4: jacksonJmsMessageConverter
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
示例5: jacksonJmsMessageConverter
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
示例6: toMessage
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
MessageConverter converter = getMessageConverterTo(object);
Message message = converter.toMessage(object, session);
setConverterOnMessage(message, converter);
return message;
}
示例7: getMessageConverterTo
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
private MessageConverter getMessageConverterTo(Object object) {
for (JmsMessageConverter converter : messageConverters) {
if (converter.canConvertTo(object)) {
return converter;
}
}
return defaultMessageConverter;
}
示例8: getMessageConverterFrom
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
private MessageConverter getMessageConverterFrom(Message message) throws JMSException {
String converterName = message.getStringProperty(CONVERTER_PROP);
if (StringUtils.isNotBlank(converterName)) {
return getConverterByConverterName(converterName);
}
for (JmsMessageConverter converter : messageConverters) {
if (converter.canConvertFrom(message)) {
return converter;
}
}
return defaultMessageConverter;
}
示例9: jacksonJmsMessageConverter
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Bean // Serialize message content to json using TextMessage
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
示例10: extractMessage
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
/**
* Extract the message body from the given JMS message.
* @param message the JMS {@code Message}
* @return the content of the message, to be passed into the listener method
* as an argument
* @throws MessageConversionException if the message could not be extracted
*/
protected Object extractMessage(Message message) {
try {
MessageConverter converter = getMessageConverter();
if (converter != null) {
return converter.fromMessage(message);
}
return message;
}
catch (JMSException ex) {
throw new MessageConversionException("Could not convert JMS message", ex);
}
}
示例11: createMessageForPayload
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
protected Message createMessageForPayload(Object payload, Session session) throws JMSException {
MessageConverter converter = getMessageConverter();
if (converter != null) {
return converter.toMessage(payload, session);
}
throw new IllegalStateException("No message converter - cannot handle [" + payload + "]");
}
示例12: getMessageConverter
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
public MessageConverter getMessageConverter() {
JmsActivationSpecConfig config = getActivationSpecConfig();
if (config != null) {
return config.getMessageConverter();
}
return null;
}
示例13: createMessageListener
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Override
protected MessagingMessageListenerAdapter createMessageListener(MessageListenerContainer container) {
Assert.state(this.messageHandlerMethodFactory != null,
"Could not create message listener - MessageHandlerMethodFactory not set");
MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
InvocableHandlerMethod invocableHandlerMethod =
this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
messageListener.setHandlerMethod(invocableHandlerMethod);
String responseDestination = getDefaultResponseDestination();
if (StringUtils.hasText(responseDestination)) {
if (container.isReplyPubSubDomain()) {
messageListener.setDefaultResponseTopicName(responseDestination);
}
else {
messageListener.setDefaultResponseQueueName(responseDestination);
}
}
MessageConverter messageConverter = container.getMessageConverter();
if (messageConverter != null) {
messageListener.setMessageConverter(messageConverter);
}
DestinationResolver destinationResolver = container.getDestinationResolver();
if (destinationResolver != null) {
messageListener.setDestinationResolver(destinationResolver);
}
return messageListener;
}
示例14: getRequiredMessageConverter
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
private MessageConverter getRequiredMessageConverter() throws IllegalStateException {
MessageConverter converter = getMessageConverter();
if (converter == null) {
throw new IllegalStateException("No 'messageConverter' specified. Check configuration of JmsTemplate.");
}
return converter;
}
示例15: incomingMessageUsesMessageConverter
import org.springframework.jms.support.converter.MessageConverter; //导入依赖的package包/类
@Test
public void incomingMessageUsesMessageConverter() throws JMSException {
javax.jms.Message jmsMessage = mock(javax.jms.Message.class);
Session session = mock(Session.class);
MessageConverter messageConverter = mock(MessageConverter.class);
given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar");
MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class);
listener.setMessageConverter(messageConverter);
listener.onMessage(jmsMessage, session);
verify(messageConverter, times(1)).fromMessage(jmsMessage);
assertEquals(1, sample.simples.size());
assertEquals("FooBar", sample.simples.get(0).getPayload());
}