Package com.linkedin.restli.client

Examples of com.linkedin.restli.client.RestClient


    final HttpClientFactory http = new HttpClientFactory();
    final Client r2Client = new TransportClientAdapter(
                                      http.getClient(Collections.<String, String>emptyMap()));

    // Create a RestClient to talk to localhost:8080
    RestClient restClient = new RestClient(r2Client, "http://localhost:8080/");

    // Generate a random ID for a fortune cookie, in the range 0-5
    long fortuneId = (long) (Math.random() * 5);

    // Construct a request for the specified fortune
    FortunesGetBuilder getBuilder = _fortuneBuilder.get();
    Request<Fortune> getReq = getBuilder.id(fortuneId).build();

    // Send the request and wait for a response
    final ResponseFuture<Fortune> getFuture = restClient.sendRequest(getReq);
    final Response<Fortune> resp = getFuture.getResponse();

    // Print the response
    System.out.println(resp.getEntity().getFortune());

    // shutdown
    restClient.shutdown(new FutureCallback<None>());
    http.shutdown(new FutureCallback<None>());
  }
View Full Code Here


  }

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
  public void testPostsWithCharset(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException
  {
    RestClient restClient = new RestClient(CLIENT, URI_PREFIX);

    Request<Greeting> request = builders.<Greeting>action("SomeAction").id(1L)
      .setActionParam("A", 1)
      .setActionParam("B", "")
      .setActionParam("C", new TransferOwnershipRequest())
      .setActionParam("D", new TransferOwnershipRequest())
      .setActionParam("E", 3)
      .setHeader("Content-Type", "application/json; charset=UTF-8")
      .build();

    Response<Greeting> response = restClient.sendRequest(request).getResponse();

    Greeting actionGreeting = response.getEntity();
    Assert.assertEquals(actionGreeting.getMessage(), "This is a newly created greeting");

    Greeting createGreeting = new Greeting();
    createGreeting.setMessage("Hello there!");
    createGreeting.setTone(Tone.FRIENDLY);

    Request<EmptyRecord> createRequest = builders
      .create()
      .input(createGreeting)
      .setHeader("Content-Type", "application/json; charset=UTF-8")
      .build();
    Response<EmptyRecord> emptyRecordResponse = restClient.sendRequest(createRequest).getResponse();
    Assert.assertNull(emptyRecordResponse.getHeader(RestConstants.HEADER_CONTENT_TYPE));
  }
View Full Code Here

  @DataProvider(name = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataDataProvider")
  public Object[][] clientDataDataProvider()
  {
    return new Object[][]
      {
        { new RestClient(CLIENT, URI_PREFIX), new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders()) }, // default client
        { new RestClient(CLIENT, URI_PREFIX), new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)) }, // default client
        { new RestClient(CLIENT, URI_PREFIX), new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders()) }, // default client
        { new RestClient(CLIENT, URI_PREFIX), new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)) }, // default client
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders()) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders()) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders()) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders()) },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), new RootBuilderWrapper<Long, Greeting>(new GreetingsRequestBuilders(TestConstants.FORCE_USE_NEXT_OPTIONS)) }
      };
  }
View Full Code Here

  @DataProvider(name = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientDataBatchDataProvider")
  public Object[][] clientDataBatchDataProvider()
  {
    return new Object[][]
      {
        { new RestClient(CLIENT, URI_PREFIX), RestliRequestOptions.DEFAULT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX), TestConstants.FORCE_USE_NEXT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), RestliRequestOptions.DEFAULT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), TestConstants.FORCE_USE_NEXT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), RestliRequestOptions.DEFAULT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), TestConstants.FORCE_USE_NEXT_OPTIONS },
      };
  }
View Full Code Here

  @DataProvider(name = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "buildersClientDataDataProvider")
  public Object[][] buildersClientDataDataProvider()
  {
    return new Object[][]
      {
        { new RestClient(CLIENT, URI_PREFIX), RestliRequestOptions.DEFAULT_OPTIONS }, // default client
        { new RestClient(CLIENT, URI_PREFIX), TestConstants.FORCE_USE_NEXT_OPTIONS }, // default client
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), RestliRequestOptions.DEFAULT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.JSON, ACCEPT_TYPES), TestConstants.FORCE_USE_NEXT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), RestliRequestOptions.DEFAULT_OPTIONS },
        { new RestClient(CLIENT, URI_PREFIX, RestClient.ContentType.PSON, ACCEPT_TYPES), TestConstants.FORCE_USE_NEXT_OPTIONS }
      };
  }
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
  public void testNonRestException(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders)
  {
    Response<Greeting> response = null;
    RestClient brokenClient = new RestClient(CLIENT, "http://localhost:8888/");
    try
    {
      final Request<Greeting> req = builders.get().id(1L).build();
      ResponseFuture<Greeting> future;

      if (explicit)
      {
        future = brokenClient.sendRequest(req, errorHandlingBehavior);
      }
      else
      {
        future = brokenClient.sendRequest(req);
      }

      response = future.getResponse();

      Assert.fail("expected exception");
View Full Code Here

TOP

Related Classes of com.linkedin.restli.client.RestClient

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.