Example usage for org.springframework.jms.support.converter MessageConversionException MessageConversionException

List of usage examples for org.springframework.jms.support.converter MessageConversionException MessageConversionException

Introduction

In this page you can find the example usage for org.springframework.jms.support.converter MessageConversionException MessageConversionException.

Prototype

public MessageConversionException(String msg) 

Source Link

Document

Create a new MessageConversionException.

Usage

From source file:org.marketcetera.client.jms.JMSMessageConverter.java

/**
 * Converts a JMS Message to a trade message.
 *
 * @param message the received JMS message. It should be of type
 * {@link ObjectMessage}./*from   w  w  w.j a v a2  s.com*/
 *
 * @return the trade message converted from the supplied JMS message.
 *
 * @throws JMSException if there were errors extracting the contents
 * of the JMS message.
 * @throws MessageConversionException if there were errors converting
 * the contents of the JMS message to a trade message.
 */
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$
    if (message instanceof ObjectMessage) {
        Serializable object = ((ObjectMessage) message).getObject();
        if (object instanceof TradeMessage) {
            return object;
        } else {
            throw new MessageConversionException(
                    new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(object))
                            .getText());
        }
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message))
                        .getText());
    }
}

From source file:org.marketcetera.client.jms.JMSMessageConverter.java

/**
 * Converts a trade message to a JMS Message.
 *
 * @param inObject the message to be converted. It should either be
 * an order or a report.//from w  ww  .  java 2  s  . c  o  m
 * @param session the JMS Session instance.
 *
 * @return the JMS message.
 *
 * @throws JMSException if there were errors serializing the
 * trade message.
 * @throws MessageConversionException if the supplied object was not
 * an acceptable trade message.
 */
@Override
public Message toMessage(Object inObject, Session session) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting to JMS {}", inObject); //$NON-NLS-1$
    if (inObject instanceof TradeMessage) {
        return session.createObjectMessage((Serializable) inObject);
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject))
                        .getText());
    }
}

From source file:org.marketcetera.jms.JMSSerMessageConverter.java

/**
 * Converts a JMS Message to an object.//ww w.j  av  a2s.co  m
 *
 * @param message the received JMS message. It should be of type
 * {@link ObjectMessage}.
 *
 * @return the object converted from the supplied JMS message.
 *
 * @throws JMSException if there were errors extracting the contents
 * of the JMS message.
 * @throws MessageConversionException if there were errors converting
 * the contents of the JMS message to an object.
 */
@Override
public Object fromMessage(Message message) throws JMSException, MessageConversionException {
    SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$
    if (message instanceof ObjectMessage) {
        return ((ObjectMessage) message).getObject();
    } else {
        throw new MessageConversionException(
                new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_RECEIVED, ObjectUtils.toString(message))
                        .getText());
    }
}

From source file:org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener.java

/**
 * 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/*w  w  w. j  a va2s. co m*/
 */
protected Message buildMessage(Session session, Object result) throws JMSException {
    Object content = preProcessResponse(
            result instanceof JmsResponse ? ((JmsResponse<?>) result).getResponse() : result);

    MessageConverter converter = getMessageConverter();
    if (converter != null) {
        if (content instanceof org.springframework.messaging.Message) {
            return this.messagingMessageConverter.toMessage(content, session);
        } else {
            return converter.toMessage(content, session);
        }
    }

    if (!(content instanceof Message)) {
        throw new MessageConversionException(
                "No MessageConverter specified - cannot handle message [" + content + "]");
    }
    return (Message) content;
}

From source file:org.springframework.jms.listener.adapter.MessageListenerAdapter.java

/**
 * 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// w ww.  j a  v  a2  s  .co m
 */
protected Message buildMessage(Session session, Object result) throws JMSException {
    MessageConverter converter = getMessageConverter();
    if (converter != null) {
        return converter.toMessage(result, session);
    } else {
        if (!(result instanceof Message)) {
            throw new MessageConversionException(
                    "No MessageConverter specified - cannot handle message [" + result + "]");
        }
        return (Message) result;
    }
}