Search in sources :

Example 6 with MultiplexedRequestContent

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;
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent) DataMap(com.linkedin.data.DataMap)

Example 7 with MultiplexedRequestContent

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();
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)

Example 8 with MultiplexedRequestContent

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();
}
Also used : IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)

Aggregations

MultiplexedRequestContent (com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)8 IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)7 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)3 Test (org.testng.annotations.Test)3 DataMap (com.linkedin.data.DataMap)1 StringMap (com.linkedin.data.template.StringMap)1 TestRecord (com.linkedin.restli.client.test.TestRecord)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 IndividualBody (com.linkedin.restli.common.multiplexer.IndividualBody)1