Spray Http Akka sender stuck on response

98 views
Skip to first unread message

Richard Grossman

unread,
Mar 24, 2013, 3:52:42 PM3/24/13
to spray...@googlegroups.com
Hi

I'm really lost and I can understand what going on.
I've written this to make aynch http call. 


 val req = HttpRequest(method = GET, uri = uri)
    for ((k, v) <- headers) req ~> addHeader(k, v)

    val pipeline = HttpConduit.sendReceive(conduit)
    val responseQuery: Future[HttpResponse] = pipeline(req)

    sender ! RequestResult("", "cxcxcxcxcx")

    responseQuery onComplete {
      case Success(response) => {
        log.info("Success with status: " + response.status)
        val content = response.entity.asString
        sender ! RequestResult(uri, content)
      }

      case Failure(error) =>
        log.info("Failure : " + error)
        sender ! RequestResult(uri, error.getMessage)
    } 

It's working I get content I can pring it even but
on the first sender ! RequestResult No problem I get response back on my dispatcher(sender)
but the second one after the responseQuery onComplete don't send nothing back.

Please some help. May be I wrong using Akka or it's related to how I'm using spray http 

Thanks

Mathias

unread,
Mar 24, 2013, 4:18:52 PM3/24/13
to spray...@googlegroups.com
Richard,

> for ((k, v) <- headers) req ~> addHeader(k, v)

This line doesn't do anything!
The HttpRequest instance `req` is immutable, `addHeader` is not side-effecting.

> It's working I get content I can pring it even but
> on the first sender ! RequestResult No problem I get response back on my
> dispatcher(sender)
> but the second one after the responseQuery onComplete don't send nothing
> back.

It's hard to see the problem without having the bigger picture of how the code snippet you showed ties into the rest of your code.
Do you see the second request go out on the wire?
Is the server really responding?
Where do you think the response is "lost"?

Cheers,
Mathias

---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "spray-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Roland Kuhn

unread,
Mar 24, 2013, 4:23:18 PM3/24/13
to spray...@googlegroups.com
Hi Richard,

24 mar 2013 kl. 20:52 skrev Richard Grossman:

Hi

I'm really lost and I can understand what going on.
I've written this to make aynch http call. 


 val req = HttpRequest(method = GET, uri = uri)
    for ((k, v) <- headers) req ~> addHeader(k, v)

    val pipeline = HttpConduit.sendReceive(conduit)
    val responseQuery: Future[HttpResponse] = pipeline(req)

    sender ! RequestResult("", "cxcxcxcxcx")

    responseQuery onComplete {
      case Success(response) => {
        log.info("Success with status: " + response.status)
        val content = response.entity.asString
        sender ! RequestResult(uri, content)

You cannot access the mutable field `sender` from a Future callback (will probably go to deadLetters); instead cache the sender in a local val:

...
val orig = sender
f onComplete { ... orig ! result }

      }

      case Failure(error) =>
        log.info("Failure : " + error)
        sender ! RequestResult(uri, error.getMessage)

Same here.

Regards,

Roland

    } 

It's working I get content I can pring it even but
on the first sender ! RequestResult No problem I get response back on my dispatcher(sender)
but the second one after the responseQuery onComplete don't send nothing back.

Please some help. May be I wrong using Akka or it's related to how I'm using spray http 

Thanks


--
You received this message because you are subscribed to the Google Groups "spray-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Empowering professional developers to build amazing apps.
twitter: @rolandkuhn

Richard Grossman

unread,
Mar 25, 2013, 3:31:38 AM3/25/13
to spray...@googlegroups.com
Thanks for your help it work perfectly !!


Mathias I still looking how to configure the request object for adding headers
thanks

Mathias

unread,
Mar 25, 2013, 4:40:23 AM3/25/13
to spray...@googlegroups.com
Richard,

> Mathias I still looking how to configure the request object for adding headers


Have you looked at this chapter of the docs?:
http://spray.io/documentation/spray-client/#message-pipeline

It shows you how to use things like `addHeader`, `addCredentials` or `encode` to form a pipeline of request transformation logic.
The key idea is to have spray-client produce a *function* that turns a request into a response (or something derived from a response).

HTH and cheers,
Reply all
Reply to author
Forward
0 new messages