Example usage for javax.jms BytesMessage propertyExists

List of usage examples for javax.jms BytesMessage propertyExists

Introduction

In this page you can find the example usage for javax.jms BytesMessage propertyExists.

Prototype


boolean propertyExists(String name) throws JMSException;

Source Link

Document

Indicates whether a property value exists.

Usage

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  w w.  j  av  a2  s .  c  om*/
 * @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);
    }
}