1

I am streaming content to my rest end-point and I have implemented it as a ServerResource. Consuming the incoming stream is not a problem but while processing the input I do want to start feeding info back to the client. However, I assume this cannot be done from a ServerResource since it would require me to actually return a Representation (and subsequently I would abort reading from the input stream).

What is the recommended approach in this scenario? Use a raw Restlet and deal with it in the handle-method? How have people solved this in general?

Obviously, it can easily be accomplished using a "raw" HttpServlet but I would love to be able to use restlet across the board.

Marvin Pinto
  • 30,138
  • 7
  • 37
  • 54
jonbo372
  • 88
  • 1
  • 6

1 Answers1

0

While not the cleanest option, you can have the client open a second connection to the server asking for the content. The server will have to hold the connection open until it has data to start sending back, but you end up with the same result. It's sort of a "long polling" approach to the problem and, architecturally, is just separating the write from the read.

There are likely better ways to accomplish this, but I tend to go with the quick solution initially and then come back to it if it's needed (ie. if it's a problem in some way, like maintainability or performance)

cdeszaq
  • 30,869
  • 25
  • 117
  • 173
  • Thanks for your response but this would only work if I controlled the clients, which I unfortunately don't. Using the HttpServlet directly is working fine so for now I'm sticking with that option but I would love to get everything over to a proper Restlet approach. – jonbo372 Mar 05 '12 at 23:52