use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TransportDispatcherImpl method handleStreamRequest.
@Override
public void handleStreamRequest(StreamRequest req, Map<String, String> wireAttrs, RequestContext requestContext, TransportCallback<StreamResponse> callback) {
final URI address = req.getURI();
final StreamRequestHandler handler = _streamHandlers.get(address);
if (handler == null) {
final RestResponse response = RestStatus.responseForStatus(RestStatus.NOT_FOUND, "No resource for URI: " + address);
callback.onResponse(TransportResponseImpl.success(Messages.toStreamResponse(response)));
req.getEntityStream().setReader(new DrainReader());
return;
}
try {
handler.handleRequest(req, requestContext, new TransportCallbackAdapter<StreamResponse>(callback));
} catch (Exception e) {
final Exception ex = RestException.forError(RestStatus.INTERNAL_SERVER_ERROR, e);
callback.onResponse(TransportResponseImpl.<StreamResponse>error(ex));
}
}
use of com.linkedin.r2.message.rest.RestResponse 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));
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class AbstractCaptureFilterTest method testInitialCapture.
@Test
public void testInitialCapture() {
final RestRequest req = request();
final RestResponse res = response();
Assert.assertNull(getDb().replay(req));
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req, res);
Assert.assertEquals(res, getDb().<Response>replay(req));
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class AbstractCaptureFilterTest method testTwoDifferentRequests.
@Test
public void testTwoDifferentRequests() {
final RestRequest req1 = request();
final RestRequest req2 = req1.builder().setEntity("This is a different request".getBytes()).build();
final RestResponse res1 = response();
final RestResponse res2 = res1.builder().setEntity("This is a different response".getBytes()).build();
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req1, res1);
FilterUtil.fireUntypedRequestResponse(getFilterChain(), req2, res2);
// Should have created two separate entries
Assert.assertEquals(res1, getDb().<Response>replay(req1));
Assert.assertEquals(res2, getDb().<Response>replay(req2));
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class AbstractReplayFilterTest method testReplayWithNoMatch.
@Test
public void testReplayWithNoMatch() {
final RestRequest req = request();
final RestResponse res = response();
final CaptureLastCallFilter captureFilter = new CaptureLastCallFilter();
final FilterChain fc = getFilterChain().addFirstRest(captureFilter);
FilterUtil.fireUntypedRequestResponse(fc, req, res);
Assert.assertEquals(res, captureFilter.getLastRes());
}
Aggregations