[英]Optimistic locking with hash function
The below code seems to complete without errors however lower down in the stack spray.can.server.HttpServerConnection wants 'If-Match' header to have a specific format. 下面的代码似乎完整无误,但是降低了堆栈中的Spray.can.server.HttpServerConnection希望'If-Match'标头具有特定格式。
I feel that I'm missing maybe a rejection handler? 我觉得我可能缺少拒绝处理程序? Or do I have to turn off something? 还是我必须关闭某些东西?
Any Ideas? 有任何想法吗?
api 22:29:56.251 | WARN | root-actor-system-akka.actor.default-dispatcher-4 | akka://root-actor-system/user/IO-HTTP/listener-0/2 | spray.can.server.HttpServerConnection | Illegal request header: Illegal 'If-Match' header: Invalid input 's', expected $timesIf$minusMatch (line 1, pos 1): somehashfunctionvalue
Route: 路线:
override def putObjectRoute = (path("api" / "models" / Segment / "objects") & authenticatedJsonRoute) {
(modeledSystemName, tenantName, authInfo) =>
put {
entity(as[ModeledObject]) { obje =>
etag(obje, hashfunction) {
onComplete(service.updateObject(modeledSystemName, tenantName, obje)) {
case Success(_) => complete(NoContent)
case Failure(ex) =>
log.error(ex.getMessage)
complete(InternalServerError, s"An error occurred: ${ex.getMessage}")
}
}
}
Directive: 指示:
trait OCCETag {
def etag[T](entity: T, f: (String, T) => Boolean): Directive0 = optionalHeaderValueByName("If-Match").flatMap {
case Some(etag) => mapInnerRoute { route =>
val e = entity
ctx => {
def complete304() = ctx.complete(HttpResponse(NotModified))
def complete412() = ctx.complete(PreconditionFailed)
if (f(etag, e)) pass else complete412()
}
}
case None => reject(MissingHeaderRejection("If-Match"))
}
}
I found the solution. 我找到了解决方案。 I changed pass to reader route(ctx). 我将通行证更改为读者路线(ctx)。 Basically the pass does not hand the context thorough to the directive. 基本上,传递不会将上下文彻底传递给指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.