Package com.linkedin.r2.message.rest

Examples of com.linkedin.r2.message.rest.RestRequestBuilder


  public void testUnavailable() throws URISyntaxException
  {
    TestLoadBalancer balancer = new TestLoadBalancer(true);
    DynamicClient client = new DynamicClient(balancer, null);
    URI uri = URI.create("d2://test");
    RestRequest restRequest = new RestRequestBuilder(uri).build();
    TestCallback<RestResponse> restCallback = new TestCallback<RestResponse>();

    client.restRequest(restRequest, restCallback);

    assertNotNull(restCallback.e);
View Full Code Here


    return buildRequest("/test", headers, protocolVersion);
  }

  private final RestRequest buildRequest(String uri, Map<String, String> headers, ProtocolVersion protocolVersion) throws URISyntaxException
  {
    return new RestRequestBuilder(new URI(uri)).setMethod("DONT_CARE").setHeaders(headers).setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString()).build();
  }
View Full Code Here

    shutdown();
  }

  private RestRequest buildRequest(URI uri, String method, byte[] entity) throws IOException
  {
    RestRequestBuilder requestBuilder = new RestRequestBuilder(uri).setMethod(method);

    requestBuilder.setHeader(DEFAULT_HEADER, "1");

    if (entity != null)
    {
      requestBuilder.setEntity(entity).setHeader("Content-Type", "application/json");
    }

    return requestBuilder.build();
  }
View Full Code Here

   * @throws RestLiSyntaxException cannot happen here
   */
  public ResourceContextImpl() throws RestLiSyntaxException
  {
    this(new PathKeysImpl(),
         new RestRequestBuilder(URI.create(""))
             .setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.LATEST_PROTOCOL_VERSION.toString())
             .build(),
         new RequestContext());
  }
View Full Code Here

      throws URISyntaxException
  {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey);
    IdResponse<CompoundKey> idResponse = new IdResponse<CompoundKey>(compoundKey);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    Map<String, String> headers = getHeaders(protocolVersion);
    // the headers passed in are modified
    Map<String, String> expectedHeaders = new HashMap<String, String>(headers);

    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
View Full Code Here

  public void testBuilderException()
      throws URISyntaxException
  {
    CompoundKey compoundKey = new CompoundKey().append("a", "a").append("b", 1);
    CreateResponse createResponse = new CreateResponse(compoundKey, null);
    RestRequest restRequest = new RestRequestBuilder(new URI("/foo")).build();
    ProtocolVersion protocolVersion = AllProtocolVersions.RESTLI_PROTOCOL_1_0_0.getProtocolVersion();
    Map<String, String> headers = getHeaders(protocolVersion);

    ResourceMethodDescriptor mockDescriptor = getMockResourceMethodDescriptor();
    ResourceContext mockContext = getMockResourceContext(protocolVersion);
View Full Code Here

public class TestQueryTunnel
{
  @Test
  public void testSimpleGetNoArgs() throws Exception
  {
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279"))
                                       .setMethod("GET").build();

    // Pass to encode, but there are no query args, so nothing should change
    RestRequest encoded = QueryTunnelUtil.encode(request, 0);
    Assert.assertEquals(request.getURI(), encoded.getURI());
View Full Code Here

  }

  @Test
  public void testSimpleGetWithArgs() throws Exception
  {
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?q=one&x=10&y=15"))
                                       .setMethod("GET").build();

    // Process GET request with params. Set threshold to 0, which should convert the result to a POST
    // with no query, and a body
    RestRequest encoded = QueryTunnelUtil.encode(request, 0);
View Full Code Here

    StringBuilder sb = new StringBuilder("http://localhost:7279?");
    sb.append("eWithAcuteAccent=\u00e9");
    sb.append("&");
    sb.append("chineseCharacter=\u4e80");

    RestRequest req = new RestRequestBuilder(new URI(sb.toString())).setMethod("GET").build();

    RestRequest roundTrip = QueryTunnelUtil.decode(QueryTunnelUtil.encode(req, 0));

    Assert.assertEquals(req, roundTrip);
  }
View Full Code Here

  @Test
  public void testPostWithEntity() throws Exception
  {
    // Test a request with an entity and a query string, to be encoded as multipart/mixed
    RestRequest request = new RestRequestBuilder(new URI("http://localhost:7279?q=one&x=10&y=15"))
                                       .setMethod("POST")
                                       .setEntity(new String("{\name\":\"value\"}").getBytes())
                                       .setHeader("Content-Type", "application/json").build();

    // Test Conversion, should have a multipart body
View Full Code Here

TOP

Related Classes of com.linkedin.r2.message.rest.RestRequestBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.