标签: spray

在代码中无法看到旋转模板(喷涂应用程序)

我有一些配置问题,我看不到.我已按照最新twirlREADME中提供的说明进行操作,但html根据编译器未定义包.

  1. 我已将sbt-twirl插件包含在project/plugins.sbt文件中

    addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.3")
    
    Run Code Online (Sandbox Code Playgroud)
  2. project/Build.scala我启用了插件

     lazy val root  = Project(id = "proj", base = file("."))
       .enablePlugins(play.twirl.sbt.SbtTwirl)
       .settings(rootSettings: _*)
    
    Run Code Online (Sandbox Code Playgroud)
  3. 我已经放置page.scala.htmlsrc/main/twirl子目录(直接或使用com/somethin/cool路径)

现在,如果我试图导入html包(或com.somethin.cool.html),编译器会抱怨它未定义.我可以使用'twirlCompile'命令编译模板,它们在target子目录中正确生成,但它们对主项目是不可见的.

注意:这不是 PlayFramework项目

  • 斯卡拉:2.10.4
  • sbt:0.13.6
  • 旋转:1.0.3

scala sbt spray twirl

13
推荐指数
1
解决办法
2633
查看次数

使用spray/scala从post请求中获取表单参数

我对所有这些Scala/Spray都很新.通过一些测试,我可以使用参数函数从Get请求中获取参数.但是我正在尝试从请求正文的POST请求中获取一些参数.似乎参数函数无法获取这些值.

作为一个例子,我试图从post请求体中获取这个值"name = john&lastname = smith".获得这些价值的最佳选择是什么?

谢谢

post scala akka spray

12
推荐指数
2
解决办法
7060
查看次数

Scala测试模拟隐含参数?

当涉及隐式参数时,我在尝试理解如何在Scala中编写测试时遇到了一些困难.

我有以下(简短版本)我的代码和测试:

实施(Scala 2.10,Spray和Akka):

import spray.httpx.SprayJsonSupport._
import com.acme.ResultJsonFormat._

case class PerRequestIndexingActor(ctx: RequestContext) extends Actor with ActorLogging {
  def receive = LoggingReceive {
    case AddToIndexRequestCompleted(result) =>
      ctx.complete(result)
      context.stop(self)
  }
}


object ResultJsonFormat extends DefaultJsonProtocol {
  implicit val resultFormat = jsonFormat2(Result)
}

case class Result(code: Int, message: String)
Run Code Online (Sandbox Code Playgroud)

测试(使用ScalaTest和Mockito):

