Search in sources :

Example 16 with IndividualRequestMap

use of com.linkedin.restli.common.multiplexer.IndividualRequestMap 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)

Aggregations

IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)16 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)10 MultiplexedRequestContent (com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)7 StringMap (com.linkedin.data.template.StringMap)5 RestResponse (com.linkedin.r2.message.rest.RestResponse)3 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)3 Callback (com.linkedin.common.callback.Callback)2 ByteString (com.linkedin.data.ByteString)1 DataMap (com.linkedin.data.DataMap)1 Task (com.linkedin.parseq.Task)1 RestException (com.linkedin.r2.message.rest.RestException)1 TestRecord (com.linkedin.restli.client.test.TestRecord)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 IndividualBody (com.linkedin.restli.common.multiplexer.IndividualBody)1 IndividualResponseMap (com.linkedin.restli.common.multiplexer.IndividualResponseMap)1 HttpCookie (java.net.HttpCookie)1 ArrayList (java.util.ArrayList)1 MimeTypeParseException (javax.activation.MimeTypeParseException)1