Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse Version query parameter for XML namespace #4

Merged
merged 1 commit into from
Mar 12, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ trait RequestHandlerLogicModule { this: ClientModule =>
class TheLogic extends RequestHandlerLogic {
def handle(request: HttpRequest, parameters: Map[String, String]) = {
val queueName = parameters(QueueNameParameter)
val version = parameters(VersionParameter)
val namespace = namespaceFor(version)
val queue = queueFor(queueName)
body(queue, request, parameters) % SqsNamespace
body(queue, request, parameters) % namespace
}
}

Expand All @@ -25,7 +27,9 @@ trait RequestHandlerLogicModule { this: ClientModule =>
class TheLogic extends RequestHandlerLogic {
def handle(request: HttpRequest, parameters: Map[String, String]) = {
val queueName = parameters(QueueNameParameter)
body(queueName, request, parameters) % SqsNamespace
val version = parameters(VersionParameter)
val namespace = namespaceFor(version)
body(queueName, request, parameters) % namespace
}
}

Expand All @@ -35,7 +39,9 @@ trait RequestHandlerLogicModule { this: ClientModule =>
def logic(body: (HttpRequest, Map[String, String]) => Elem): RequestHandlerLogic = {
class TheLogic extends RequestHandlerLogic {
def handle(request: HttpRequest, parameters: Map[String, String]) = {
body(request, parameters) % SqsNamespace
val version = parameters(VersionParameter)
val namespace = namespaceFor(version)
body(request, parameters) % namespace
}
}

Expand All @@ -44,6 +50,12 @@ trait RequestHandlerLogicModule { this: ClientModule =>

private implicit def elemToStringResponse(e: Elem): StringResponse = StringResponse(e.toString())

private def namespaceFor(version: String) = {
if (version == null || version.isEmpty) { version = SqsDefaultVersion }

new UnprefixedAttribute("xmlns", "http://queue.amazonaws.com/doc/%s/".format(version), Null)
}

private def queueFor(queueName: String) = {
val queueOption = client.lookupQueue(queueName)

Expand All @@ -65,4 +77,4 @@ trait RequestHandlerLogicModule { this: ClientModule =>

private def handleSQSException(e: SQSException) = StringResponse(e.toXml(EmptyRequestId).toString(), e.httpStatusCode)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Constants._
class SQSException(val code: String,
val message: String = "See the SQS docs.",
val httpStatusCode: Int = 400,
errorType: String = "Sender") extends Exception {
errorType: String = "Sender",
sqsVersion: String = SqsDefaultVersion) extends Exception {
def toXml(requestId: String) =
<ErrorResponse>
<Error>
Expand All @@ -15,7 +16,13 @@ class SQSException(val code: String,
<Detail/>
</Error>
<RequestId>{requestId}</RequestId>
</ErrorResponse> % SqsNamespace
</ErrorResponse> % namespaceFor(sqsVersion)

private def namespaceFor(version: String) = {
if (version == null || version.isEmpty) { version = SqsDefaultVersion }

new UnprefixedAttribute("xmlns", "http://queue.amazonaws.com/doc/%s/".format(version), Null)
}
}

object SQSException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ class SQSRestServerBuilder(client: Client,

object Constants {
val EmptyRequestId = "00000000-0000-0000-0000-000000000000"
val SqsNamespace = new UnprefixedAttribute("xmlns", "http://queue.amazonaws.com/doc/2009-02-01/", Null)
val SqsDefaultVersion = "2012-11-05"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why I still get response messages with xmlns=[...]/2009-02-01/?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which version are you using? Maybe your client sends this version as the desired one?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the latest binaries last week (May, 23) - 0.6.3.
Fiddled the request: &Version=2012-11-05
and the response is: <CreateQueueResponse xmlns="http://queue.amazonaws.com/doc/2009-02-01/">

Also browsing http://localhost:9324/?Action=ListQueues returns

<ListQueuesResponse xmlns="http://queue.amazonaws.com/doc/2009-02-01/">

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check that on 0.7.0 master, thx for reporting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a bug: #6

val QueueUrlPath = "queue"
val QueuePath = root / QueueUrlPath / %("QueueName")
val QueueNameParameter = "QueueName"
val ReceiptHandleParameter = "ReceiptHandle"
val VersionParameter = "Version"
val VisibilityTimeoutParameter = "VisibilityTimeout"
val DelayParameter = "DelaySeconds"
val IdSubParameter = "Id"
Expand Down