在创建记录时,Lift Scala MongoDB 中的基本 REST 服务出现错误 500

发布于 2024-11-02 03:45:42 字数 8388 浏览 3 评论 0原文

REST 服务对象代码是:

object Account extends RestHelper {
  def createUser = {
    for {
      username <- S.param("username") ?~ "username parameter missing" ~> 400
      number <- S.param("number") ?~ "number parameter missing"
    } yield {
      val u = GeoFence.createRecord.name(username)
      u.save
      u.asJSON
    }
  }

  serve {
    case Req("api" :: "hello" :: Nil, "json", GetRequest) => JString("hi")
    case Req("api" :: "accounts" :: "new" :: Nil, "json", GetRequest) => createUser()
  }
}

这是每当我尝试运行 REST 服务时我在浏览器上看到的异常。

例外是指向第 27 行:

val u = GeoFence.createRecord.name(用户名)

你保存

HTTP ERROR 500

访问 /api/accounts/new.json 时出现问题。原因:

(class: net/liftweb/record/Record$class, method: toForm signature: (Lnet/liftweb/record/Record;Lscala/Function1;)Lscala/xml/NodeSeq;) Incompatible object argument for function call

引起:

java.lang.VerifyError: (类: net/liftweb/record/Record$class, 方法: toForm 签名: (Lnet/liftweb/record/Record;Lscala/Function1;)Lscala/xml/NodeSeq;)函数调用的对象参数不兼容 在 smartfamily.model.GeoFence。(GeoFence.scala:21) 在 smartfamily.model.GeoFence$。(GeoFence.scala:19) 在 smartfamily.model.GeoFence$.(GeoFence.scala) 在 smartfamily.api.Account$$anonfun$createUser$1$$anonfun$apply$1.apply(Account.scala:27​​) 在 smartfamily.api.Account$$anonfun$createUser$1$$anonfun$apply$1.apply(Account.scala:25) 在 net.liftweb.common.Full.map(Box.scala:478) 在 smartfamily.api.Account$$anonfun$createUser$1.apply(Account.scala:25) 在 smartfamily.api.Account$$anonfun$createUser$1.apply(Account.scala:24) 在 net.liftweb.common.Full.flatMap(Box.scala:480) 在 smartfamily.api.Account$.createUser(Account.scala:24) 在 smartfamily.api.Account$$anonfun$1.apply(Account.scala:35) 在 smartfamily.api.Account$$anonfun$1.apply(Account.scala:33) 在 net.liftweb.http.rest.RestHelper$class.apply(RestHelper.scala:472) 在 smartfamily.api.Account$.apply(Account.scala:21) 在 smartfamily.api.Account$.apply(Account.scala:21) 在 net.liftweb.util.NamedPF$$anonfun$applyBox$1.apply(NamedPartialFunction.scala:97) 在 net.liftweb.util.NamedPF$$anonfun$applyBox$1.apply(NamedPartialFunction.scala:97) 在 net.liftweb.common.Full.map(Box.scala:478) 在 net.liftweb.util.NamedPF$.applyBox(NamedPartialFunction.scala:97) 在 net.liftweb.http.LiftServlet.doService(LiftServlet.scala:220) 在 net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply$mcZ$sp(LiftServlet.scala:129) 在 net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:129) 在 net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:129) 在 net.liftweb.util.TimeHelpers$class.calcTime(TimeHelpers.scala:344) 在 net.liftweb.util.Helpers$.calcTime(Helpers.scala:34) 在 net.liftweb.util.TimeHelpers$class.logTime(TimeHelpers.scala:353) 在 net.liftweb.util.Helpers$.logTime(Helpers.scala:34) 在 net.liftweb.http.LiftServlet.doIt$1(LiftServlet.scala:128) 在 net.liftweb.http.LiftServlet.service(LiftServlet.scala:137) 在 net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply$mcV$sp(HTTPProvider.scala:69) 在net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply(HTTPProvider.scala:68) 在net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply(HTTPProvider.scala:68) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.URLRewriter$.doWith(Req.scala:1063) 在 net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply$mcV$sp(HTTPProvider.scala:67) 在 net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply(HTTPProvider.scala:67) 在 net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply(HTTPProvider.scala:67) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.provider.HTTPProvider$class.service(HTTPProvider.scala:63) 在 net.liftweb.http.LiftFilter.service(LiftServlet.scala:689) 在net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(ServletFilterProvider.scala:67) 在net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply(ServletFilterProvider.scala:62) 在net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply(ServletFilterProvider.scala:62) 在net.liftweb.http.CoreRequestVarHandler$$anonfun$申请$12$$anonfun$申请$13$$anonfun$申请$14$$anonfun$申请$15.apply(Vars.scala:513) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13$$anonfun$apply$14.apply(Vars.scala:512) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13.apply(Vars.scala:511) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12.apply(Vars.scala:510) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:509) 在 net.liftweb.http.RequestVarHandler$.apply(Vars.scala:428) 在 net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply$mcV$sp(ServletFilterProvider.scala:61) 在 net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:61) 在 net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:61) 在net.liftweb.http.CoreRequestVarHandler$$anonfun$申请$12$$anonfun$申请$13$$anonfun$申请$14$$anonfun$申请$15.apply(Vars.scala:513) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13$$anonfun$apply$14.apply(Vars.scala:512) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13.apply(Vars.scala:511) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12.apply(Vars.scala:510) 在 net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71) 在 net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:509) 在 net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:432) 在 net.liftweb.http.provider.servlet.ServletFilterProvider$class.doFilter(ServletFilterProvider.scala:60) 在 net.liftweb.http.LiftFilter.doFilter(LiftServlet.scala:689) 在 org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 在 org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388) 在 org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) 在 org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) 在 org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765) 在 org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440) 在 org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) 在 org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114) 在 org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) 在 org.mortbay.jetty.Server.handle(Server.java:326) 在 org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) 在 org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926) 在 org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549) 在 org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212) 在 org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) 在 org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) 在 org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

