use of com.linkedin.r2.filter.NextFilter in project rest.li by linkedin.
the class TestServerRetryFilter method testNestedException.
@Test
public void testNestedException() {
String retryMessage = "this is a retry";
ServerRetryFilter retryFilter = new ServerRetryFilter();
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertEquals(wireAttrs.get(R2Constants.RETRY_MESSAGE_ATTRIBUTE_KEY), retryMessage);
}
};
FilterChain filterChain = FilterChains.createRestChain(captureFilter, retryFilter);
Throwable nestedException = new RetriableRequestException(retryMessage);
for (int i = 0; i < 5; i++) {
nestedException = new RuntimeException(nestedException);
}
FilterUtil.fireRestError(filterChain, new RestException(null, nestedException), new HashMap<String, String>());
}
use of com.linkedin.r2.filter.NextFilter in project rest.li by linkedin.
the class DispatcherRequestFilter method onStreamRequest.
@Override
public void onStreamRequest(StreamRequest req, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<StreamRequest, StreamResponse> nextFilter) {
Connector connector = null;
try {
final AtomicBoolean responded = new AtomicBoolean(false);
TransportCallback<StreamResponse> callback = createStreamCallback(requestContext, nextFilter, responded);
connector = new Connector(responded, nextFilter, requestContext, wireAttrs);
req.getEntityStream().setReader(connector);
EntityStream newStream = EntityStreams.newEntityStream(connector);
_dispatcher.handleStreamRequest(req.builder().build(newStream), wireAttrs, requestContext, callback);
} catch (Exception e) {
nextFilter.onError(e, requestContext, new HashMap<String, String>());
if (connector != null) {
connector.cancel();
}
}
}
Aggregations