Package com.linkedin.restli.client

Examples of com.linkedin.restli.client.RestLiResponseException


      Response<Greeting> response = future.getResponse();

      Assert.assertNull(response.getEntity());
      Assert.assertEquals(response.getStatus(), 404);

      RestLiResponseException restLiResponseException = response.getError();
      Assert.assertEquals(restLiResponseException.getStatus(), 404);
      Assert.assertEquals(restLiResponseException.getServiceErrorMessage(), "foo");
    }
    catch (Exception e)
    {
      Assert.fail("No exception should have been thrown!");
    }
View Full Code Here


  public void testBuild()
  {
    MockResponseBuilder<Long, Greeting> mockResponseBuilder = new MockResponseBuilder<Long, Greeting>();
    Greeting greeting = new Greeting().setId(1L).setMessage("message");
    Map<String, String> headers = Collections.singletonMap("foo", "bar");
    RestLiResponseException restLiResponseException = EasyMock.createMock(RestLiResponseException.class);
    EasyMock.expect(restLiResponseException.getErrorSource()).andReturn("foo").once();
    EasyMock.replay(restLiResponseException);

    // build a response object using all the setters. This response does not make sense logically but the goal here
    // is to test that the builder is working correctly.
View Full Code Here

        .setStatus(status)
        .setHeaders(Collections.unmodifiableMap(headers))
        .build();

    // create a RestLiResponseException and wrap it in an ExecutionException that will be thrown by the ResponseFuture
    RestLiResponseException restLiResponseException = new RestLiResponseException(restResponse, null, _errorResponse);
    ExecutionException executionException = new ExecutionException(restLiResponseException);

    Future<Response<V>> responseFuture = buildFuture(null, executionException);
    return new ResponseFutureImpl<V>(responseFuture, _errorHandlingBehavior);
  }
