Search in sources :

Example 41 with ByteString

use of com.linkedin.data.ByteString in project rest.li by linkedin.

the class MultiplexedRequestHandlerImpl method aggregateResponses.

private static RestResponse aggregateResponses(IndividualResponseMap responses, Map<String, HttpCookie> responseCookies) {
    MultiplexedResponseContent aggregatedResponseContent = new MultiplexedResponseContent();
    aggregatedResponseContent.setResponses(responses);
    ByteString aggregatedResponseData = DataMapUtils.mapToByteString(aggregatedResponseContent.data(), Collections.singletonMap(RestConstants.HEADER_CONTENT_TYPE, RestConstants.HEADER_VALUE_APPLICATION_JSON));
    return new RestResponseBuilder().setStatus(HttpStatus.S_200_OK.getCode()).setEntity(aggregatedResponseData).setCookies(CookieUtil.encodeSetCookies(new ArrayList<>(responseCookies.values()))).build();
}
Also used : MultiplexedResponseContent(com.linkedin.restli.common.multiplexer.MultiplexedResponseContent) ByteString(com.linkedin.data.ByteString) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 42 with ByteString

use of com.linkedin.data.ByteString 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 43 with ByteString

use of com.linkedin.data.ByteString 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)

Example 44 with ByteString

use of com.linkedin.data.ByteString in project rest.li by linkedin.

the class UnstructuredDataReactiveCollectionResource method get.

@Override
public void get(String key, @CallbackParam Callback<UnstructuredDataReactiveResult> callback) {
    Writer<ByteString> writer = new SingletonWriter<>(ByteString.copy(UNSTRUCTURED_DATA_BYTES));
    UnstructuredDataReactiveResult result = new UnstructuredDataReactiveResult(EntityStreams.newEntityStream(writer), MIME_TYPE);
    callback.onSuccess(result);
}
Also used : ByteString(com.linkedin.data.ByteString) UnstructuredDataReactiveResult(com.linkedin.restli.server.UnstructuredDataReactiveResult) SingletonWriter(com.linkedin.entitystream.SingletonWriter)

Example 45 with ByteString

use of com.linkedin.data.ByteString in project rest.li by linkedin.

the class TestSchemaSampleDataGenerator method testFixedSchema.

@Test
public void testFixedSchema() {
    final FixedDataSchema schema = (FixedDataSchema) DataTemplateUtil.getSchema(FixedMD5.class);
    final ByteString value = (ByteString) SchemaSampleDataGenerator.buildData(schema, _spec);
    Assert.assertSame(value.length(), schema.getSize());
}
Also used : ByteString(com.linkedin.data.ByteString) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) FixedMD5(com.linkedin.pegasus.generator.test.FixedMD5) UnionTest(com.linkedin.pegasus.generator.test.UnionTest) Test(org.testng.annotations.Test) TyperefTest(com.linkedin.pegasus.generator.test.TyperefTest)

Aggregations

ByteString (com.linkedin.data.ByteString)152 Test (org.testng.annotations.Test)77 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 MimeMultipart (javax.mail.internet.MimeMultipart)31 MimeBodyPart (javax.mail.internet.MimeBodyPart)26 DataMap (com.linkedin.data.DataMap)25 RestResponse (com.linkedin.r2.message.rest.RestResponse)25 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)22 FullEntityReader (com.linkedin.r2.message.stream.entitystream.FullEntityReader)22 RestRequest (com.linkedin.r2.message.rest.RestRequest)21 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)21 URI (java.net.URI)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 RequestContext (com.linkedin.r2.message.RequestContext)18 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)18 Callback (com.linkedin.common.callback.Callback)17 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)14 RestException (com.linkedin.r2.message.rest.RestException)12 HashMap (java.util.HashMap)12 DataList (com.linkedin.data.DataList)11