mapper.writeValue(writer, messageFinder.getMessageObject());
}
private void getMessageList(HttpServletRequest request, HttpServletResponse response) throws IOException
{
Queue queue = getQueueFromRequest(request);
int first = -1;
int last = -1;
String range = request.getHeader("Range");
if(range != null)
{
String[] boundaries = range.split("=")[1].split("-");
first = Integer.parseInt(boundaries[0]);
last = Integer.parseInt(boundaries[1]);
}
final MessageCollector messageCollector = new MessageCollector(first, last);
queue.visit(messageCollector);
response.setContentType("application/json");
final List<Map<String, Object>> messages = messageCollector.getMessages();
int queueSize = (int) queue.getQueueDepthMessages();
String min = messages.isEmpty() ? "0" : messages.get(0).get("position").toString();
String max = messages.isEmpty() ? "0" : messages.get(messages.size()-1).get("position").toString();
response.setHeader("Content-Range", (min + "-" + max + "/" + queueSize));
response.setStatus(HttpServletResponse.SC_OK);