Search in sources :

Example 6 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class TestDefaultMessageSerializer method testSimpleRestRes.

@Test
public void testSimpleRestRes() throws IOException {
    final RestResponse expected = new RestResponseBuilder().build();
    assertMsgEquals(expected, _serializer.readRestResponse(getResource("simple-rest-res.txt")));
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) Test(org.testng.annotations.Test)

Example 7 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class TestServerCompressionFilter method testResponseCompressionRules.

// Test response compression rules where the server has a default threshold of Integer.MAX_VALUE.
@Test(dataProvider = "headersData")
public void testResponseCompressionRules(String acceptEncoding, int compressionThreshold, EncodingType expectedContentEncoding) throws CompressionException, URISyntaxException {
    ServerCompressionFilter serverCompressionFilter = new ServerCompressionFilter(ACCEPT_COMPRESSIONS);
    RequestContext context = new RequestContext();
    context.putLocalAttr(HttpConstants.ACCEPT_ENCODING, acceptEncoding);
    context.putLocalAttr(HttpConstants.HEADER_RESPONSE_COMPRESSION_THRESHOLD, compressionThreshold);
    int originalLength = 100;
    byte[] entity = new byte[originalLength];
    Arrays.fill(entity, (byte) 'A');
    int compressedLength = (expectedContentEncoding == null) ? originalLength : expectedContentEncoding.getCompressor().deflate(new ByteArrayInputStream(entity)).length;
    String expectedContentEncodingName = (expectedContentEncoding == null) ? null : expectedContentEncoding.getHttpName();
    RestResponse restResponse = new RestResponseBuilder().setEntity(entity).build();
    serverCompressionFilter.onRestResponse(restResponse, context, Collections.<String, String>emptyMap(), new HeaderCaptureFilter(HttpConstants.CONTENT_ENCODING, expectedContentEncodingName, compressedLength));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) RequestContext(com.linkedin.r2.message.RequestContext) Test(org.testng.annotations.Test)

Example 8 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class EchoHandler method handleRequest.

@Override
public void handleRequest(RestRequest request, RequestContext requestContext, final Callback<RestResponse> callback) {
    RestResponseBuilder builder = new RestResponseBuilder();
    callback.onSuccess(builder.setEntity(request.getEntity()).build());
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 9 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder in project rest.li by linkedin.

the class RestLiResponseException method createErrorRestResponse.

private static RestResponse createErrorRestResponse(ErrorResponse errorResponse) {
    RestResponseBuilder builder = new RestResponseBuilder().setStatus(errorResponse.getStatus());
    String errorMessage = errorResponse.getMessage();
    if (errorMessage != null) {
        builder.setEntity(errorMessage.getBytes());
    }
    return builder.build();
}
Also used : RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder)

Example 10 with RestResponseBuilder

use of com.linkedin.r2.message.rest.RestResponseBuilder 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)

Aggregations

RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)67 Test (org.testng.annotations.Test)45 RestResponse (com.linkedin.r2.message.rest.RestResponse)41 RestException (com.linkedin.r2.message.rest.RestException)23 RequestExecutionReport (com.linkedin.restli.server.RequestExecutionReport)14 RequestExecutionReportBuilder (com.linkedin.restli.server.RequestExecutionReportBuilder)14 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)14 BeforeTest (org.testng.annotations.BeforeTest)14 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)13 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)11 RoutingException (com.linkedin.restli.server.RoutingException)10 FilterResponseContext (com.linkedin.restli.server.filter.FilterResponseContext)10 EmptyRecord (com.linkedin.restli.common.EmptyRecord)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 HashMap (java.util.HashMap)8 RequestContext (com.linkedin.r2.message.RequestContext)7 ByteString (com.linkedin.data.ByteString)6 RecordTemplate (com.linkedin.data.template.RecordTemplate)6 Map (java.util.Map)6