spray

Can I set a timeout and number of retries on a specific pipeline request?

为君一笑 提交于 2021-02-18 10:34:41
问题 When using spray's pipelining to make an HTTP request like this: val urlpipeline = sendReceive ~> unmarshal[String] urlpipeline { Get(url) } is there a way to specify a timeout for the request and the number of times it should retry for that specific request? All the documentation I've found only references doing in a config (and even then I can't seem to get it to work). thx 回答1: With the configuration file I use Spray 1.2.0 in an Akka system. Inside my actor, I import the existing Akka

Execution Context and Dispatcher - Best practices, useful configurations and Documentation

半腔热情 提交于 2021-01-20 14:29:10
问题 Scala Execution Context and Dispatchers - Listing and comparison: Why ? There are a lot of questions around what/how/what is the best Execution Context to use to execute futures on in Scala and how to configure the dispatcher. Still I never was able to find a longer list with pros and cons and configuration examples. The best I could find was in the Akka Documentation: http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html and Play Documentation https://www.playframework.com

Compile error when using a companion object of a case class as a type parameter

我是研究僧i 提交于 2020-08-24 08:42:06
问题 I'm create a number of json messages for spray in scala using case classes. For example: case class Foo(name: String, attrs: List[String]) implicit val fooFormat = jsonFormat2(Foo) object Foo { case class Invalid(error: String) } case class Bar(name: String, kv: Map[String, String]) implicit val barFormat = jsonFormat2(Bar) In the above snippet, barFormat compiles, but fooFormat does not: type mismatch; found : Foo.type required: (?, ?) => ? Note: implicit value barFormat is not applicable

How do directives work in Spray?

隐身守侯 提交于 2020-02-24 16:50:28
问题 I'd like to understand how directives in Spray work. As per the documentation: The general anatomy of a directive is as follows: name(arguments) { extractions => ... // inner Route } My basic understanding is that in the below snippet, 32 is passed as a parameter to method test . test { 32 } However, in the above directive name example, it is said arguments are passed into inner route, which is an anonymous function. Could someone please help me understand the syntax and the flow starting

How can I locate where an implicit comes from in Scala?

纵饮孤独 提交于 2020-01-13 00:07:01
问题 Short question: Is there a way to ask the scala compiler to tell me where a certain implicit used at a given point in a program was declared ? If not, is there an algorithm that I can follow manually to find out myself where an implicit was declared ? Long question: I am following simple spray crud tutorial. In the code snippet below (coming the this repo for the tutorial): pathEnd { post { entity(as[Question]) { question => completeWithLocationHeader( resourceId = questionService

Spray send xls file to client

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 07:00:33
问题 I'm developing a rest api with spray I need to download from my web-client an excel file with a report. The excel-generator method is ready but spray's "getFromFile(fileFullPath)" is getting "Internal server error" Any ideas? Here is my spray code: (ctx: RequestContext) => { val actor = actorRefFactory.actorOf(Props(new Actor { def receive = { case GetAnualReport(year, generateExcel) => val flujoActor = context.actorOf(Props[FlujoActor]) flujoActor ! GetAnualReport(year, generateExcel) case

Execute some logic asynchronously in spray routing

纵然是瞬间 提交于 2020-01-05 04:36:11
问题 Here is my simple routing application: object Main extends App with SimpleRoutingApp { implicit val system = ActorSystem("my-system") startServer(interface = "0.0.0.0", port = System.getenv("PORT").toInt) { import format.UsageJsonFormat._ import spray.httpx.SprayJsonSupport._ path("") { get { complete("OK") } } ~ path("meter" / JavaUUID) { meterUUID => pathEnd { post { entity(as[Usage]) { usage => // execute some logic asynchronously // do not wait for the result complete("OK") } } } } } }

Providing a JsonFormat for a Sequence of Objects

僤鯓⒐⒋嵵緔 提交于 2020-01-03 15:58:00
问题 i`m trying here to find some help to apply an JsonFormat extended of the DefaultJsonProtocol to an class containing a Sequence of Objects. So for the classes: class Person(val name: String, [......], val adresses: Seq[Adress]) class Adress(val streetname: String, val plz: BigDecimal, val city: String) now i would like to apply my JsonFormat: object PersonJsonProtocol extends DefaultJsonProtocol { implicit object PersonJsonFormat extends RootJsonFormat[Person] { def write(pers: Person) =

Providing a JsonFormat for a Sequence of Objects

余生颓废 提交于 2020-01-03 15:57:48
问题 i`m trying here to find some help to apply an JsonFormat extended of the DefaultJsonProtocol to an class containing a Sequence of Objects. So for the classes: class Person(val name: String, [......], val adresses: Seq[Adress]) class Adress(val streetname: String, val plz: BigDecimal, val city: String) now i would like to apply my JsonFormat: object PersonJsonProtocol extends DefaultJsonProtocol { implicit object PersonJsonFormat extends RootJsonFormat[Person] { def write(pers: Person) =

why do I get “The requested resource could not be found.” when accessing simple spray route?

女生的网名这么多〃 提交于 2020-01-03 13:33:44
问题 I tried a simple spray example app and i cannot access the route, I uploaded the example source code which does not work to github: spray-tomcat-example: git clone https://github.com/avidanyum/spray-tomcat-example mvn package cp cp target/spray-tomcat-example-0.1-SNAPSHOT.war ~/tmp/tomcat/apache-tomcat-7.0.61/webapps/spraytomcat.war cd ~/tmp/tomcat/apache-tomcat-7.0.61/bin ./catalina.sh jpda run http://localhost:8080/spraytomcat/ I get "The requested resource could not be found." I defined