use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestClientRetryFilter method testNoWireAttribute.
@Test
public void testNoWireAttribute() {
ClientRetryFilter clientRetryFilter = new ClientRetryFilter();
RemoteInvocationException exception = new RemoteInvocationException("exception");
RestFilter captureFilter = new RestFilter() {
@Override
public void onRestError(Throwable ex, RequestContext requestContext, Map<String, String> wireAttrs, NextFilter<RestRequest, RestResponse> nextFilter) {
Assert.assertEquals(exception, ex);
}
};
FilterChain filterChain = FilterChains.createRestChain(captureFilter, clientRetryFilter);
FilterUtil.fireRestError(filterChain, exception, new HashMap<>());
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestRestBuilders method testSetHeaderWithCookieFails.
@Test(expectedExceptions = IllegalArgumentException.class)
public void testSetHeaderWithCookieFails() {
final String headerName = "set-cookie";
final String headerValue = "value";
final RestResponse res = new RestResponseBuilder().setHeader(headerName, headerValue).build();
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestRestBuilders method testSetCookiesMultipleValues.
@Test
public void testSetCookiesMultipleValues() {
final String cookie1 = "cookie1";
final String cookie2 = "cookie2";
final String cookie3 = "cookie3";
List<String> cookies = new ArrayList<String>();
cookies.add(cookie2);
cookies.add(cookie3);
final RestResponse res = new RestResponseBuilder().addCookie(cookie1).setCookies(cookies).build();
Assert.assertNotNull(res.getHeaders());
Assert.assertNotNull(res.getCookies());
Assert.assertTrue(res.getHeaders().isEmpty());
Assert.assertEquals(res.getCookies().size(), 2);
Assert.assertEquals(res.getCookies().get(0), cookie2);
Assert.assertEquals(res.getCookies().get(1), cookie3);
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class RAPResponseHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, RestResponse response) throws Exception {
final Map<String, String> headers = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
final Map<String, String> wireAttrs = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
headers.putAll(response.getHeaders());
wireAttrs.putAll(WireAttributeHelper.removeWireAttributes(headers));
final RestResponse newResponse = new RestResponseBuilder(response).unsafeSetHeaders(headers).build();
// In general there should always be a callback to handle a received message,
// but it could have been removed due to a previous exception or closure on the
// channel
TransportCallback<RestResponse> callback = ctx.channel().attr(CALLBACK_ATTR_KEY).getAndRemove();
if (callback != null) {
LOG.debug("{}: handling a response", ctx.channel().remoteAddress());
callback.onResponse(TransportResponseImpl.success(newResponse, wireAttrs));
} else {
LOG.debug("{}: dropped a response", ctx.channel().remoteAddress());
}
ctx.fireChannelRead(response);
}
use of com.linkedin.r2.message.rest.RestResponse in project rest.li by linkedin.
the class TestChannelPoolHandler method testConnectionClose.
@Test(dataProvider = "connectionClose")
public void testConnectionClose(String headerName, String headerValue) {
EmbeddedChannel ch = new EmbeddedChannel(new ChannelPoolHandler());
FakePool pool = new FakePool();
ch.attr(ChannelPoolHandler.CHANNEL_POOL_ATTR_KEY).set(pool);
RestResponse response = new RestResponseBuilder().setHeader(headerName, headerValue).build();
ch.writeInbound(response);
Assert.assertTrue(pool.isDisposeCalled());
Assert.assertFalse(pool.isPutCalled());
}
Aggregations