/** * Adds all the required pagination links to the headers and body of the response. * * @param pages The paginated set of results containing the pages being linked to. * @param uriBuilder The uri builder to build the links * @param responseProcessor The response processor whose links are being built */ public static void addLinks( Pagination<?> pages, UriBuilder uriBuilder, MappingResponseProcessor responseProcessor ) { LinkedHashMap<String, URI> bodyLinks = new LinkedHashMap<>(); Arrays.stream(PaginationLink.values()) .forEachOrdered(link -> addLink(link, pages, uriBuilder, responseProcessor, bodyLinks)); ResponseContext responseContext = responseProcessor.getResponseContext(); responseContext.put(ResponseContextKeys.PAGINATION_LINKS_CONTEXT_KEY.getName(), bodyLinks); responseContext.put(ResponseContextKeys.PAGINATION_CONTEXT_KEY.getName(), pages); }
if (throwable instanceof ResponseException) { ResponseException responseException = (ResponseException) throwable; responseContext.put(ResponseContextKeys.STATUS.getName(), responseException.getStatusCode()); responseContext.put(ResponseContextKeys.ERROR_MESSAGE.getName(), responseException.getReason()); } else { responseContext.put( ResponseContextKeys.STATUS.getName(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode() ); responseContext.put(ResponseContextKeys.ERROR_MESSAGE.getName(), throwable.getMessage());
responseContext.put("headers", new MultivaluedHashMap<>()); responseContext.put("apiMetricColumnNames", apiMetricColumnNames); responseContext.put("requestedApiDimensionFields", new LinkedHashMap<>()); errorResponseContext.put("headers", new MultivaluedHashMap<>()); errorResponseContext.put(ResponseContextKeys.STATUS.getName(), 500); errorResponseContext.put(ResponseContextKeys.ERROR_MESSAGE.getName(), "Error"); errorResponseContext.put("apiMetricColumnNames", apiMetricColumnNames); errorResponseContext.put("requestedApiDimensionFields", new HashMap<>()); PreResponse errorPresResponse = new PreResponse(resultSet, errorResponseContext); preResponseStore.save("errorPreResponse", errorPresResponse);
responseContext.put("headers", new MultivaluedHashMap<>()); responseContext.put("apiMetricColumnNames", apiMetricColumnNames); responseContext.put("requestedApiDimensionFields", new LinkedHashMap<>()); errorResponseContext.put("headers", new MultivaluedHashMap<>()); errorResponseContext.put(ResponseContextKeys.STATUS.getName(), 500); errorResponseContext.put(ResponseContextKeys.ERROR_MESSAGE.getName(), "Error"); errorResponseContext.put("apiMetricColumnNames", apiMetricColumnNames); errorResponseContext.put("requestedApiDimensionFields", new HashMap<>()); PreResponse errorPresResponse = new PreResponse(resultSet, errorResponseContext); preResponseStore.save("errorPreResponse", errorPresResponse);
@Override public boolean handleRequest( RequestContext context, DataApiRequest request, DruidAggregationQuery<?> druidQuery, ResponseProcessor response ) { if (!(response instanceof MappingResponseProcessor)) { throw new IllegalStateException("Volatile data request handler requires a mapping response."); } MappingResponseProcessor mappingResponse = (MappingResponseProcessor) response; // Gather the volatile intervals. A volatile interval in one data source make that interval volatile overall. SimplifiedIntervalList volatileIntervals = volatileIntervalsService.getVolatileIntervals( druidQuery.getGranularity(), druidQuery.getIntervals(), physicalTableDictionary.get( druidQuery .getInnermostQuery() .getDataSource() .getPhysicalTable() .getName() ) ); if (!volatileIntervals.isEmpty()) { ResponseContext responseContext = response.getResponseContext(); responseContext.put(VOLATILE_INTERVALS_CONTEXT_KEY.getName(), volatileIntervals); } return next.handleRequest(context, request, druidQuery, mappingResponse); }