"Per Request Indexing Actor" should {
    "send the HTTP Response when AddToIndexRequestCompleted message is received" in {
      val request = mock[RequestContext]
      val result = mock[Result]

      val perRequestIndexingActor = TestActorRef(Props(new PerRequestIndexingActor(request)))
      perRequestIndexingActor ! AddToIndexRequestCompleted(result) …
Run Code Online (Sandbox Code Playgroud)

testing unit-testing scala scalatest spray

12
推荐指数
1
解决办法
3612
查看次数

spray-json错误:无法找到参数um的隐含值

我有这个案例课

case class Person(val name: String)

object JsonImplicits extends DefaultJsonProtocol {
  implicit val impPerson = jsonFormat1(Person)
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用spray-json来解析post请求:

  post {
    entity(as[Person]) { person =>
      complete(person)
    }
  }
Run Code Online (Sandbox Code Playgroud)

但是当我尝试编译时,我得到了:

src/main/scala/com/example/ServiceActor.scala:61:错误:找不到参数um的隐式值:spray.httpx.unmarshalling.FromRequestUnmarshaller [com.example.Person]

我不明白发生了什么,我怎么能解决这个问题呢?

谢谢

scala implicit-conversion akka spray

12
推荐指数
1
解决办法
8359
查看次数

执行上下文和调度程序 - 最佳实践,有用的配置和文档

Scala执行上下文和调度程序 - 列表和比较:为什么?

Execution Context关于在Scala中执行期货的最佳/如何/最佳用途以及如何配置调度程序,存在很多问题.我仍然无法找到更长的列表,其中包含优缺点和配置示例.

我能找到的最好的是Akka文档:http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html和Play Documentation https://www.playframework.com/documentation/2.5.x/ThreadPools.

我想问一下除了scala.concurrent.ExecutionContext.Implicits.global你在日常开发生活中使用的Akka默认配置,当你使用它们时有什么配置,以及它们的优点和缺点.

以下是我已经拥有的一些内容:

第一个未完成的概述

标准: scala.concurrent.ExecutionContext.Implicits.global

测试 - ExecutionContext.fromExecutor(new ForkJoinPool(1))

  • 用于测试
  • 没有并行性

播放默认的EC - play.api.libs.concurrent.Execution.Implicits._

Akka的默认执行上下文

舱壁

ExecutionContext.fromExecutor(new ForkJoinPool(n)) based on an separated dispatcher . Thanks to Sergiy Prydatchenko
Run Code Online (Sandbox Code Playgroud)

concurrency scala akka playframework spray

12
推荐指数
1
解决办法
1192
查看次数

如何为JSON公开REST服务?

我需要公开一个接受JSON有效负载的Spray服务.我在哪里可以找到能够展示这种功能的样本?

scala spray spray-json

11
推荐指数
1
解决办法
8602
查看次数

如何为akka http添加自定义marshaller?

作为scala和akka-http的初学者,我试图勾选序列化和编组过程.

该项目使用akka@2.5.2和akka-http@10.0.10".此外,它还包含akka-http-spray-json依赖项.

在代码库中,我们使用Java.Util.Currency(它可能已被弃用,这并不重要,因为我仍然想知道如何添加自定义编组器.)

鉴于此示例控制器:

def getCurrencyExample: Route = {
    path("currencyExample") {
      val currency: Currency = Currency.getInstance("EUR")
      val code: String = currency.getCurrencyCode

      val shouldBeFormated = collection.immutable.HashMap(
        "currencyCode" -> code,
        "currencyObject" -> currency
      )

      complete(shouldBeFormated)
    }
  }
Run Code Online (Sandbox Code Playgroud)

我得到这样的回复货币对象变空了:

 {
  currencyObject: { },
  currencyCode: "EUR",
 }
Run Code Online (Sandbox Code Playgroud)

我希望有类似的东西:

 {
  currencyObject: "EUR",
  currencyCode: "EUR",
 }
Run Code Online (Sandbox Code Playgroud)

currency对象应转换为JSON字符串.由于我不想手动转换每个响应,我想挂钩编组过程并在后台完成.

我想仅为Java.Util.Currency对象添加自定义marhaller ,但即使阅读文档,我也不确定如何继续.描述了多种方法,我不确定哪种方法符合我的需要,或者从哪里开始.


我尝试创建自己的CurrencyJsonProtocol:

package com.foo.api.marshallers

import java.util.Currency

import spray.json.{DefaultJsonProtocol, JsString, JsValue, RootJsonFormat}

object CurrencyJsonProtocol extends DefaultJsonProtocol { …
Run Code Online (Sandbox Code Playgroud)

json scala marshalling spray akka-http

11
推荐指数
1
解决办法
1222
查看次数

阿卡演员优先事项

我有一个基于actor的系统,它执行定期的,CPU密集的数据摄取以及RESTful端点.我正在使用Akka演员来发信号/控制摄取过程的各个阶段,而Spray(当然是建立在Akka上)来为我的休息端点提供服务.

我的问题是这样的:当摄取开始时它消耗了大部分CPU,使RESTful端点挨饿直到完成.

降低摄取优先级的最佳方法是什么?现在,摄取和Spray模块共享相同的ActorSystem,但如果这有助于解决方案,它们可以分开.

multithreading scala akka spray

10
推荐指数
1
解决办法
1875
查看次数

IDEA在尝试解析spray-template的build.sbt文件时抱怨Revolver.settings

on_spray-can_1.1按照Spray的" 入门 "页面上的建议克隆了Spray模板项目(分支),并使用sbt-idea生成相应的IDEA项目.它建立得很好,但是当我打开我的build.sbt文件时,最后一行让IDEA不高兴:

seq(Revolver.settings: _*)
Run Code Online (Sandbox Code Playgroud)

它不承认Revolver,并建议进口spray.revolver.RevolverPlugin.Revolver,这似乎是合理的.但是,当我这样做时,它仍然抱怨"表达式类型(Def.SettingsDefinition)必须符合SBT文件中的设置[_]".

显然,这不是一个真正的问题,或者IDEA的(外部)make会失败,和/或SBT会从命令行中抱怨.但为什么IDEA认为这是一个问题?最近版本的SBT有什么变化吗?

当我看到SBT 0.13.0源代码时,我注意到seq它已被弃用; 它说"在build.sbt文件中,可以删除此调用." 但是,如果我这样做,Revolver会停止工作("不是有效命令:重新启动").

FWIW,我在Scint 2.10.3上使用SBT 0.13.0,在Mint 14上使用IDEA 12.1.6.

intellij-idea sbt spray

10
推荐指数
1
解决办法
1803
查看次数

Spray.io:无法编译测试规范

我有以下服务:

trait PingService extends MyHttpService {

val pingRoutes =
    path("ping") {
      get {
        complete("message" -> "pong")
      }
    }
}
Run Code Online (Sandbox Code Playgroud)

MyHttpService是一个扩展的自定义类,HttpService只包含实用程序方法.

这是测试规范:

import akka.actor.ActorRefFactory
import org.json4s.{DefaultFormats, Formats}
import org.scalatest.{FreeSpec, Matchers}
import spray.testkit.ScalatestRouteTest

class PingServiceSpec extends FreeSpec with PingService with ScalatestRouteTest with Matchers {

override implicit def actorRefFactory: ActorRefFactory = system

override implicit def json4sFormats: Formats = DefaultFormats

  "Ping service" - {
    "when calling GET /ping" - {
      "should return 'pong'" in {
        Get("/ping") ~> pingRoutes ~> check { …
Run Code Online (Sandbox Code Playgroud)

testing scala akka spray

10
推荐指数
1
解决办法
1472
查看次数