java - Play Scala 从另一个方法调用 Controller 方法

标签 java scala playframework-2.0 playframework-2.3 ws-client

我一直在使用 Scala 的 Play 框架,但遇到了一些麻烦。

我正在尝试从 Controller 方法调用另一个 Controller 方法。首先,我尝试使用 WSRequest/Response 来调用其他 Controller 方法的路由,但是 WSResponse 不包含任何内容!没有 Cookie 或 header 即使 Controller 的方法会返回 WithCookies 重定向。

另外,我不确定如何直接调用 Controller 方法,因为它返回 EssentialAction,但第一个方法使用需要 Future[Result] 的隐式请求 ActionAsync 方法。我将如何使用 EssentiaLAction 创造 future [结果]!!?

关于如何解决我的问题有什么想法吗?谢谢!

最佳答案

基于Action composition

def a(s: String): Action[AnyContent] = Action.async {
  Future(Ok(s))
}

def b: Action[AnyContent] = Action.async {request =>
  a("from b")(request)
}

关于java - Play Scala 从另一个方法调用 Controller 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37284191/

相关文章:

java - 对 gremlin 服务器使用 gremlin 遍历 (Tinkergraph)

java - HQL:处理特殊字符

java - 在 Android 中将 double 转换为字符串

java - 你能提供 Java 中的 scala View 边界吗?

scala - 如何使用reduce或fold来避免可变状态

java - 在外部 jar 中查找文件而不是在我的类路径中

java - 无法在 heroku 上运行 Play 应用程序

scala - Play 2 : How to do execute piece of code before each test using specs2

java - Azure Key Vault 在本地工作但在 Azure 云中收到 403 禁止错误

html - 在 Play2 scala 模板中声明变量