Skip to content

Commit

Permalink
Relax the Content-Type Parsing
Browse files Browse the repository at this point in the history
Stop using guava media type
  • Loading branch information
bmooney authored and mkiedys committed Feb 13, 2017
1 parent 91d1706 commit 331ea03
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/main/scala/io/scalac/amqp/Message.scala
@@ -1,6 +1,5 @@
package io.scalac.amqp

import com.google.common.net.MediaType
import io.scalac.amqp.Message.{PriorityMax, PriorityMin}
import java.time.ZonedDateTime

Expand All @@ -23,7 +22,7 @@ final case class Message(
* the content-type SHOULD NOT be set, allowing the recipient to determine the actual type.
* Where the section is known to be truly opaque binary data, the content-type SHOULD be set
* to application/octet-stream. */
contentType: Option[MediaType] = None,
contentType: Option[String] = None,

/** When present, describes additional content encodings applied to the application-data,
* and thus what decoding mechanisms need to be applied in order to obtain the media-type
Expand Down
5 changes: 2 additions & 3 deletions src/main/scala/io/scalac/amqp/impl/Conversions.scala
Expand Up @@ -6,7 +6,6 @@ import java.util.Date
import java.util.concurrent.TimeUnit

import com.google.common.collect.ImmutableMap
import com.google.common.net.MediaType
import com.rabbitmq.client.{AMQP, ConnectionFactory, Envelope}
import io.scalac.amqp._

Expand Down Expand Up @@ -61,7 +60,7 @@ private object Conversions {

Message(
body = body,
contentType = Option(properties.getContentType).map(MediaType.parse),
contentType = Option(properties.getContentType),
contentEncoding = Option(properties.getContentEncoding),
headers = Option(properties.getHeaders).map(_.asScala.toMap.mapValues(_.toString)).getOrElse(Map()),
mode = toDeliveryMode(properties.getDeliveryMode),
Expand Down Expand Up @@ -97,7 +96,7 @@ private object Conversions {
}

new AMQP.BasicProperties.Builder()
.contentType(message.contentType.map(_.toString).orNull)
.contentType(message.contentType.orNull)
.contentEncoding(message.contentEncoding.orNull)
.headers(message.headers.asJava.asInstanceOf[util.Map[String, AnyRef]])
.deliveryMode(toDeliveryMode(message.mode))
Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/io/scalac/amqp/impl/ConversionsSpec.scala
Expand Up @@ -2,6 +2,7 @@ package io.scalac.amqp.impl

import javax.net.ssl.SSLContext

import com.rabbitmq.client.AMQP.BasicProperties
import io.scalac.amqp.{Address, ConnectionSettings}
import org.scalatest.FlatSpec

Expand Down Expand Up @@ -30,4 +31,18 @@ class ConversionsSpec extends FlatSpec {

assert(connectionFactory.isSSL)
}


it should "handle valid content-type headers" in {
val props = new BasicProperties.Builder()
.contentType("application/json")
.build

val mediaType = Conversions
.toMessage(props, Array[Byte]())
.contentType
.get

assert(mediaType == "application/json")
}
}

0 comments on commit 331ea03

Please sign in to comment.