use of com.linkedin.restli.common.multiplexer.IndividualBody in project rest.li by linkedin.
the class MultiplexedCallback method buildIndividualRestResponse.
private static RestResponse buildIndividualRestResponse(Response<?> envelopeResponse, IndividualResponse individualResponse) throws IOException, MimeTypeParseException {
IndividualBody body = individualResponse.getBody(GetMode.NULL);
ByteString entity = (body != null) ? DataMapConverter.dataMapToByteString(individualResponse.getHeaders(), body.data()) : ByteString.empty();
return new RestResponseBuilder().setStatus(individualResponse.getStatus()).setHeaders(inheritHeaders(individualResponse, envelopeResponse)).setCookies(CookieUtil.encodeSetCookies(envelopeResponse.getCookies())).setEntity(entity).build();
}
use of com.linkedin.restli.common.multiplexer.IndividualBody in project rest.li by linkedin.
the class TestMultiplexedRequestBuilder method testBody.
@Test
public void testBody() throws IOException {
TestRecord entity = fakeEntity(0);
CreateRequest<TestRecord> request = fakeCreateRequest(entity);
NoOpCallback<EmptyRecord> callback = new NoOpCallback<>();
MultiplexedRequest multiplexedRequest = MultiplexedRequestBuilder.createSequentialRequest().addRequest(request, callback).build();
IndividualRequest individualRequest = new IndividualRequest().setMethod(HttpMethod.POST.name()).setHeaders(new StringMap(HEADERS)).setRelativeUrl(BASE_URI).setBody(new IndividualBody(entity.data()));
MultiplexedRequestContent expectedRequests = new MultiplexedRequestContent();
expectedRequests.setRequests(new IndividualRequestMap(ImmutableMap.of("0", individualRequest)));
assertMultiplexedRequestContentEquals(multiplexedRequest.getContent(), expectedRequests);
}
use of com.linkedin.restli.common.multiplexer.IndividualBody in project rest.li by linkedin.
the class IndividualResponseException method createErrorIndividualResponse.
private static IndividualResponse createErrorIndividualResponse(HttpStatus status, ErrorResponse errorResponse) {
IndividualResponse response = new IndividualResponse();
response.setStatus(status.getCode());
if (errorResponse != null) {
response.setBody(new IndividualBody(errorResponse.data()));
}
return response;
}
use of com.linkedin.restli.common.multiplexer.IndividualBody in project rest.li by linkedin.
the class SyntheticRequestCreationTask method getBodyAsByteString.
private static ByteString getBodyAsByteString(IndividualRequest individualRequest) throws MimeTypeParseException, IOException {
IndividualBody body = individualRequest.getBody(GetMode.NULL);
ByteString entity = ByteString.empty();
if (body != null) {
entity = DataMapConverter.dataMapToByteString(individualRequest.getHeaders(), body.data());
}
return entity;
}
use of com.linkedin.restli.common.multiplexer.IndividualBody in project rest.li by linkedin.
the class IndividualResponseConversionTask method toIndividualResponse.
private static IndividualResponse toIndividualResponse(String id, RestResponse restResponse) throws MimeTypeParseException, IOException {
IndividualResponse individualResponse = new IndividualResponse();
individualResponse.setStatus(restResponse.getStatus());
individualResponse.setHeaders(new StringMap(restResponse.getHeaders()));
ByteString entity = restResponse.getEntity();
if (!entity.isEmpty()) {
// TODO Avoid converting bytes to datamap here. Individual response should have only the bytes.
individualResponse.setBody(new IndividualBody(DataMapConverter.bytesToDataMap(restResponse.getHeaders(), entity)));
}
return individualResponse;
}
Aggregations