Repository: softwaremill/elasticmq
Pull request #449 (2021-01-19 13:06:19)

fix response mime type for rest server - should be xml


Patch:
diff --git a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/RespondDirectives.scala b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/RespondDirectives.scala
index 594e6c9a..21573825 100644
--- a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/RespondDirectives.scala
+++ b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/RespondDirectives.scala
@@ -1,10 +1,12 @@
 package org.elasticmq.rest.sqs.directives
 
-import akka.http.scaladsl.server.{Route, Directives, RequestContext}
-
-import scala.xml.{Null, UnprefixedAttribute, Elem}
+import akka.http.scaladsl.model.ContentTypes._
+import akka.http.scaladsl.model.HttpEntity
+import akka.http.scaladsl.server.{Directives, RequestContext, Route}
 import org.elasticmq.rest.sqs.Constants._
 
+import scala.xml.{Elem, Null, UnprefixedAttribute}
+
 trait RespondDirectives {
   this: Directives =>
 
@@ -12,7 +14,7 @@ trait RespondDirectives {
     namespace { ns => (ctx: RequestContext) =>
       {
         val result = elem % ns
-        ctx.complete(result.toString())
+        ctx.complete(HttpEntity(`text/xml(UTF-8)`, result.toString()))
       }
     }
 
@@ -20,7 +22,7 @@ trait RespondDirectives {
     namespace { ns => (ctx: RequestContext) =>
       {
         val result = elem % ns
-        ctx.complete((statusCode, result.toString()))
+        ctx.complete((statusCode, HttpEntity(`text/xml(UTF-8)`, result.toString())))
       }
     }
 


Test patch:
diff --git a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala
index 79410367..9b19a0a4 100644
--- a/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala
+++ b/rest/rest-sqs-testing-amazon-java-sdk/src/test/scala/org/elasticmq/rest/sqs/AmazonJavaSdkTestSuite.scala
@@ -3,14 +3,13 @@ package org.elasticmq.rest.sqs
 import java.net.URI
 import java.nio.ByteBuffer
 import java.util.UUID
-
 import akka.http.scaladsl.model.StatusCodes
 import com.amazonaws.AmazonServiceException
 import com.amazonaws.services.sqs.AmazonSQS
 import com.amazonaws.services.sqs.model._
 import org.apache.http.HttpHost
 import org.apache.http.client.entity.UrlEncodedFormEntity
-import org.apache.http.client.methods.HttpPost
+import org.apache.http.client.methods.{HttpGet, HttpPost}
 import org.apache.http.message.BasicNameValuePair
 import org.elasticmq._
 import org.elasticmq.rest.sqs.model.RedrivePolicy
@@ -210,6 +209,21 @@ class AmazonJavaSdkTestSuite extends SqsClientServerCommunication with Matchers
     )
   }
 
+  test("should respond with text/xml") {
+    // given
+    client.createQueue(new CreateQueueRequest("testQueue1"))
+
+    val httpHost = new HttpHost("localhost", 9321)
+    val req = new HttpGet("/queue/testQueue1?Action=ReceiveMessage")
+
+    //when
+    val res = httpClient.execute(httpHost, req)
+
+    //then
+    res.getStatusLine.getStatusCode shouldBe StatusCodes.OK.intValue
+    res.getEntity.getContentType.getValue should be("text/xml; charset=UTF-8")
+  }
+
   test("should reply with a MissingAction error when no action sent") {
     // given
     val httpHost = new HttpHost("localhost", 9321)