更新 1

那么,优秀的电梯社区在给定的链接上解决了这个问题。

http://groups.google.com/group/liftweb/browse_thread/thread/e70cc3763734fdd9

The REST service object code is:

object Account extends RestHelper {
  def createUser = {
    for {
      username <- S.param("username") ?~ "username parameter missing" ~> 400
      number <- S.param("number") ?~ "number parameter missing"
    } yield {
      val u = GeoFence.createRecord.name(username)
      u.save
      u.asJSON
    }
  }

  serve {
    case Req("api" :: "hello" :: Nil, "json", GetRequest) => JString("hi")
    case Req("api" :: "accounts" :: "new" :: Nil, "json", GetRequest) => createUser()
  }
}

This is the exception I see on browser whenever I'm trying to run the REST service.

The exception is pointing to line 27 which is:

val u = GeoFence.createRecord.name(username)

u.save

HTTP ERROR 500

Problem accessing /api/accounts/new.json. Reason:

(class: net/liftweb/record/Record$class, method: toForm signature: (Lnet/liftweb/record/Record;Lscala/Function1;)Lscala/xml/NodeSeq;) Incompatible object argument for function call

Caused by:

java.lang.VerifyError: (class: net/liftweb/record/Record$class, method: toForm signature: (Lnet/liftweb/record/Record;Lscala/Function1;)Lscala/xml/NodeSeq;) Incompatible object argument for function call
at smartfamily.model.GeoFence.(GeoFence.scala:21)
at smartfamily.model.GeoFence$.(GeoFence.scala:19)
at smartfamily.model.GeoFence$.(GeoFence.scala)
at smartfamily.api.Account$$anonfun$createUser$1$$anonfun$apply$1.apply(Account.scala:27)
at smartfamily.api.Account$$anonfun$createUser$1$$anonfun$apply$1.apply(Account.scala:25)
at net.liftweb.common.Full.map(Box.scala:478)
at smartfamily.api.Account$$anonfun$createUser$1.apply(Account.scala:25)
at smartfamily.api.Account$$anonfun$createUser$1.apply(Account.scala:24)
at net.liftweb.common.Full.flatMap(Box.scala:480)
at smartfamily.api.Account$.createUser(Account.scala:24)
at smartfamily.api.Account$$anonfun$1.apply(Account.scala:35)
at smartfamily.api.Account$$anonfun$1.apply(Account.scala:33)
at net.liftweb.http.rest.RestHelper$class.apply(RestHelper.scala:472)
at smartfamily.api.Account$.apply(Account.scala:21)
at smartfamily.api.Account$.apply(Account.scala:21)
at net.liftweb.util.NamedPF$$anonfun$applyBox$1.apply(NamedPartialFunction.scala:97)
at net.liftweb.util.NamedPF$$anonfun$applyBox$1.apply(NamedPartialFunction.scala:97)
at net.liftweb.common.Full.map(Box.scala:478)
at net.liftweb.util.NamedPF$.applyBox(NamedPartialFunction.scala:97)
at net.liftweb.http.LiftServlet.doService(LiftServlet.scala:220)
at net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply$mcZ$sp(LiftServlet.scala:129)
at net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:129)
at net.liftweb.http.LiftServlet$$anonfun$doIt$1$1.apply(LiftServlet.scala:129)
at net.liftweb.util.TimeHelpers$class.calcTime(TimeHelpers.scala:344)
at net.liftweb.util.Helpers$.calcTime(Helpers.scala:34)
at net.liftweb.util.TimeHelpers$class.logTime(TimeHelpers.scala:353)
at net.liftweb.util.Helpers$.logTime(Helpers.scala:34)
at net.liftweb.http.LiftServlet.doIt$1(LiftServlet.scala:128)
at net.liftweb.http.LiftServlet.service(LiftServlet.scala:137)
at net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply$mcV$sp(HTTPProvider.scala:69)
at net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply(HTTPProvider.scala:68)
at net.liftweb.http.provider.HTTPProvider$$anonfun$service$2$$anonfun$apply$mcV$sp$1.apply(HTTPProvider.scala:68)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.URLRewriter$.doWith(Req.scala:1063)
at net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply$mcV$sp(HTTPProvider.scala:67)
at net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply(HTTPProvider.scala:67)
at net.liftweb.http.provider.HTTPProvider$$anonfun$service$2.apply(HTTPProvider.scala:67)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.provider.HTTPProvider$class.service(HTTPProvider.scala:63)
at net.liftweb.http.LiftFilter.service(LiftServlet.scala:689)
at net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply$mcV$sp(ServletFilterProvider.scala:67)
at net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply(ServletFilterProvider.scala:62)
at net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1$$anonfun$apply$mcV$sp$1.apply(ServletFilterProvider.scala:62)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13$$anonfun$apply$14$$anonfun$apply$15.apply(Vars.scala:513)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13$$anonfun$apply$14.apply(Vars.scala:512)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13.apply(Vars.scala:511)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12.apply(Vars.scala:510)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:509)
at net.liftweb.http.RequestVarHandler$.apply(Vars.scala:428)
at net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply$mcV$sp(ServletFilterProvider.scala:61)
at net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:61)
at net.liftweb.http.provider.servlet.ServletFilterProvider$$anonfun$doFilter$1.apply(ServletFilterProvider.scala:61)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13$$anonfun$apply$14$$anonfun$apply$15.apply(Vars.scala:513)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13$$anonfun$apply$14.apply(Vars.scala:512)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12$$anonfun$apply$13.apply(Vars.scala:511)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$$anonfun$apply$12.apply(Vars.scala:510)
at net.liftweb.util.ThreadGlobal.doWith(ThreadGlobal.scala:71)
at net.liftweb.http.CoreRequestVarHandler$class.apply(Vars.scala:509)
at net.liftweb.http.TransientRequestVarHandler$.apply(Vars.scala:432)
at net.liftweb.http.provider.servlet.ServletFilterProvider$class.doFilter(ServletFilterProvider.scala:60)
at net.liftweb.http.LiftFilter.doFilter(LiftServlet.scala:689)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:440)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:926)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

UPDATE 1

Well it was resolved by the excellent lift community at the given link.

http://groups.google.com/group/liftweb/browse_thread/thread/e70cc3763734fdd9

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖竹 2024-11-09 03:45:42

异常中的第一行是:

smartfamily.model.GeoFence.<init>(GeoFence.scala:21)

这是您必须查找问题的地方。您对 net.liftweb.record.Record.toForm 的调用显然与您编译它的签名不匹配。我猜您正在使用错误版本的 lift 运行应用程序。要么是你的 lift jar 文件已损坏。

The first line in your exception is:

smartfamily.model.GeoFence.<init>(GeoFence.scala:21)

This is where you'll have to look for the problem. Your call to net.liftweb.record.Record.toForm apparently doesn't match the signature you compiled it against. I would guess that you're running your application with the wrong version of lift. Either that or your lift jar file is corrupt.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文