PUT/POST long running request and streaming body data

81 views
Skip to first unread message

alm...@googlemail.com

unread,
Apr 8, 2014, 7:02:56 AM4/8/14
to dispatc...@googlegroups.com
Hi,
I'm trying to call a WS using dispatch which will establish a long running connection (very much like twitters firewhose endpoint)
When connected, I need to stream body data from a (possibly endless) input stream.

I tried to use nings InputStreamBodyGenerator but it looks like it doesnt send the data of the inputstream immediatelly over the wire.

Here's my sample code:
val req = url(myWSUrl).POST
req.subject.underlying(_.setBody(new InputStreamBodyGenerator(is)))

val futureResponse = Http(req > customAsyncHandler)

for debugging I simulate the WS endpoint using a netcat -l 8080 which prints the incoming request to stdout - it sends the requestheaders but no body data:

POST /debugendpoint HTTP/1.1
Host: localhost:1212
Connection: keep-alive
Accept: */*
User-Agent: Dispatch/0.11.0


any suggestions how to accomplish this ?
thanks & cheers
hanez

Miles Spielberg

unread,
Apr 9, 2014, 8:59:03 PM4/9/14
to dispatc...@googlegroups.com
Req.underlying returns a modified copy of the Req with the additional changes embedded. You need to capture the return value from req.underlying, and provide that to Http():

val req = url(myWSUrl).POST
val reqWithBody = req.underlying(_.setBody(new InputStreamBodyGenerator(is)))

val futureResponse = Http(reqWithBody > customAsyncHandler)


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

alm...@googlemail.com

unread,
Apr 10, 2014, 6:22:02 AM4/10/14
to dispatc...@googlegroups.com
... which perfectly makes sense! :-)

Thanks for pointing this out Miles!
Reply all
Reply to author
Forward
0 new messages