From c20972bfe98422fc9f7cc1c6ea20542b71720875 Mon Sep 17 00:00:00 2001 From: Sergey Morgunov Date: Thu, 2 Sep 2021 19:50:57 +0300 Subject: [PATCH] JMS producer should support null values for property #2690 --- .../akka/stream/alpakka/jms/JmsExceptions.scala | 2 ++ .../alpakka/jms/impl/JmsMessageProducer.scala | 4 ++-- .../jms/impl/JmsMessageProducerSpec.scala | 16 +++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/jms/src/main/scala/akka/stream/alpakka/jms/JmsExceptions.scala b/jms/src/main/scala/akka/stream/alpakka/jms/JmsExceptions.scala index 73bb4a3eaa..62444cfec7 100644 --- a/jms/src/main/scala/akka/stream/alpakka/jms/JmsExceptions.scala +++ b/jms/src/main/scala/akka/stream/alpakka/jms/JmsExceptions.scala @@ -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'." @@ -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'." diff --git a/jms/src/main/scala/akka/stream/alpakka/jms/impl/JmsMessageProducer.scala b/jms/src/main/scala/akka/stream/alpakka/jms/impl/JmsMessageProducer.scala index 76a3fe5810..3bfbbef00f 100644 --- a/jms/src/main/scala/akka/stream/alpakka/jms/impl/JmsMessageProducer.scala +++ b/jms/src/main/scala/akka/stream/alpakka/jms/impl/JmsMessageProducer.scala @@ -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) } } @@ -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) } } diff --git a/jms/src/test/scala/akka/stream/alpakka/jms/impl/JmsMessageProducerSpec.scala b/jms/src/test/scala/akka/stream/alpakka/jms/impl/JmsMessageProducerSpec.scala index 7eefd73280..d41c359d89 100644 --- a/jms/src/test/scala/akka/stream/alpakka/jms/impl/JmsMessageProducerSpec.scala +++ b/jms/src/test/scala/akka/stream/alpakka/jms/impl/JmsMessageProducerSpec.scala @@ -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) } } @@ -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) } } }