use of com.linkedin.r2.message.rest.RestRequest 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.RestRequest in project rest.li by linkedin.
the class TestDefaultMessageSerializer method testRestReqWithHeaders.
@Test
public void testRestReqWithHeaders() throws IOException {
final RestRequest expected = new RestRequestBuilder(URI.create("http://localhost:1234")).setHeader("field-name1", "field-val1").setHeader("field-name2", "field-val2").build();
assertMsgEquals(expected, _serializer.readRestRequest(getResource("rest-req-with-headers.txt")));
}
use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class TestDefaultMessageSerializer method testRestRequestReversible6.
@Test
public void testRestRequestReversible6() throws IOException {
final RestRequest req = createRestRequest().builder().setHeader("set-cookie", "field-value1").addCookie("cookie-key1=cookie-value1").build();
assertMsgEquals(req, readRestReq(writeReq(req)));
}
use of com.linkedin.r2.message.rest.RestRequest 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));
}
use of com.linkedin.r2.message.rest.RestRequest in project rest.li by linkedin.
the class AbstractCaptureFilterTest method testSameRequestDifferentResponses.
@Test
public void testSameRequestDifferentResponses() {
final RestRequest req = request();
final RestResponse res1 = response();
final RestResponse res2 = res1.builder().setEntity("This is a different response".getBytes()).build();
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req, res1);
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req, res2);
// Last one wins
Assert.assertEquals(res2, getDb().<Response>replay(req));
}
Aggregations