Source:
protected FullHttpResponse doGet(final FullHttpRequest request) { try { final QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); final Map<String, List<String>> parameters = decoder.parameters(); final String query = parameters.get("q").get(0); final Map<TimeSeriesId, Iterator<? extends DataPoint>> dataPoints = datapointsClient.query(query).get(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final JsonFactory jsonFactory = objectMapper.getFactory(); final JsonGenerator jsonGenerator = jsonFactory.createGenerator(out); jsonGenerator.writeStartObject(); for (final Map.Entry<TimeSeriesId, Iterator<? extends DataPoint>> timeSeries : dataPoints.entrySet()) { jsonGenerator.writeArrayFieldStart(timeSeries.getKey().toString()); final Iterator<? extends DataPoint> dps = timeSeries.getValue(); while (dps.hasNext()) { final DataPoint next = dps.next(); jsonGenerator.writeStartArray(2); if (next instanceof DataPoint.LongDataPoint) { jsonGenerator.writeNumber(((DataPoint.LongDataPoint) next).value()); } jsonGenerator.writeNumber(next.timestamp()); jsonGenerator.writeEndArray(); } jsonGenerator.writeEndArray(); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return response(OK, Unpooled.wrappedBuffer(out.toByteArray())); } catch (QueryException e) { return response(BAD_REQUEST); } catch (InterruptedException e) { e.printStackTrace(); return response(BAD_REQUEST); } catch (ExecutionException e) { e.printStackTrace(); return response(BAD_REQUEST); } catch (IOException e) { e.printStackTrace(); return response(BAD_REQUEST); } }

Target:
protected FullHttpResponse doGet(final FullHttpRequest request) { try { final QueryStringDecoder decoder = new QueryStringDecoder(request.uri()); final Map<String, List<String>> parameters = decoder.parameters(); final List<String> queries = parameters.get("q"); if (queries == null || queries.isEmpty()) { LOG.info("Received query request with missing query parameter"); return response(BAD_REQUEST); } final String query = queries.get(0); if (Strings.isNullOrEmpty(query)) { LOG.info("Received query request with empty query parameter"); return response(BAD_REQUEST); } final Map<TimeSeriesId, Iterator<? extends DataPoint>> dataPoints = datapointsClient.query(query).get(); final ByteArrayOutputStream out = new ByteArrayOutputStream(); final JsonFactory jsonFactory = objectMapper.getFactory(); final JsonGenerator jsonGenerator = jsonFactory.createGenerator(out); jsonGenerator.writeStartObject(); for (final Map.Entry<TimeSeriesId, Iterator<? extends DataPoint>> timeSeries : dataPoints.entrySet()) { jsonGenerator.writeArrayFieldStart(timeSeries.getKey().toString()); final Iterator<? extends DataPoint> timeSerieDataPoints = timeSeries.getValue(); while (timeSerieDataPoints.hasNext()) { final DataPoint next = timeSerieDataPoints.next(); jsonGenerator.writeStartArray(2); if (next instanceof DataPoint.LongDataPoint) { jsonGenerator.writeNumber(((DataPoint.LongDataPoint) next).value()); } jsonGenerator.writeNumber(next.timestamp()); jsonGenerator.writeEndArray(); } jsonGenerator.writeEndArray(); } jsonGenerator.writeEndObject(); jsonGenerator.close(); return response(OK, Unpooled.wrappedBuffer(out.toByteArray())); } catch (QueryException e) { LOG.warn("Encountered an exception while executing query", e); return response(BAD_REQUEST); } catch (InterruptedException e) { LOG.warn("Interrupted while executing query", e); return response(INTERNAL_SERVER_ERROR); } catch (ExecutionException e) { LOG.warn("Encountered an exception while executing query", e); return response(INTERNAL_SERVER_ERROR); } catch (IOException e) { LOG.warn("Encountered an exception while writing response", e); return response(INTERNAL_SERVER_ERROR); } }