Skip to content

Commit

Permalink
JMS producer should support null values for property akka#2690
Browse files Browse the repository at this point in the history
  • Loading branch information
ihostage committed Sep 2, 2021
1 parent f9214c8 commit c20972b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ case class UnsupportedMessagePropertyType(propertyName: String, propertyValue: A
)
with NonRetriableJmsException

@deprecated("Not used anywhere", "3.0.4")
case class NullMessageProperty(propertyName: String, message: JmsEnvelope[_])
extends Exception(
s"null value was given for Jms property '$propertyName'."
Expand All @@ -34,6 +35,7 @@ case class UnsupportedMapMessageEntryType(entryName: String, entryValue: Any, me
)
with NonRetriableJmsException

@deprecated("Not used anywhere", "3.0.4")
case class NullMapMessageEntry(entryName: String, message: JmsMapMessagePassThrough[_])
extends Exception(
s"null value was given for Jms MapMessage entry '$entryName'."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private class JmsMessageProducer(jmsProducer: jms.MessageProducer, jmsSession: J
case v: Float => message.setFloatProperty(key, v)
case v: Long => message.setLongProperty(key, v)
case v: Double => message.setDoubleProperty(key, v)
case null => throw NullMessageProperty(key, jmsMessage)
case null => message.setObjectProperty(key, null)
case _ => throw UnsupportedMessagePropertyType(key, v, jmsMessage)
}
}
Expand All @@ -103,7 +103,7 @@ private class JmsMessageProducer(jmsProducer: jms.MessageProducer, jmsSession: J
case v: Long => message.setLong(key, v)
case v: Double => message.setDouble(key, v)
case v: Array[Byte] => message.setBytes(key, v)
case null => throw NullMapMessageEntry(key, jmsMessage)
case null => message.setObject(key, v)
case _ => throw UnsupportedMapMessageEntryType(key, v, jmsMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,10 @@ class JmsMessageProducerSpec extends JmsSpec with MockitoSugar {
}
}

"fail if a property is set to a null value" in new Setup {
"succeed if a property is set to a null value" in new Setup {
val jmsProducer = JmsMessageProducer(jmsSession, settings, 0)
assertThrows[NullMessageProperty] {
jmsProducer.populateMessageProperties(textMessage, JmsTextMessage("test").withProperty("object", null))
}
jmsProducer.populateMessageProperties(textMessage, JmsTextMessage("test").withProperty("object", null))
verify(textMessage).setObjectProperty("object", null)
}
}

Expand Down Expand Up @@ -143,12 +142,11 @@ class JmsMessageProducerSpec extends JmsSpec with MockitoSugar {
}
}

"fail if a map value is set to null" in new Setup {
"succeed if a map value is set to null" in new Setup {
val jmsProducer = JmsMessageProducer(jmsSession, settings, 0)
assertThrows[NullMapMessageEntry] {
val wrongMap: Map[String, Any] = Map("object" -> null)
jmsProducer.createMessage(JmsMapMessage(wrongMap))
}
val correctMap: Map[String, Any] = Map("object" -> null)
jmsProducer.createMessage(JmsMapMessage(correctMap))
verify(mapMessage).setObject("object", null)
}
}
}

0 comments on commit c20972b

Please sign in to comment.