I'm using Spring RestTemplate to write a RESTful client. I need to intantiate the HTTP Chunk mode on client side, so I can read chuncked data sent by the server I'm calling.
Can anyone help me how to do that? I've already searched on the internet for something that looks like what I need to do, but it didn't help. Can you, at least, put me on some direction? and I'll will try to do it on my own :)
I need to do something like this:
ExecutorService executorService = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 0L, //
TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
executorService.execute(() -> {
ChunkedInput<JsonNode> chunkedInput = null;
JsonNode chunk = null;
while (true) {
try {
chunkedInput = getJsonNodeChunkedInput(privatePollingUrl);
} catch (CtiAlcatelException e) {
logger.error("Getting Json Node Chunked Input refused", e);
}
while ((chunk = chunkedInput.read()) != null) {
logger.debug("-- Next chunk received: {}", chunk);
try {
processEvent(chunk);
} catch (Exception e) {
logger.error("Error occured while processing chunk {}", chunk, e);
}
}
if (Thread.currentThread().isInterrupted()) {
logger.info("Chunk thread interrupted");
Thread.currentThread().interrupt();
chunkedInput.close();
}
logger.debug("-- Restarting the chunk");
}
});
private ChunkedInput<JsonNode> getJsonNodeChunkedInput(String privatePollingUrl) throws CtiAlcatelException {
logger.trace(">> getJsonNodeChunkedInput() > Got param: {}", privatePollingUrl);
final Response response = restfulService.get(privatePollingUrl, alcAdminCredential.getCookie(), null);
ChunkedInput<JsonNode> chunkedInput = response.readEntity(new GenericType<ChunkedInput<JsonNode>>() {
});
logger.trace("<< getJsonNodeChunkedInput() < Returning: {}", chunkedInput);
return chunkedInput;
}
This is done using Jersey client. Thank you very much