List of usage examples for org.springframework.jms.support.converter MessageConversionException MessageConversionException
public MessageConversionException(String msg, @Nullable Throwable cause)
From source file:com.oracle.demo.ops.event.spring.converter.ParcelLogEventMessageConverter.java
@Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { //System.out.println("MessageConverter! "); try {//from w ww.java 2 s.co m return MyMarshaller.unmarshalEvent((TextMessage) message); } catch (JAXBException e) { throw new MessageConversionException("Error in MessageConverter: " + e.getMessage(), e); } }
From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterTibjmsImpl.java
/** * @throws MessageConversionException//w ww.j av a 2s. c om * if a problem occurs loading {@link com.tibco.tibjms.Tibjms#setMessageEncodingMethod} method. */ public JaxbMessageConverterTibjmsImpl() { super(); try { Class<?> tibJmsClass = Class.forName(TIBJMS_CLASS); this.setMessageEncodingMethod = tibJmsClass.getMethod(TIBJMS_SET_MESSAGE_ENCODING_METHOD, new Class[] { Message.class, String.class }); } catch (Exception e) { throw new MessageConversionException( NestedExceptionUtils.buildMessage("Exception loading Tibjms class", e), e); } }
From source file:org.nebulaframework.grid.cluster.manager.services.jobs.remote.RemoteJobRequestMessageConverter.java
/** * Returns the ClusterID of a given JobID. * <p>/*from www . j a v a 2s .c o m*/ * Note that JobID format specifies that * a job ID should be, * <pre> * <i>ClusterId</i>.<i>NodeId</i>.<i>RandomUUID</i> * </pre> * * @param jobId JobId * @return ClusterId * @throws MessageConversionException if JobId is invalid */ private String parseClusterId(String jobId) throws MessageConversionException { try { return jobId.split("\\.")[0]; } catch (Exception e) { throw new MessageConversionException("Exception while parsing ClusterId", e); } }
From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterTibjmsImpl.java
/** * Set given <code>message</code> encoding with Tibco proprietary APIs. * //from ww w.j a v a2 s . c om * @see com.tibco.tibjms.Tibjms#setMessageEncoding(javax.jms.Message, String) * @see fr.xebia.springframework.jms.support.converter.JaxbMessageConverter#postProcessResponseMessage(Message) */ @Override protected void postProcessResponseMessage(Message textMessage) throws JMSException { super.postProcessResponseMessage(textMessage); String encoding = this.marshallerProperties == null ? null : (String) this.marshallerProperties.get(Marshaller.JAXB_ENCODING); encoding = encoding == null ? "UTF-8" : encoding; try { this.setMessageEncodingMethod.invoke(null, new Object[] { textMessage, encoding }); } catch (Exception e) { MessageConversionException jmse = new MessageConversionException( NestedExceptionUtils.buildMessage("Exception setting message encoding", e), e); throw jmse; } }
From source file:org.globus.crux.messaging.utils.JAXBMessageConverter.java
/** * <p>/* ww w. ja v a 2 s . c o m*/ * Marshal the given <code>object</code> into a text message. * </p> * * <p> * This method ensures that the message encoding supported by the underlying JMS provider is in sync with the encoding used to generate * the XML message. * </p> * * @param object * @see org.springframework.jms.support.converter.MessageConverter#toMessage(java.lang.Object, javax.jms.Session) */ public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { StringWriter out = new StringWriter(); try { context.createMarshaller().marshal(object, new StreamResult(out)); } catch (JAXBException e) { throw new MessageConversionException("Error marshalling object to Text", e); } // create TextMessage result String text = out.toString(); TextMessage textMessage = session.createTextMessage(text); postProcessResponseMessage(textMessage); return textMessage; }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
@Override public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException { Message message;/*from w w w.ja v a 2 s . com*/ try { switch (this.targetType) { case TEXT: message = mapToTextMessage(object, session, this.objectMapper); break; case BYTES: message = mapToBytesMessage(object, session, this.objectMapper); break; default: message = mapToMessage(object, session, this.objectMapper, this.targetType); } } catch (IOException ex) { throw new MessageConversionException("Could not map JSON object [" + object + "]", ex); } setTypeIdOnMessage(object, message); return message; }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
@Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { try {/*from w ww . ja va2s. c om*/ JavaType targetJavaType = getJavaTypeForMessage(message); String payload = getPayload(message); if (null != targetJavaType) { return this.objectMapper.readValue(payload, targetJavaType); } return new GenericMessage(payload); } catch (IOException ex) { throw new MessageConversionException("Failed to convert JSON message content", ex); } }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
/** * Convert a BytesMessage to a Java Object with the specified type. * @param message the input message//from w ww .j a v a2s .c o m * @return the message body * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected String getPayloadFromBytesMessage(BytesMessage message) throws JMSException, IOException { String encoding = this.encoding; if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) { encoding = message.getStringProperty(this.encodingPropertyName); } byte[] bytes = new byte[(int) message.getBodyLength()]; message.readBytes(bytes); try { return new String(bytes, encoding); } catch (UnsupportedEncodingException ex) { throw new MessageConversionException("Cannot convert bytes to String", ex); } }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
protected JavaType getJavaTypeForMessage(Message message) throws JMSException { if (null == this.typeIdPropertyName || !message.propertyExists(this.typeIdPropertyName)) { return null; }//from ww w. j a va 2 s . c o m String typeId = message.getStringProperty(this.typeIdPropertyName); if (typeId == null) { LOGGER.debug("Could not find type id property [{}]", typeIdPropertyName); return null; } try { Class<?> typeClass = ClassUtils.forName(typeId, this.beanClassLoader); return this.objectMapper.getTypeFactory().constructType(typeClass); } catch (Throwable ex) { throw new MessageConversionException("Failed to resolve type id [" + typeId + "]", ex); } }
From source file:org.marketcetera.client.jms.JMSXMLMessageConverter.java
/** * Converts a JMS Message to a messaging object. * * @param message the received JMS message. It should be of type * {@link javax.jms.ObjectMessage}.//from w w w. jav a2 s . c om * * @return the messaging object converted from the supplied JMS message. * * @throws javax.jms.JMSException if there were errors extracting the contents * of the JMS message. * @throws org.springframework.jms.support.converter.MessageConversionException if there were errors converting * the contents of the JMS message to a messaging object. */ @Override public Object fromMessage(Message message) throws JMSException, MessageConversionException { SLF4JLoggerProxy.debug(this, "Converting from JMS {}", message); //$NON-NLS-1$ if (message instanceof TextMessage) { Object object = null; try { object = fromXML(((TextMessage) message).getText()); } catch (JAXBException e) { throw new MessageConversionException(new I18NBoundMessage1P( Messages.ERROR_CONVERTING_MESSAGE_TO_OBJECT, ObjectUtils.toString(object)).getText(), e); } if ((object instanceof ReportBaseImpl) || (object instanceof FIXResponseImpl) || (object instanceof OrderEnvelope) || (object instanceof BrokerStatus)) { 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()); } }