use of com.linkedin.restli.common.multiplexer.IndividualRequest 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.IndividualRequest in project rest.li by linkedin.
the class MultiplexedRequestBuilder method toIndividualRequest.
private static IndividualRequest toIndividualRequest(Request<?> request, IndividualRequestMap dependantRequests) throws RestLiEncodingException {
// TODO: Hardcoding RESTLI_PROTOCOL_2_0_0 for now. We need to refactor this code later to get protocol version using the mechanism similar to
// RestClient.getProtocolVersionForService()
ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_2_0_0.getProtocolVersion();
String relativeUrl = getRelativeUrl(request, protocolVersion);
IndividualRequest individualRequest = new IndividualRequest();
individualRequest.setRelativeUrl(relativeUrl);
individualRequest.setMethod(request.getMethod().getHttpMethod().name());
individualRequest.setHeaders(new StringMap(request.getHeaders()));
List<HttpCookie> cookies = request.getCookies();
if (cookies != null && !cookies.isEmpty()) {
throw new IllegalArgumentException(String.format("Cookies for individual request '%s' MUST be added at the envelope request level", relativeUrl));
}
individualRequest.setBody(getBody(request, protocolVersion), SetMode.IGNORE_NULL);
individualRequest.setDependentRequests(dependantRequests);
return individualRequest;
}
use of com.linkedin.restli.common.multiplexer.IndividualRequest in project rest.li by linkedin.
the class MultiplexedRequestBuilder method buildParallel.
private MultiplexedRequest buildParallel() throws RestLiEncodingException {
Map<Integer, Callback<RestResponse>> callbacks = new HashMap<>(_requestsWithCallbacks.size());
IndividualRequestMap individualRequests = new IndividualRequestMap(_requestsWithCallbacks.size());
// Dependent requests map is always empty
IndividualRequestMap dependentRequests = new IndividualRequestMap();
for (int i = 0; i < _requestsWithCallbacks.size(); i++) {
RequestWithCallback<?> requestWithCallback = _requestsWithCallbacks.get(i);
IndividualRequest individualRequest = toIndividualRequest(requestWithCallback.getRequest(), dependentRequests);
individualRequests.put(Integer.toString(i), individualRequest);
callbacks.put(i, wrapCallback(requestWithCallback));
}
return toMultiplexedRequest(individualRequests, callbacks, _requestOptions);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequest in project rest.li by linkedin.
the class MultiplexedRequestBuilder method buildSequential.
private MultiplexedRequest buildSequential() throws RestLiEncodingException {
Map<Integer, Callback<RestResponse>> callbacks = new HashMap<>(_requestsWithCallbacks.size());
// Dependent requests - requests which are dependent on the current request (executed after the current request)
IndividualRequestMap dependentRequests = new IndividualRequestMap();
// We start with the last request in the list and proceed backwards because sequential ordering is built using reverse dependencies
for (int i = _requestsWithCallbacks.size() - 1; i >= 0; i--) {
RequestWithCallback<?> requestWithCallback = _requestsWithCallbacks.get(i);
IndividualRequest individualRequest = toIndividualRequest(requestWithCallback.getRequest(), dependentRequests);
dependentRequests = new IndividualRequestMap();
dependentRequests.put(Integer.toString(i), individualRequest);
callbacks.put(i, wrapCallback(requestWithCallback));
}
return toMultiplexedRequest(dependentRequests, callbacks, _requestOptions);
}
use of com.linkedin.restli.common.multiplexer.IndividualRequest in project rest.li by linkedin.
the class InheritEnvelopeRequestTask method run.
@Override
protected Promise<? extends IndividualRequest> run(Context context) throws Throwable {
if (_individualRequest.isFailed()) {
return Promises.error(_individualRequest.getError());
}
IndividualRequest individualRequest = _individualRequest.get();
inheritHeaders(individualRequest, _envelopeRequest);
return Promises.value(individualRequest);
}
Aggregations