/** * Builds the headers for the response and gives them to the provided response builder to be added to the response. * * @param rspBuilder ResponseBuilder that handles adding the headers to the response * @param responseFormatType The type of the response * @param containerRequestContext The request context * * @return the response builder that has had the headers added */ protected ResponseBuilder buildAndAddResponseHeaders( ResponseBuilder rspBuilder, ResponseFormatType responseFormatType, ContainerRequestContext containerRequestContext ) { return buildAndAddResponseHeaders(rspBuilder, responseFormatType, containerRequestContext, null); }
@Override public void onNext(PreResponse preResponse) { publishResponse(httpResponseMaker.buildResponse(preResponse, apiRequest, containerRequestContext)); }
)); ResponseData responseData = buildResponseData( resultSet, (LinkedHashSet<String>) responseContext.get(API_METRIC_COLUMN_NAMES.getName()), return buildAndAddResponseHeaders( rspBuilder, responseFormatType,
/** * Build complete response. * * @param preResponse PreResponse object which contains result set, response context and headers * @param apiRequest ApiRequest object which contains request related information * @param containerRequestContext The container for jersey request processing objects * * @return Completely built response with headers and result set */ public javax.ws.rs.core.Response buildResponse( PreResponse preResponse, ApiRequest apiRequest, ContainerRequestContext containerRequestContext ) { ResponseBuilder rspBuilder = createResponseBuilder( preResponse.getResultSet(), preResponse.getResponseContext(), apiRequest, containerRequestContext ); @SuppressWarnings("unchecked") MultivaluedMap<String, Object> headers = (MultivaluedMap<String, Object>) preResponse .getResponseContext() .get(HEADERS.getName()); //Headers are a multivalued map, and we want to add each element of each value to the builder. headers.entrySet().stream() .forEach(entry -> entry.getValue().forEach(value -> rspBuilder.header(entry.getKey(), value))); return rspBuilder.build(); }
/** * Method to handle an error case from its observables. Default argument for this method is Throwable. * Customized this argument as Exception which contains the attributes to prepare the error Response. * If the throwable is not the type of `ResponseException`, then it will be re-thrown as RuntimeException. * * @param responseException An object contains error response attributes wrapped along with an Exception object */ @Override public void onError(Throwable responseException) { if (responseException instanceof ResponseException) { ResponseException resException = (ResponseException) responseException; publishResponse( httpResponseMaker.buildErrorResponse( resException.getStatusCode(), resException.getReason(), resException.getDescription(), resException.getDruidQuery() ) ); } else { LOG.error("Failed to publish error Response", responseException); throw new RuntimeException("Failed to publish error Response", responseException); } }