spray

Scala: Receiving Server-Sent-Events

时光总嘲笑我的痴心妄想 提交于 2019-12-03 12:42:46
Set-up: A project I am working on has a pub/sub server with an HTTP interface. Subscription works by accepting server-sent-events. curl -X GET server:port/topics/news which will be pushed whenever a message is published to the given topic URL curl -X PUT server:port/topics/news -d "Politician Lies!" Problem: I have a scala project which needs to subscribe to this pub/sub server. The Play! framework is able to handle this by using PlayWS with Enumeratee + Iteratee. Unfortunately, the PlayWS library requires that a Play! Application is in scope and I am not using Play. Is there a library (with

spray-json and list marshalling

不打扰是莪最后的温柔 提交于 2019-12-03 12:17:05
I'm using spray-json to marshal lists of custom objects into JSON. I have the following case class and its JsonProtocol. case class ElementResponse(name: String, symbol: String, code: String, pkwiu: String, remarks: String, priceNetto: BigDecimal, priceBrutto: BigDecimal, vat: Int, minInStock:Int, maxInStock: Int) object JollyJsonProtocol extends DefaultJsonProtocol with SprayJsonSupport { implicit val elementFormat = jsonFormat10(ElementResponse) } When I try to put in in a route like this one: get { complete { List(new ElementResponse(...), new ElementResponse(...)) } } I get an error saying

How to fix the Dropping Close since the SSL connection is already closing error in spray

Deadly 提交于 2019-12-03 10:26:37
I’m making a call to an API, but most of the time I keep getting an error: “ Dropping Close since the SSL connection is already closing ” and “ Premature connection close (the server doesn't appear to support request pipelining) .” Like 90% of the time I get that error, meaning: on very rare occasions the query does return the data it supposed to. To make sure this wasn’t the API’s server issue, I replicate the same query using Node.js (Express and Request libs) and it works every time. It makes me almost sure is a spray bug . Here's an example of the code : case class MyClass(user: String,

Configuration issue for Spray https server with self-signed certificate?

帅比萌擦擦* 提交于 2019-12-03 07:48:55
I am using Spray 1.3, Akka 2.3, and Scala 2.11 on Mac 10.9.4 to set up an HTTP server. I am following the Ch. 2 example in Manning's Akka in Action (sample code available here: https://github.com/RayRoestenburg/akka-in-action.git ), which compiles, runs, and behaves as expected when I use http, but I am having trouble configuring it for use with https. To run with https, I have generated a self-signed certificate as follows: keytool -genkey -keyalg RSA -alias selfsigned -keystore myjks.jks -storepass abcdef -validity 360 -keysize 2048 Following this example, https://github.com/spray/spray/tree

Spray, Akka-http and Play, Which is the best bet for a new HTTP/REST project

半腔热情 提交于 2019-12-03 05:31:58
问题 I'm going to develop new HTTP/REST services using Scala and Akka Actors. I have experience working with Play, but I don't really need a complete web Framework. From what I read, I think Spray is a suitable choice. My question come from the future of Spray after the new arrived AKKA-HTTP. Does the Spray project will grow independently from the Akka-HTTP project, or are the two project going to be merged into one Akka-HTTTP? What is the impact of this if I start developing with Spray? Also I

How can I parse out get request parameters in spray-routing?

空扰寡人 提交于 2019-12-03 05:30:23
This is what the section of code looks like get{ respondWithMediaType(MediaTypes.`application/json`){ entity(as[HttpRequest]){ obj => complete{ println(obj) "ok" } } } }~ I can map the request to a spray.http.HttpRequest object and I can extract the uri from this object but I imagine there is an easier way to parse out the parameters in a get request than doing it manually. For example if my get request is http://localhost:8080/url?id=23434&age=24 I want to be able to get id and age out of this request 4lex1v Actually you can do this much much better. In routing there are two directives:

Scala parameters pattern (Spray routing example)

给你一囗甜甜゛ 提交于 2019-12-03 00:29:23
Sorry about the vague title...wasn't sure how to characterize this. I've seen/used a certain code construction in Scala for some time but I don't know how it works. It looks like this (example from Spray routing): path( "foo" / Segment / Segment ) { (a,b) => { // <-- What's this style with a,b? ... }} In this example, the Segements in the path are bound to a and b respectively inside the associated block. I know how to use this pattern but how does it work? Why didn't it bind something to "foo"? I'm not so interested in how spray works for my purpose here, but what facility of Scala is this,

how to use scala spray detach?

你。 提交于 2019-12-02 18:08:01
问题 i'm trying to use spray detach as following: path("") { get { detach { respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here complete { <html> <body> <h1>Say hello to <i>spray-routing</i> on <i>Jetty</i>!</h1> </body> </html> } } } } } but i get following compilation error: type mismatch; found : spray.routing.RequestContext => Unit required: spray.routing.directives.DetachMagnet respondWithMediaType( text/html ) { // XML is marshalled

how to use scala spray detach?

拥有回忆 提交于 2019-12-02 08:30:36
i'm trying to use spray detach as following: path("") { get { detach { respondWithMediaType(`text/html`) { // XML is marshalled to `text/xml` by default, so we simply override here complete { <html> <body> <h1>Say hello to <i>spray-routing</i> on <i>Jetty</i>!</h1> </body> </html> } } } } } but i get following compilation error: type mismatch; found : spray.routing.RequestContext => Unit required: spray.routing.directives.DetachMagnet respondWithMediaType( text/html ) { // XML is marshalled to text/xml by default, so we simply override here ^ I looked at: https://github.com/spray/spray/wiki

Basic Spray-Testkit usage to test a route does not work

青春壹個敷衍的年華 提交于 2019-12-02 07:51:39
问题 I am trying to use spray route and want to test it with Spray-TestKit. I am using : - Scala 2.10.3 - Akka 2.3.3 - Spray 1.3.1 I create a trait extending HttpService, where I define a route : trait MyService extends HttpService with CoreAccess { import greentee.am.endpoint.tsmsp.tsmSPJsonSupport._ val myRoute = { path("resources"/"ping") { get { complete(OK, "pong") } } } } I deleted part of the route which was not relevant. CoreAccess is a trait extending Actor, because I have methods in that