Search in sources :

Example 96 with RestResponse

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<>());
}
Also used : RestFilter(com.linkedin.r2.filter.message.rest.RestFilter) NextFilter(com.linkedin.r2.filter.NextFilter) FilterChain(com.linkedin.r2.filter.FilterChain) ClientRetryFilter(com.linkedin.r2.filter.transport.ClientRetryFilter) RemoteInvocationException(com.linkedin.r2.RemoteInvocationException) RequestContext(com.linkedin.r2.message.RequestContext) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 97 with RestResponse

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();
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) Test(org.testng.annotations.Test)

Example 98 with RestResponse

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);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) ArrayList(java.util.ArrayList) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) Test(org.testng.annotations.Test)

Example 99 with RestResponse

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);
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) TreeMap(java.util.TreeMap)

Example 100 with RestResponse

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());
}
Also used : RestResponse(com.linkedin.r2.message.rest.RestResponse) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Test(org.testng.annotations.Test)

Aggregations

RestResponse (com.linkedin.r2.message.rest.RestResponse)231 Test (org.testng.annotations.Test)174 RestRequest (com.linkedin.r2.message.rest.RestRequest)147 RequestContext (com.linkedin.r2.message.RequestContext)108 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)100 URI (java.net.URI)74 RestException (com.linkedin.r2.message.rest.RestException)68 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)55 ByteString (com.linkedin.data.ByteString)50 FutureCallback (com.linkedin.common.callback.FutureCallback)45 Callback (com.linkedin.common.callback.Callback)43 HashMap (java.util.HashMap)41 ExecutionException (java.util.concurrent.ExecutionException)40 Map (java.util.Map)38 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)35 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)29 URISyntaxException (java.net.URISyntaxException)27 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)24 FilterChain (com.linkedin.r2.filter.FilterChain)23 BeforeTest (org.testng.annotations.BeforeTest)23