本文整理匯總了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);
}
}