use of com.linkedin.restli.common.multiplexer.IndividualRequestMap 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();
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexerTestBase method fakeIndividualRequest.
protected static IndividualRequest fakeIndividualRequest(String url, Map<String, IndividualRequest> dependentCalls) {
IndividualRequest request = new IndividualRequest();
request.setMethod(HttpMethod.GET.name());
request.setHeaders(new StringMap(HEADERS));
request.setRelativeUrl(url);
request.setDependentRequests(new IndividualRequestMap(dependentCalls));
return request;
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexerTestBase method assertMultiplexedRequestContentEquals.
protected static void assertMultiplexedRequestContentEquals(MultiplexedRequestContent actual, MultiplexedRequestContent expected) {
IndividualRequestMap actualRequests = actual.getRequests();
IndividualRequestMap expectedRequests = expected.getRequests();
Assert.assertEquals(actualRequests.size(), expectedRequests.size());
for (String id : expectedRequests.keySet()) {
assertIndividualRequestEquals(actualRequests.get(id), expectedRequests.get(id));
}
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testSequential.
@Test
public void testSequential() throws RestLiEncodingException {
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request1, callback1).addRequest(request2, callback2).build();
//verify requests
IndividualRequest ir2 = fakeIndividualRequest(getUri(ID2));
IndividualRequest ir1 = fakeIndividualRequest(getUri(ID1), ImmutableMap.of("1", ir2));
MultiplexedRequestContent expectedRequests = new MultiplexedRequestContent();
expectedRequests.setRequests(new IndividualRequestMap(ImmutableMap.of("0", ir1)));
assertMultiplexedRequestContentEquals(multiplexedRequest.getContent(), expectedRequests);
verifyCallbacks(multiplexedRequest);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequestMap in project rest.li by linkedin.
the class MultiplexedRequestHandlerImpl method handleRequest.
@Override
public void handleRequest(RestRequest request, RequestContext requestContext, final Callback<RestResponse> callback) {
if (HttpMethod.POST != HttpMethod.valueOf(request.getMethod())) {
_log.error("POST is expected, but " + request.getMethod() + " received");
callback.onError(RestException.forError(HttpStatus.S_405_METHOD_NOT_ALLOWED.getCode(), "Invalid method"));
return;
}
IndividualRequestMap individualRequests;
try {
individualRequests = extractIndividualRequests(request);
} catch (RestException e) {
_log.error("Invalid multiplexed request", e);
callback.onError(e);
return;
} catch (Exception e) {
_log.error("Invalid multiplexed request", e);
callback.onError(RestException.forError(HttpStatus.S_400_BAD_REQUEST.getCode(), e));
return;
}
// prepare the map of individual responses to be collected
final IndividualResponseMap individualResponses = new IndividualResponseMap(individualRequests.size());
final Map<String, HttpCookie> responseCookies = new HashMap<>();
// all tasks are Void and side effect based, that will be useful when we add streaming
Task<?> requestProcessingTask = createParallelRequestsTask(request, requestContext, individualRequests, individualResponses, responseCookies);
Task<Void> responseAggregationTask = Task.action("send aggregated response", () -> {
RestResponse aggregatedResponse = aggregateResponses(individualResponses, responseCookies);
callback.onSuccess(aggregatedResponse);
});
_engine.run(requestProcessingTask.andThen(responseAggregationTask), MUX_PLAN_CLASS);
}
Aggregations