use of com.linkedin.restli.common.multiplexer.MultiplexedRequestContent in project rest.li by linkedin.
the class MultiplexedRequestHandlerImpl method extractIndividualRequests.
/**
* Extracts individual requests from the given REST request.
*
* @return a non-empty map of individual requests
* @throws RestException if the payload of the RestRequest is ill-formed, contains no individual requests, or contains
* more than allowable individual requests.
*/
private IndividualRequestMap extractIndividualRequests(RestRequest restRequest) throws RestException {
validateHeaders(restRequest);
DataMap data = DataMapUtils.readMap(restRequest);
MultiplexedRequestContent multiplexedRequestContent = DataTemplateUtil.wrap(data, MultiplexedRequestContent.class);
IndividualRequestMap individualRequests = multiplexedRequestContent.getRequests();
int totalCount = totalRequestCount(individualRequests);
if (totalCount == 0) {
throw RestException.forError(HttpStatus.S_400_BAD_REQUEST.getCode(), "No individual requests to process");
}
if (totalCount > _maximumRequestsNumber) {
throw RestException.forError(HttpStatus.S_400_BAD_REQUEST.getCode(), "The server is configured to serve up to " + _maximumRequestsNumber + " requests, but received " + totalCount);
}
return individualRequests;
}
use of com.linkedin.restli.common.multiplexer.MultiplexedRequestContent in project rest.li by linkedin.
the class TestMultiplexedRequestHandlerImpl method fakeMuxRestRequest.
private static RestRequest fakeMuxRestRequest(Map<String, IndividualRequest> requests) throws URISyntaxException, IOException {
MultiplexedRequestContent content = new MultiplexedRequestContent();
content.setRequests(new IndividualRequestMap(requests));
return muxRequestBuilder().setMethod(HttpMethod.POST.name()).setEntity(CODEC.mapToBytes(content.data())).setHeader(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_APPLICATION_JSON).build();
}
use of com.linkedin.restli.common.multiplexer.MultiplexedRequestContent in project rest.li by linkedin.
the class TestMultiplexerRunMode method muxRestRequest.
private RestRequest muxRestRequest(Map<String, IndividualRequest> requests) throws URISyntaxException, IOException {
MultiplexedRequestContent content = new MultiplexedRequestContent();
content.setRequests(new IndividualRequestMap(requests));
return muxRequestBuilder().setMethod(HttpMethod.POST.name()).setEntity(CODEC.mapToBytes(content.data())).setHeader(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_APPLICATION_JSON).build();
}
Aggregations