本文整理汇总了Java中javax.jms.BytesMessage.getStringProperty方法的典型用法代码示例。如果您正苦于以下问题:Java BytesMessage.getStringProperty方法的具体用法?Java BytesMessage.getStringProperty怎么用?Java BytesMessage.getStringProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.BytesMessage
的用法示例。
在下文中一共展示了BytesMessage.getStringProperty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertFromBytesMessage
import javax.jms.BytesMessage; //导入方法依赖的package包/类
/**
* Convert a BytesMessage to a Java Object with the specified type.
* @param message the input message
* @param targetJavaType the target type
* @return the message converted to an object
* @throws JMSException if thrown by JMS
* @throws IOException in case of I/O errors
*/
protected Object convertFromBytesMessage(BytesMessage message, JavaType targetJavaType)
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 {
String body = new String(bytes, encoding);
return this.objectMapper.readValue(body, targetJavaType);
}
catch (UnsupportedEncodingException ex) {
throw new MessageConversionException("Cannot convert bytes to String", ex);
}
}
示例2: getPayloadFromBytesMessage
import javax.jms.BytesMessage; //导入方法依赖的package包/类
/**
* Convert a BytesMessage to a Java Object with the specified type.
* @param message the input message
* @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);
}
}