use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class ServletHelper method writeToServletError.
static void writeToServletError(HttpServletResponse resp, int statusCode, String message) throws IOException {
RestResponse restResponse = RestStatus.responseForStatus(statusCode, message);
writeResponseHeadersToServletResponse(TransportResponseImpl.success(Messages.toStreamResponse(restResponse)), resp);
final ByteString entity = restResponse.getEntity();
entity.write(resp.getOutputStream());
resp.getOutputStream().close();
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class DefaultMessageSerializer method readRestResponse.
@Override
public RestResponse readRestResponse(InputStream in) throws IOException {
final RestResponseBuilder builder = new RestResponseBuilder();
readResLine(builder, in);
readHeaders(builder, in, HttpConstants.RESPONSE_COOKIE_HEADER_NAME);
builder.setEntity(readEntity(in));
return builder.build();
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestDefaultMessageSerializer method testRestResponseReversible2.
@Test
public void testRestResponseReversible2() throws IOException {
final RestResponse res = createRestResponse().builder().setStatus(RestStatus.INTERNAL_SERVER_ERROR).build();
assertMsgEquals(res, readRestRes(writeRes(res)));
}
use of com.linkedin.r2.message.rest.RestResponse 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.RestResponse in project rest.li by linkedin.
the class TestServerTimeout method testServerThrowButShouldNotTimeout.
@Test
public void testServerThrowButShouldNotTimeout() throws Exception {
RestRequest request = new RestRequestBuilder(Bootstrap.createHttpURI(PORT, THROW_BUT_SHOULD_NOT_TIMEOUT_URI)).setEntity(new byte[10240]).build();
_client.restRequest(request);
Future<RestResponse> futureResponse = _client.restRequest(request);
// if server times out, our second request would fail with TimeoutException because it's blocked by first one
try {
futureResponse.get(SERVER_IOHANDLER_TIMEOUT / 2, TimeUnit.MILLISECONDS);
Assert.fail("Should fail with ExecutionException");
} catch (ExecutionException ex) {
Assert.assertTrue(ex.getCause() instanceof RestException);
RestException restException = (RestException) ex.getCause();
Assert.assertTrue(restException.getResponse().getEntity().asString("UTF8").contains("Server throw for test."));
}
}
Aggregations