Spray client Pipeline error

406 views
Skip to first unread message

Eric Weise

unread,
Mar 3, 2014, 5:14:47 PM3/3/14
to spray...@googlegroups.com
I am getting a couple of errors trying to build a simple pipeline that adds a header and does a post

[error] /Users/eweise/workspace/block-reporter-cell/src/main/scala/com/messagebus/block/app/Poster.scala:91: could not find implicit value for parameter aux: spray.httpx.TransformerAux[spray.http.HttpRequest,scala.concurrent.Future[spray.http.HttpResponse],spray.http.HttpRequest,spray.http.HttpRequest,R]
[error]     sendReceive ~> addHeader("X-My-Special-Header", "fancy-value")
[error]                 ^
[error] /Users/eweise/workspace/block-reporter-cell/src/main/scala/com/messagebus/block/app/Poster.scala:97: could not find implicit value for evidence parameter of type spray.httpx.marshalling.Marshaller[com.messagebus.block.model.Block]
[error]     Await.result(pipeline(Post("blocks", item)), 10000 millis)
[

My code looks like;


object BlockJsonProtocol extends DefaultJsonProtocol {
  implicit val orderFormat = jsonFormat3(Block)
}

class Poster extends Logging {

  import spray.http._
  import scala.concurrent.duration._
  import akka.actor.ActorSystem
  import spray.client.pipelining._
  import scala.concurrent.duration._
  import TransformerAux._
  import spray.client.pipelining._

  implicit val system = ActorSystem()
  implicit val timeout = Timeout(20 seconds)

  import system.dispatcher

  val pipeline: HttpRequest => Future[HttpResponse] = (sendReceive ~> addHeader("X-My-Special-Header", "fancy-value"))

  def handle(item: Block) = {
    import BlockJsonProtocol._
    Await.result(pipeline(Post("blocks", item)), 10000 millis)
  }
}

Can anyone tell me what I'm doing wrong or point me to an example that adds a header and does a post? I'm finding this DSL extremely difficult to use so if anyone can show me a more straightforward way to do a simple post without all the magic I would greatly appreciate it.

Eric

Mathias Doenitz

unread,
Mar 4, 2014, 3:21:57 AM3/4/14
to spray...@googlegroups.com
Eric,

the basic structure of a spray-client pipeline is this:

{request-transformation-stuff} ~> sendReceive ~> {response-transformation-stuff}

In your example:

sendReceive ~> addHeader("X-My-Special-Header", "fancy-value")

you use request transformation stuff (`addHeader`) on the response side of things, which cannot work.

If you want to add a header to the request you need to put the `addHeader` bit *before* the `sendReceive`.

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray.io User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
> Visit this group at http://groups.google.com/group/spray-user.
> To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/264b776a-acd0-457a-9737-2dbe18910796%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Eric Weise

unread,
Mar 5, 2014, 1:28:50 AM3/5/14
to spray...@googlegroups.com
Thanks for the response Mathius. Your explanation makes things much clearer.

Eric
Reply all
Reply to author
Forward
0 new messages