use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestCapRepFilter method testStreamException.
@Test
public void testStreamException() throws IOException {
Path dirPath = Files.createTempDirectory("caprep-test");
CaptureLastCallFilter lastCallFilter = new CaptureLastCallFilter();
FilterChain fc = FilterChains.createStreamChain(StreamFilterAdapters.adaptRestFilter(lastCallFilter), _filter);
RestRequest myRequest = new RestRequestBuilder(URI.create("/req1")).setEntity("123".getBytes()).build();
RestResponse myErrorResponse = new RestResponseBuilder().setStatus(400).setEntity("321".getBytes()).build();
RestException myRestException = new RestException(myErrorResponse);
_filter.capture(dirPath.toString());
RequestContext requestContext = new RequestContext();
FilterUtil.fireStreamRequest(fc, Messages.toStreamRequest(myRequest), requestContext, FilterUtil.emptyWireAttrs());
FilterUtil.fireStreamError(fc, Messages.toStreamException(myRestException), requestContext, FilterUtil.emptyWireAttrs());
lastCallFilter.reset();
_filter.replay(dirPath.toString());
FilterUtil.fireSimpleStreamRequest(fc);
Assert.assertNull(lastCallFilter.getLastErr());
FilterUtil.fireStreamRequest(fc, Messages.toStreamRequest(myRequest));
Assert.assertTrue(lastCallFilter.getLastErr() instanceof RestException);
Assert.assertEquals(((RestException) lastCallFilter.getLastErr()).getResponse(), myErrorResponse);
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestDefaultMessageSerializer method testRestResWithCookies.
@Test
public void testRestResWithCookies() throws IOException {
final RestResponse expected = new RestResponseBuilder().addCookie("cookie-name1=cookie-value1").addCookie("cookie-name2=cookie-value2").build();
assertMsgEquals(expected, _serializer.readRestResponse(getResource("rest-res-with-cookies.txt")));
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestDefaultMessageSerializer method testRestResWithHeadersAndCookies.
@Test
public void testRestResWithHeadersAndCookies() throws IOException {
final RestResponse expected = new RestResponseBuilder().addCookie("cookie-name1=cookie-value1").addCookie("cookie-name2=cookie-value2").addHeaderValue("header-field1", "header-value1").build();
assertMsgEquals(expected, _serializer.readRestResponse(getResource("rest-res-with-headers-and-cookies.txt")));
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestDefaultMessageSerializer method testRestResponseReversible4.
@Test
public void testRestResponseReversible4() throws IOException {
final RestResponse res = createRestResponse().builder().setHeader("field-key1", "field-val1").setHeader("field-key2", "field-val2").build();
assertMsgEquals(res, readRestRes(writeRes(res)));
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class AbstractClient method restRequest.
@Override
public void restRequest(RestRequest request, RequestContext requestContext, Callback<RestResponse> callback) {
StreamRequest streamRequest = Messages.toStreamRequest(request);
// IS_FULL_REQUEST flag, if set true, would result in the request being sent without using chunked transfer encoding
// This is needed as the legacy R2 server (before 2.8.0) does not support chunked transfer encoding.
requestContext.putLocalAttr(R2Constants.IS_FULL_REQUEST, true);
// here we add back the content-length header for the response because some client code depends on this header
streamRequest(streamRequest, requestContext, Messages.toStreamCallback(callback, true));
}
Aggregations