[英]How to find the name of a file received over JMS message (onmessage)
How do we find the name of the file received through JMS message, i need to know the name of the file, for example if the text file of name example.txt is received, i want to get the name "example" of the file through javax.jms.Message. 我们如何找到通过JMS消息接收到的文件的名称,我需要知道文件的名称,例如,是否收到名称为example.txt的文本文件,我想获取文件的名称为“ example”通过javax.jms.Message。
here's the code 这是代码
public void onMessage(Message message, Session session) throws JMSException {
String msg = null;
if (message instanceof TextMessage || message instanceof BytesMessage) {
if (message instanceof BytesMessage) {
BytesMessage byteMessage = (BytesMessage) message;
StringBuffer buffer = new StringBuffer((int)byteMessage.getBodyLength());
byteMessage.
for (int i = 0; i < (int)byteMessage.getBodyLength(); i++) {
buffer.append((char)byteMessage.readByte());
}
msg = buffer.toString().trim();
//for processing the message i need to know the name of the file.
//how to find the name of the file received, like "example" //if received file is "example.txt"
}
else {
getLogger().debug(this.getClass().getName() + ": Received TextMessage");
msg = ((TextMessage)message).getText();
}
getLogger().debug("Request received by " + this.getClass().getName() + " has been processed");
}
JMS has no idea what a file is. JMS不知道文件是什么。 Although, when sending the message, you can attach metadata to the message using string properties. 尽管在发送消息时,您可以使用字符串属性将元数据附加到消息。 It's common to place something like "originalFilename" as a property when the message is sent. 发送消息时,通常将诸如“ originalFilename”之类的属性放置为属性。
msg.setStringProperty("originalFilename",filename);
// .. set the bytes of the file somehow
msgProducer.send(msg);
then, in your receive code, you can just pick it up by 然后,在接收代码中,您可以通过
String filename = message.getStringProperty("originalFilename");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.