ARTEMIS-4133 msg w/null prop value can't be consumed via STOMP

This commit is contained in:
Justin Bertram 2023-01-17 10:05:30 -06:00
parent e68034518d
commit 8a974fe89c
5 changed files with 40 additions and 7 deletions

View File

@ -16,6 +16,7 @@
*/
package org.apache.activemq.artemis.core.protocol.stomp;
import org.apache.activemq.artemis.api.core.ICoreMessage;
import org.apache.activemq.artemis.logs.annotation.LogBundle;
import org.apache.activemq.artemis.logs.annotation.LogMessage;
import org.apache.activemq.artemis.logs.BundleFactory;
@ -36,4 +37,7 @@ public interface ActiveMQStompProtocolLogger {
@LogMessage(id = 332070, value = "Unable to send frame {}", level = LogMessage.Level.ERROR)
void errorSendingFrame(StompFrame frame, Exception e);
@LogMessage(id = 332071, value = "Unable to send message to client: {}", level = LogMessage.Level.WARN)
void unableToSendMessageToClient(ICoreMessage message, Exception e);
}

View File

@ -198,8 +198,7 @@ public class StompSession implements SessionCallback {
return length;
} catch (Exception e) {
logger.debug("exception in sendMessage", e);
ActiveMQStompProtocolLogger.LOGGER.unableToSendMessageToClient(coreMessage, e);
return 0;
}
}

View File

@ -103,7 +103,7 @@ public class StompUtils {
public static void copyStandardHeadersFromMessageToFrame(Message message,
StompFrame command,
int deliveryCount) throws Exception {
int deliveryCount) {
command.addHeader(Stomp.Headers.Message.MESSAGE_ID, String.valueOf(message.getMessageID()));
SimpleString prefix = message.getSimpleStringProperty(Message.HDR_PREFIX);
command.addHeader(Stomp.Headers.Message.DESTINATION, (prefix == null ? "" : prefix) + message.getAddress());
@ -150,9 +150,12 @@ public class StompUtils {
continue;
}
command.addHeader(name.toString(), message.getObjectProperty(name).toString());
Object value = message.getObjectProperty(name);
if (value != null) {
command.addHeader(name.toString(), value.toString());
} else {
command.addHeader(name.toString(), "");
}
}
}
}

View File

@ -707,6 +707,23 @@ public class StompTest extends StompTestBase {
}
@Test
public void testNullPropertyValue() throws Exception {
conn.connect(defUser, defPass);
subscribe(conn, null, Stomp.Headers.Subscribe.AckModeValues.AUTO);
sendJmsMessage(getName(), "foo", null);
ClientStompFrame frame = conn.receiveFrame(2000);
Assert.assertEquals(Stomp.Responses.MESSAGE, frame.getCommand());
Assert.assertEquals(getQueuePrefix() + getQueueName(), frame.getHeader(Stomp.Headers.Send.DESTINATION));
Assert.assertEquals(getName(), frame.getBody());
Assert.assertEquals("", frame.getHeader("foo"));
conn.disconnect();
}
@Test
public void testTransactedSessionLeak() throws Exception {
for (int i = 0; i < 10; i++) {

View File

@ -62,7 +62,17 @@ public class StompFrameFactoryV10 implements StompFrameFactory {
@Override
public String[] handleHeaders(String header) {
return header.split(":");
String[] result = header.split(":");
// handle headers with empty value
if (result.length == 1) {
String[] tmp = new String[2];
tmp[0] = result[0];
tmp[1] = "";
result = tmp;
}
return result;
}
@Override