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")));
}
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));
}
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());
}
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();
}
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();
}
Aggregations