List of usage examples for org.springframework.jms.support.converter MessageConversionException MessageConversionException
public MessageConversionException(String msg)
From source file:com.oracle.demo.ops.event.spring.converter.ParcelLogEventMessageConverter.java
@Override public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { throw new MessageConversionException("Not Implemented"); }
From source file:org.fusesource.camel.util.BlobMessageConverter.java
@Override public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { if (session instanceof PooledSession) { session = ((PooledSession) session).getInternalSession(); }/*from w w w . j a v a 2 s . co m*/ if (session instanceof ActiveMQSession) { if (object instanceof InputStream) { return ((ActiveMQSession) session).createBlobMessage((InputStream) object); } else { throw new MessageConversionException("Object must be of type InputStream."); } } else { throw new MessageConversionException("Session must be of type ActiveMQSession."); } }
From source file:org.fusesource.camel.util.BlobMessageConverter.java
@Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { if (message instanceof BlobMessage) { try {//from ww w. j a v a 2 s.co m return ((BlobMessage) message).getInputStream(); } catch (IOException e) { JMSException jmsE = new JMSException("Unable to read blob message."); jmsE.setLinkedException(e); throw jmsE; } } else { throw new MessageConversionException("Message must be of type ActiveMQBlobMessage."); } }
From source file:org.dataminx.dts.ws.jms.DtsWsMessageConverter.java
/** * Extracts the given JMS Message payload and returns it as an object. * * @param message the incoming JMS message * @return the message payload as an {@link Object} * @throws JMSException if the incoming message is not of a supported * message type// ww w . j a va 2 s. co m */ private Object extractMessagePayload(final Message message) throws JMSException { final Object payload; if (message instanceof TextMessage) { final TextMessage textMessage = (TextMessage) message; payload = textMessage.getText(); } else if (message instanceof ObjectMessage) { final ObjectMessage objectMessage = (ObjectMessage) message; payload = objectMessage.getObject(); } else if (message instanceof BytesMessage) { final BytesMessage bytesMessage = (BytesMessage) message; final byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); final ByteArrayInputStream bis = new ByteArrayInputStream(bytes); payload = new StreamSource(bis); } else { throw new MessageConversionException("Invalid message type..."); } return payload; }
From source file:org.globus.crux.messaging.utils.JAXBMessageConverter.java
/** * <p>//from ww w. j a v a 2 s . co m * Unmarshal given <code>message</code> into an <code>object</code>. * </p> * * <p> * Should we raise an exception if the XML message encoding is not in sync with the underlying TextMessage encoding when the JMS * Provider supports MOM message's encoding ? * </p> * * @param message * message to unmarshal, MUST be an instance of {@link TextMessage} or of {@link BytesMessage}. * @see org.springframework.jms.support.converter.MessageConverter#fromMessage(javax.jms.Message) */ public Object fromMessage(Message message) throws JMSException, MessageConversionException { Source source; if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; source = new StreamSource(new StringReader(textMessage.getText())); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); source = new StreamSource(new ByteArrayInputStream(bytes)); } else { throw new MessageConversionException("Unsupported JMS Message type " + message.getClass() + ", expected instance of TextMessage or BytesMessage for " + message); } Object result; try { result = context.createUnmarshaller().unmarshal(source); } catch (JAXBException e) { throw new MessageConversionException("Error unmarshalling message", e); } return result; }
From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverter.java
/** * <p>//from w w w . ja v a 2 s.co m * Unmarshal given <code>message</code> into an <code>object</code>. * </p> * * <p> * Should we raise an exception if the XML message encoding is not in sync with the underlying TextMessage encoding when the JMS * Provider supports MOM message's encoding ? * </p> * * @param message * message to unmarshal, MUST be an instance of {@link TextMessage} or of {@link BytesMessage}. * @see org.springframework.jms.support.converter.MessageConverter#fromMessage(javax.jms.Message) * @see org.springframework.oxm.Unmarshaller#unmarshal(Source) */ public Object fromMessage(Message message) throws JMSException, MessageConversionException { Source source; if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; source = new StringSource(textMessage.getText()); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); source = new StreamSource(new ByteArrayInputStream(bytes)); } else { throw new MessageConversionException("Unsupported JMS Message type " + message.getClass() + ", expected instance of TextMessage or BytesMessage for " + message); } Object result = jaxb2Marshaller.unmarshal(source); return result; }
From source file:org.bremersee.common.jms.DefaultJmsConverter.java
@Override public Object fromMessage(Message message) throws JMSException { if (message == null) { return null; }/*from w w w . j av a 2s .c om*/ Class<?> payloadClass; try { payloadClass = Class.forName(message.getJMSType()); } catch (Throwable t) { // NOSONAR payloadClass = null; } Object payload; if (message instanceof TextMessage) { TextMessage msg = (TextMessage) message; payload = tryToGetPayload(msg, payloadClass); } else if (message instanceof BytesMessage) { BytesMessage msg = (BytesMessage) message; payload = tryToGetPayload(msg, payloadClass); } else { MessageConversionException e = new MessageConversionException( "Unsupported message type [" + message.getClass().getName() + "]."); log.error("Could not convert message:", e); throw e; } return payload; }
From source file:org.bremersee.common.jms.DefaultJmsConverter.java
private Object tryToGetPayload(TextMessage msg, Class<?> payloadClass) throws JMSException { String text = msg.getText();//from w w w .jav a 2s. c o m if (StringUtils.isBlank(text)) { return null; } String trimmedText = text.trim(); Object payload = null; if (payloadClass != null && trimmedText.startsWith("{") && trimmedText.endsWith("}")) { try { payload = objectMapper.readValue(trimmedText, payloadClass); } catch (Throwable t0) { // NOSONAR log.info("Reading JSON from message with JMSType [" + msg.getJMSType() + "] failed."); // NOSONAR } } if (payload == null) { try { payload = marshaller.unmarshal(new StreamSource(new StringReader(text))); } catch (Throwable t0) { // NOSONAR log.info("Reading XML from message with JMSType [" + msg.getJMSType() + "] failed."); } } if (payload == null) { MessageConversionException e = new MessageConversionException("Converting TextMessage failed."); log.error("Could not convert text:\n" + text + "\n", e); throw e; } return payload; }
From source file:org.bremersee.common.jms.DefaultJmsConverter.java
private Object tryToGetPayload(BytesMessage msg, Class<?> payloadClass) throws JMSException { int len;/*from ww w. j av a 2s . com*/ byte[] buf = new byte[1024]; ByteArrayOutputStream out = new ByteArrayOutputStream(); while ((len = msg.readBytes(buf)) != -1) { out.write(buf, 0, len); } byte[] payloadBytes = out.toByteArray(); if (payloadBytes == null || payloadBytes.length == 0) { return null; } Object payload = null; if (shouldTryJson(payloadClass, payloadBytes)) { try { payload = objectMapper.readValue(payloadBytes, payloadClass); } catch (Throwable t0) { // NOSONAR log.info("Reading JSON from message with JMSType [" + msg.getJMSType() + "] failed."); } } if (shouldTryUnmarshal(payload, payloadClass)) { try { payload = marshaller.unmarshal(new StreamSource(new ByteArrayInputStream(payloadBytes))); } catch (Throwable t0) { // NOSONAR log.info("Reading XML from message with JMSType [" + msg.getJMSType() + "] failed."); } } if (shouldTryDeserialize(payload, payloadClass)) { try { ObjectInputStream objectInputStream = new ObjectInputStream(new ByteArrayInputStream(payloadBytes)); payload = objectInputStream.readObject(); } catch (Throwable t0) { // NOSONAR log.info("Reading serialized object of JMSType [" + msg.getJMSType() + "] failed."); } } if (payload == null) { MessageConversionException e = new MessageConversionException("Converting BytesMessage failed."); log.error("Could not convert bytes:\n" + Base64.encodeBase64String(payloadBytes) + "\n", e); throw e; } return payload; }
From source file:org.bremersee.common.jms.DefaultJmsConverter.java
@Override public Message toMessage(Object object, Session session) throws JMSException { Message message = null;/*from w w w. j a va 2s .co m*/ if (object != null) { message = createJsonMessage(object, session); if (message == null && marshaller != null && marshaller.supports(object.getClass())) { message = createXmlMessage(object, session); } if (message == null && object instanceof Serializable) { message = createSerializedMessage((Serializable) object, session); } } if (message == null) { MessageConversionException e = new MessageConversionException("No message creator found."); log.error("Creating JMS from object of type [" + (object == null ? "null" : object.getClass().getName()) + "] failed.", e); throw e; } return message; }