List of usage examples for org.springframework.jms.support.converter MessageConversionException MessageConversionException
public MessageConversionException(String msg, @Nullable Throwable cause)
From source file:org.marketcetera.client.jms.JMSXMLMessageConverter.java
/** * Converts a messaging object to a JMS Message. * * @param inObject the message to be converted. It should either be * an order or a report.//from w w w .java2 s . co m * @param session the JMS Session instance. * * @return the JMS message. * * @throws javax.jms.JMSException if there were errors serializing the * messaging object. * @throws org.springframework.jms.support.converter.MessageConversionException if the supplied object was not * an acceptable messaging object. */ @Override public Message toMessage(Object inObject, Session session) throws JMSException, MessageConversionException { SLF4JLoggerProxy.debug(this, "Converting to JMS {}", inObject); //$NON-NLS-1$ if ((inObject instanceof ReportBaseImpl) || (inObject instanceof FIXResponseImpl) || (inObject instanceof OrderEnvelope) || (inObject instanceof BrokerStatus)) { try { TextMessage message = session.createTextMessage(toXML(inObject)); //Set the type property for interoperability with .NET client. message.setStringProperty(JMS_TYPE_PROPERTY, inObject.getClass().getSimpleName()); return message; } catch (JAXBException e) { throw new MessageConversionException(new I18NBoundMessage1P( Messages.ERROR_CONVERTING_OBJECT_TO_MESSAGE, ObjectUtils.toString(inObject)).getText(), e); } } else { throw new MessageConversionException( new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject)) .getText()); } }
From source file:org.marketcetera.jms.JMSSerMessageConverter.java
/** * Converts an object to a JMS Message by serializing it. * * @param inObject the object to be converted. The object should be * serializable./*w ww. j a v a 2s. co m*/ * @param session the JMS Session instance. * * @return the JMS message. * * @throws JMSException if there were errors serializing the object. * @throws MessageConversionException if the supplied object was not * serializable or if there were errors serializing the object. */ @Override public Message toMessage(Object inObject, Session session) throws JMSException, MessageConversionException { SLF4JLoggerProxy.debug(this, "Converting to JMS {}", inObject); //$NON-NLS-1$ if (inObject instanceof Serializable) { try { return session.createObjectMessage((Serializable) inObject); } catch (RuntimeException e) { throw new MessageConversionException( new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject)) .getText(), e); } } else { throw new MessageConversionException( new I18NBoundMessage1P(Messages.UNEXPECTED_MESSAGE_TO_SEND, ObjectUtils.toString(inObject)) .getText()); } }
From source file:org.springframework.jms.listener.adapter.AbstractAdaptableMessageListener.java
/** * 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//from w w w.j a v a 2 s . co m * @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); } }
From source file:org.springframework.jms.support.converter.obm.MarshallingMessageConverter.java
@Override public javax.jms.Message toMessage(Object object, javax.jms.Session session) throws JMSException, MessageConversionException { try {/*from w w w .ja va 2 s .c o m*/ javax.jms.Message msg = marshalToBytesMessage(object, session, this.marshaller); if (log.isDebugEnabled()) { log.debug("converted " + object + " to a message."); } return msg; } catch (Exception ex) { throw new MessageConversionException("Could not marshal [" + object + "]", ex); } }
From source file:org.springframework.jms.support.converter.obm.MarshallingMessageConverter.java
public Object fromMessage(Message message) throws JMSException, MessageConversionException { try {/*from w ww . j a v a 2 s.c o m*/ Assert.isInstanceOf(BytesMessage.class, message); if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; return unmarshalFromBytesMessage(this.payloadClass, bytesMessage, this.unmarshaller); } } catch (IOException ex) { throw new MessageConversionException("Could not access message content: " + message, ex); } return null; }