View Full Code Here

        .setEntity(entity)
        .setStatus(status)
        .setHeaders(decodedResponse.getHeaders())
        .build();

    RestLiResponseException restLiResponseException = new RestLiResponseException(restResponse,
                                                                                  decodedResponse,
                                                                                  new ErrorResponse());
    ExecutionException executionException = new ExecutionException(restLiResponseException);

    Future<Response<V>> responseFuture = buildFuture(null, executionException);
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
  public void testException(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException
  {
    Response<Greeting> response = null;
    RestLiResponseException exception = null;

    try
    {
      Request<Greeting> readRequest = builders.get().id(1L).build();
      ResponseFuture<Greeting> future;

      if (explicit)
      {
        future = REST_CLIENT.sendRequest(readRequest, errorHandlingBehavior);
      }
      else
      {
        future = REST_CLIENT.sendRequest(readRequest);
      }

      response = future.getResponse();

      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        Assert.fail("expected exception");
      }
    }
    catch (RestLiResponseException e)
    {
      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        exception = e;
      }
      else
      {
        Assert.fail("not expected exception");
      }
    }

    if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS)
    {
      Assert.assertNotNull(response);
      Assert.assertTrue(response.hasError());
      exception = response.getError();
      Assert.assertEquals(response.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
      Assert.assertNull(response.getEntity());
    }

    Assert.assertNotNull(exception);
    Assert.assertFalse(exception.hasDecodedResponse());
    Assert.assertEquals(exception.getStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR.getCode());
    Assert.assertEquals(exception.getServiceErrorCode(), 42);
    Assert.assertEquals(exception.getServiceErrorMessage(), "error processing request");
    Assert.assertTrue(exception.getServiceErrorStackTrace().contains("at com.linkedin.restli.examples.greetings.server.ExceptionsResource.get("));
  }
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
  public void testCreateError(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws Exception
  {
    Response<EmptyRecord> response = null;
    RestLiResponseException exception = null;

    try
    {
      Request<EmptyRecord> createRequest = builders.create()
          .input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING))
          .build();
      ResponseFuture<EmptyRecord> future;

      if (explicit)
      {
        future = REST_CLIENT.sendRequest(createRequest, errorHandlingBehavior);
      }
      else
      {
        future = REST_CLIENT.sendRequest(createRequest);
      }

      response = future.getResponse();

      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        Assert.fail("expected exception");
      }
    }
    catch (RestLiResponseException e)
    {
      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        exception = e;
      }
      else
      {
        Assert.fail("not expected exception");
      }
    }

    if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS)
    {
      Assert.assertNotNull(response);
      Assert.assertTrue(response.hasError());
      exception = response.getError();
      Assert.assertEquals(response.getStatus(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
      Assert.assertNull(response.getEntity());
    }

    Assert.assertNotNull(exception);
    Assert.assertFalse(exception.hasDecodedResponse());
    Assert.assertEquals(exception.getStatus(), HttpStatus.S_406_NOT_ACCEPTABLE.getCode());
    Assert.assertEquals(exception.getServiceErrorMessage(), "I will not tolerate your insolence!");
    Assert.assertEquals(exception.getServiceErrorCode(), 999);
    Assert.assertEquals(exception.getErrorSource(), RestConstants.HEADER_VALUE_ERROR);
    Assert.assertEquals(exception.getErrorDetails().getString("reason"), "insultingGreeting");
    Assert.assertTrue(exception.getServiceErrorStackTrace().startsWith("com.linkedin.restli.server.RestLiServiceException [HTTP Status:406, serviceErrorCode:999]: I will not tolerate your insolence!"),
                      "stacktrace mismatch:" + exception.getStackTrace());
  }
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
  public void testGet404(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException
  {
    Response<Greeting> response = null;
    RestLiResponseException exception = null;

    try
    {
      Request<Greeting> readRequest = builders.get().id(1L).build();
      ResponseFuture<Greeting> future;

      if (explicit)
      {
        future = REST_CLIENT.sendRequest(readRequest, errorHandlingBehavior);
      }
      else
      {
        future = REST_CLIENT.sendRequest(readRequest);
      }

      response = future.getResponse();

      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        Assert.fail("expected exception");
      }
    }
    catch (RestLiResponseException e)
    {
      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        exception = e;
      }
      else
      {
        Assert.fail("not expected exception");
      }
    }

    if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS)
    {
      Assert.assertNotNull(response);
      Assert.assertTrue(response.hasError());
      exception = response.getError();
      Assert.assertEquals(response.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
      Assert.assertNull(response.getEntity());
    }

    Assert.assertNotNull(exception);
    Assert.assertFalse(exception.hasDecodedResponse());
    Assert.assertEquals(exception.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
  }
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "exceptionHandlingModesDataProvider")
  public void testUpdate(boolean explicit, ErrorHandlingBehavior errorHandlingBehavior, RootBuilderWrapper<Long, Greeting> builders) throws Exception
  {
    Response<EmptyRecord> response = null;
    RestLiResponseException exception = null;

    try
    {
      Request<EmptyRecord> request = builders.update().id(11L)
          .input(new Greeting().setId(11L).setMessage("@#$%@!$%").setTone(Tone.INSULTING))
          .build();
      ResponseFuture<EmptyRecord> future;

      if (explicit)
      {
        future = REST_CLIENT.sendRequest(request, errorHandlingBehavior);
      }
      else
      {
        future = REST_CLIENT.sendRequest(request);
      }

      response = future.getResponse();

      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        Assert.fail("expected exception");
      }
    }
    catch (RestLiResponseException e)
    {
      if (!explicit || errorHandlingBehavior == ErrorHandlingBehavior.FAIL_ON_ERROR)
      {
        exception = e;
      }
      else
      {
        Assert.fail("not expected exception");
      }
    }

    if (explicit && errorHandlingBehavior == ErrorHandlingBehavior.TREAT_SERVER_ERROR_AS_SUCCESS)
    {
      Assert.assertNotNull(response);
      Assert.assertTrue(response.hasError());
      exception = response.getError();
      Assert.assertEquals(response.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
      Assert.assertNull(response.getEntity());
    }

    Assert.assertNotNull(exception);
    Assert.assertTrue(exception.hasDecodedResponse());
    Assert.assertEquals(exception.getStatus(), HttpStatus.S_404_NOT_FOUND.getCode());
  }
View Full Code Here

        {
          return new RemoteInvocationException(decodingException);
        }
      }

      return new RestLiResponseException(response, decodedResponse, errorResponse, e);
    }

    if (e instanceof RemoteInvocationException)
    {
      return (RemoteInvocationException) e;
View Full Code Here

  static RemoteInvocationException wrapThrowable(Throwable e)
  {
    if (e instanceof RestLiResponseException)
    {
      final RestLiResponseException restliException = (RestLiResponseException) e;
      final ErrorResponse errorResponse;

      try
      {
        errorResponse = getErrorResponse(restliException.getResponse());
      }
      catch (RestLiDecodingException decodingException)
      {
        return new RemoteInvocationException(decodingException);
      }

      return new RestLiResponseException(restliException.getResponse(),
                                         restliException.getDecodedResponse(),
                                         errorResponse,
                                         restliException);
    }

    return new RemoteInvocationException(e);
View Full Code Here

TOP

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

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.