小编rot*_*erl的帖子

使用编译时DI时,Play 2.4.6中的功能测试

我正在使用Play 2.4.6编译时依赖注入和ScalaTest.控制器的构造函数有很少的参数,在ApplicationLoader中我创建它.这是代码:

class BootstrapLoader extends ApplicationLoader {
  def load(context: Context) = {
    new AppComponents(context).application
  }
}

class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with NingWSComponents {
  lazy val router = new Routes(httpErrorHandler, authenticationController, applicationController, assets)
  lazy val applicationController = new controllers.Application()
  lazy val authenticationController = new controllers.Authentication()(configuration, wsApi.client)
  lazy val assets = new controllers.Assets(httpErrorHandler)
}

class Authentication(implicit configuration: Configuration, val ws: WSClient) extends Controller {
  def login = Action { implicit request =>
    Unauthorized(s"${redirectUrl}")
  }
}

class AuthenticationSpec extends PlaySpec with OneAppPerSuite …
Run Code Online (Sandbox Code Playgroud)

scala scalatest playframework

9
推荐指数
1
解决办法
1045
查看次数

使用喷雾客户端进行多次请求时akka超时

使用喷雾1.3.2和akka 2.3.6.(akka仅用于喷雾).
我需要读取大文件,并为每一行发出一个http请求.
我用迭代器逐行读取文件,并为每个项目发出请求.它成功地运行了一些线路,但在某些时候它开始失败:
akka.pattern.AskTimeoutException: Ask timed out on [Actor[akka://default/user/IO-HTTP#-35162984]] after [60000 ms].
我首先想到我重载了服务,所以我将"spray.can.host-connector.max-connections"设置为1.它运行得慢得多,但我得到了同样的错误.

这里的代码:

import spray.http.MediaTypes._
val EdnType = register(
MediaType.custom(
  mainType = "application",
  subType = "edn",
  compressible = true,
  binary = false,
  fileExtensions = Seq("edn")))

val pipeline = (
  addHeader("Accept", "application/json")
  ~> sendReceive
  ~> unmarshal[PipelineResponse])

def postData(data: String) = {
  val request = Post(pipelineUrl).withEntity(HttpEntity.apply(EdnType, data))
  val responseFuture: Future[PipelineResponse] = pipeline(request)
  responseFuture
}

dataLines.map { d =>
  val f = postData(d)
  f.onFailure { case e => println("Error - …
Run Code Online (Sandbox Code Playgroud)

scala spray spray-client

6
推荐指数
1
解决办法
3339
查看次数

如何使用Play的json序列化/反序列化动态字段名称

我正在使用Play framework 2.2.2.我正在尝试像这样处理json请求

[
  {
    "id" : "123",
    "language" : "en",
    "text" : "This is an example of a text",
    "Metadata_IP" : "192.168.20.34",
    "Metadata_date" : "2001-07-04T12:08:56.235-0700"
  },
  {
    "id" : "124",
    "language" : "en",
    "text" : "Some more text here",
    "Metadata_IP" : "192.168.20.31",
    "Metadata_date" : "2001-07-04T12:09:56.235-0700",
    "Metadata_name" : "someone"
  }
]
Run Code Online (Sandbox Code Playgroud)

Metadata_字段是动态字段,意味着用户可以发送他想要的内容(例如,Metadata_color等...)处理此问题的最佳方法是什么?

我可以使用Readers将其反序列化为case class吗?我怎样才能做到这一点?我想动态字段将是Map [String,String],但是我应该如何让读者解析这个呢?

谢谢

scala playframework

3
推荐指数
1
解决办法
860
查看次数

标签 统计

scala ×3

playframework ×2

scalatest ×1

spray ×1

spray-client ×1