Search in sources :

Example 1 with IndividualBody

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();
}
Also used : IndividualBody(com.linkedin.restli.common.multiplexer.IndividualBody) ByteString(com.linkedin.data.ByteString) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 2 with IndividualBody

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);
}
Also used : EmptyRecord(com.linkedin.restli.common.EmptyRecord) IndividualRequest(com.linkedin.restli.common.multiplexer.IndividualRequest) IndividualRequestMap(com.linkedin.restli.common.multiplexer.IndividualRequestMap) StringMap(com.linkedin.data.template.StringMap) IndividualBody(com.linkedin.restli.common.multiplexer.IndividualBody) MultiplexedRequestContent(com.linkedin.restli.common.multiplexer.MultiplexedRequestContent) TestRecord(com.linkedin.restli.client.test.TestRecord) Test(org.testng.annotations.Test)

Example 3 with IndividualBody

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

Example 4 with IndividualBody

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

Example 5 with IndividualBody

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;
}
Also used : StringMap(com.linkedin.data.template.StringMap) IndividualBody(com.linkedin.restli.common.multiplexer.IndividualBody) ByteString(com.linkedin.data.ByteString) IndividualResponse(com.linkedin.restli.common.multiplexer.IndividualResponse)

Aggregations

IndividualBody (com.linkedin.restli.common.multiplexer.IndividualBody)6 ByteString (com.linkedin.data.ByteString)4 StringMap (com.linkedin.data.template.StringMap)3 IndividualResponse (com.linkedin.restli.common.multiplexer.IndividualResponse)3 IndividualRequest (com.linkedin.restli.common.multiplexer.IndividualRequest)2 IndividualRequestMap (com.linkedin.restli.common.multiplexer.IndividualRequestMap)2 Test (org.testng.annotations.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 FutureCallback (com.linkedin.common.callback.FutureCallback)1 DataMap (com.linkedin.data.DataMap)1 RequestContext (com.linkedin.r2.message.RequestContext)1 RestException (com.linkedin.r2.message.rest.RestException)1 RestRequest (com.linkedin.r2.message.rest.RestRequest)1 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)1 RestResponse (com.linkedin.r2.message.rest.RestResponse)1 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)1 TestRecord (com.linkedin.restli.client.test.TestRecord)1 EmptyRecord (com.linkedin.restli.common.EmptyRecord)1 IndividualResponseMap (com.linkedin.restli.common.multiplexer.IndividualResponseMap)1 MultiplexedRequestContent (com.linkedin.restli.common.multiplexer.MultiplexedRequestContent)1