Repository: softwaremill/elasticmq (scala)

Issue:
when using queue name to send messages get Invalid request: MissingQueryParamRejection(QueueName),
While trying to send message to queue with ElasticMQ (embedded) I get this exception:

` Invalid request: MissingQueryParamRejection(QueueName)
`


this is how i send message to the queue: 
```
SendMessageRequest sendMsgRequest = new SendMessageRequest()
                    .withQueueUrl("dev-Test-Queue")
                    .withMessageBody(message);

```


create embedded queue:

```
   SQSRestServerBuilder
                .withPort(SQS_PORT)
                .withInterface("localhost")
                .start();
    }
```


init client:

```
 sqs = AmazonSQSClientBuilder.standard()
                .standard().withClientConfiguration(getClientConfiguration())
                .withCredentials(getCredentialsProvider())
                .withEndpointConfiguration(
                        new AwsClientBuilder.EndpointConfiguration("http://localhost:8887", region))
                .build();
```
        
//create new queue:

```
    public String createQueue(String address, Map<String, String> attributes) {
        CreateQueueRequest createQueueRequest = new CreateQueueRequest("dev-Test-Queue");
        sqs.createQueue(createQueueRequest);
    }

```


the only way it works is if I send messages this way:

```
this is how i send message to the queue: 
SendMessageRequest sendMsgRequest = new SendMessageRequest()
                    .withQueueUrl("http://localhost:8887/queue/dev-Test-Queue")
                    .withMessageBody(message);
```


I have to write the full path "**http://localhost:8887/queue/dev-Test-Queue**" 
while using real SQS api mentioning only the queue name (**dev-Test-Queue**) is enough.

any idea how to over come this?
thanks.

Pull request:

Patch:
diff --git a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/QueueDirectives.scala b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/QueueDirectives.scala
index ceed4d16d..85a830e20 100644
--- a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/QueueDirectives.scala
+++ b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/directives/QueueDirectives.scala
@@ -1,7 +1,7 @@
 package org.elasticmq.rest.sqs.directives
 
 import akka.actor.ActorRef
-import akka.http.scaladsl.server.{Directive1, Directives, MissingFormFieldRejection, Route}
+import akka.http.scaladsl.server.{Directive1, Directives, MissingQueryParamRejection, PathMatchers, Rejection, Route}
 import org.elasticmq.QueueData
 import org.elasticmq.actor.reply._
 import org.elasticmq.msg.{GetQueueData, LookupQueue}
@@ -45,13 +45,14 @@ trait QueueDirectives {
 
   private def queueNameFromRequest(p: AnyParams)(body: String => Route): Route = {
     val queueNameDirective =
+      checkOnlyOneSegmentInUri() |
       pathPrefix(accountId.r / Segment).tmap(_._2) |
         pathPrefix(QueueUrlContext / Segment) |
         queueNameFromParams(p) |
         queueUrlFromParams(p).flatMap { queueUrl =>
           lastPathSegment.findFirstMatchIn(queueUrl).map(_.group(2)) match {
             case Some(queueName) => provide(queueName)
-            case None            => reject(MissingFormFieldRejection(queueUrlParameter)): Directive1[String]
+            case None            => reject(MissingQueryParamRejection(queueUrlParameter)): Directive1[String]
           }
         }
 
@@ -76,4 +77,12 @@ trait QueueDirectives {
       body(queueData)
     }
   }
+
+  private def checkOnlyOneSegmentInUri(): Directive1[String] = {
+    path(Segment).flatMap { _ =>
+      reject(WrongURLFormatRejection("Provided only queueName instead of the full URL")): Directive1[String]
+    }
+  }
 }
+
+final case class WrongURLFormatRejection(fieldName: String) extends Rejection
diff --git a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/package.scala b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/package.scala
index f38747218..f17c5beea 100644
--- a/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/package.scala
+++ b/rest/rest-sqs/src/main/scala/org/elasticmq/rest/sqs/package.scala
@@ -1,6 +1,6 @@
 package org.elasticmq.rest
 
-import akka.http.scaladsl.server.{MissingQueryParamRejection, Directive1, Directive0}
+import akka.http.scaladsl.server.{Directive0, Directive1, MissingQueryParamRejection}
 import akka.http.scaladsl.server.Directives._
 
 package object sqs {
@@ -24,3 +24,4 @@ package object sqs {
     }
   }
 }
+


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 9b19a0a42..e4ecac1c7 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
@@ -13,7 +13,6 @@ import org.apache.http.client.methods.{HttpGet, HttpPost}
 import org.apache.http.message.BasicNameValuePair
 import org.elasticmq._
 import org.elasticmq.rest.sqs.model.RedrivePolicy
-import org.scalatest._
 import org.scalatest.matchers.should.Matchers
 
 import scala.collection.JavaConverters._
@@ -1948,6 +1947,13 @@ class AmazonJavaSdkTestSuite extends SqsClientServerCommunication with Matchers
     }
   }
 
+  test("should throws proper exception when referencing queue by name") {
+    val _ = client.createQueue(new CreateQueueRequest("testQueue1")).getQueueUrl
+
+    val ex = the[AmazonSQSException] thrownBy client.sendMessage(new SendMessageRequest("testQueue1", "Message 1"))
+    ex.getMessage should include("WrongURLFormatRejection(Provided only queueName instead of the full URL)")
+  }
+
   def queueDelay(queueUrl: String): Long = getQueueLongAttribute(queueUrl, delaySecondsAttribute)
 
   def getQueueLongAttribute(queueUrl: String, attributeName: String): Long = {