use of org.apache.cxf.jaxrs.ext.StreamingResponse in project cxf by apache.
the class BookStoreWebSocket method getBookStream.
@GET
@Path("/bookstream")
@Produces("application/json")
public StreamingResponse<Book> getBookStream() {
return new StreamingResponse<Book>() {
public void writeTo(final StreamingResponse.Writer<Book> out) throws IOException {
out.write(new Book("WebSocket1", 1));
executor.execute(new Runnable() {
public void run() {
try {
for (int i = 2; i <= 5; i++) {
Thread.sleep(500);
out.write(new Book("WebSocket" + i, i));
out.getEntityStream().flush();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
};
}
Aggregations