spray

spray-json and list marshalling

爱⌒轻易说出口 提交于 2019-12-04 18:17:27
问题 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

Sending post with json using spray?

戏子无情 提交于 2019-12-04 13:04:29
Sorry I can't manage to make this work: I need to add some json to a post, so following the documentation: http://spray.io/documentation/1.1-M8/spray-httpx/request-building/ : import scala.util.{Success, Failure} import akka.actor.{Props, ActorSystem} import spray.can.client.DefaultHttpClient import spray.client.HttpConduit import spray.httpx.SprayJsonSupport import spray.http._ import spray.json.JsonParser._ import spray.json._ import HttpMethods._ import HttpHeaders._ import MediaTypes._ import spray.httpx.RequestBuilding._ import scala.concurrent.ExecutionContext.Implicits.global ... val

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

与世无争的帅哥 提交于 2019-12-04 11:57:34
问题 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

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

青春壹個敷衍的年華 提交于 2019-12-04 10:20:04
问题 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

How do I automatically add slash to end of a url in spray routing?

北战南征 提交于 2019-12-04 05:23:49
问题 It's common practice for web servers to automatically redirect users to a URL ending in a slash when that URL represents a "directory". For example, entering http://www.apache.org/licenses into a browser redirects to http://www.apache.org/licenses/ automatically. Due to the way spray's path-segment-based route matching works, I can't see an obvious way to create this behavior for a specific path segment. Any ideas? 来源: https://stackoverflow.com/questions/19556196/how-do-i-automatically-add

Sending a post request in spray

白昼怎懂夜的黑 提交于 2019-12-04 03:28:38
I need to make a simple HTTP request using spray framework. I found some examples on their web site but they turned out to be complicated and involving Akka which is not necessary for me. Besides, I need to be able to fill in a request's headers (like X-Application , content-type , etc) and, of course, a requests's post data (in my case, it would be a data in JSON). So how do I do that? Here is an example. There is going to be a small amount of akka code but as I mentioned in my comment, it's necessary for spray: import spray.httpx.RequestBuilding._ import spray.http._ import HttpMethods._

spray Marshaller for futures not in implicit scope after upgrading to spray 1.2

醉酒当歌 提交于 2019-12-04 02:57:05
After updating to spray 1.2 I got a problem regarding my JSON-Marshallers that worked perfectly with 1.1. Doing the following inside a HttpService trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging => case class Test(hallo: String, test: String) implicit val storyJsonFormat = jsonFormat2(Test.apply) def test(implicit m : Marshaller[Future[Test]]) = 17 def hallo = test } leads to the following error: could not find implicit value for parameter marshaller: spray.httpx.marshalling.Marshaller[scala.concurrent.Future[amanuensis.story.Story]

Akka Actor Priorities

ぃ、小莉子 提交于 2019-12-04 02:31:12
I have an actor-based system that performs periodic, cpu-intensive data ingests as well as serves RESTful endpoints. I'm using Akka actors to signal/control the various stages of the ingest process, and Spray (which is of course built on Akka) to serve my restful endpoints. My problem is this: When the ingest kicks off it consumes most of the CPU, starving the RESTful endpoints until its done. What's the best way to lower the priority of the ingest? Right now the ingest and the Spray module share the same ActorSystem, but they could be separated if that helps the solution. It seems the

spray-json error: could not find implicit value for parameter um

僤鯓⒐⒋嵵緔 提交于 2019-12-04 00:55:52
I have this case class case class Person(val name: String) object JsonImplicits extends DefaultJsonProtocol { implicit val impPerson = jsonFormat1(Person) } I'm trying spray-json in order to parse post request: post { entity(as[Person]) { person => complete(person) } } However I get when I try to compile this: src/main/scala/com/example/ServiceActor.scala:61: error: could not find implicit value for parameter um: spray.httpx.unmarshalling.FromRequestUnmarshaller[com.example.Person] I don't understand what's happening, how can I fix this to be working? thanks Spray's 'entity[E]' directive

akka-http: How to set response headers

蓝咒 提交于 2019-12-03 12:55:04
I've a route as follows: val route = { logRequestResult("user-service") { pathPrefix("user") { get { respondWithHeader(RawHeader("Content-Type", "application/json")) { parameters("firstName".?, "lastName".?).as(Name) { name => findUserByName(name) match { case Left(users) => complete(users) case Right(error) => complete(error) } } } } ~ (put & entity(as[User])) { user => complete(Created -> s"Hello ${user.firstName} ${user.lastName}") } ~ (post & entity(as[User])) { user => complete(s"Hello ${user.firstName} ${user.lastName}") } ~ (delete & path(Segment)) { userId => complete(s"Hello $userId")