Package com.linkedin.restli.common

Examples of com.linkedin.restli.common.ErrorResponse


    // Filter suff.
    ArgumentCaptor<RestLiServiceException> exFromFilterCapture = ArgumentCaptor.forClass(RestLiServiceException.class);
    final Map<String, String> headersFromFilter = Maps.newHashMap();
    headersFromFilter.put("Key", "Error from filter");
    ErrorResponse errorResponseFromFilter = new ErrorResponse().setStatus(500);
    AugmentedRestLiResponseData responseErrorData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_500_INTERNAL_SERVER_ERROR)
                                                                   .errorResponse(errorResponseFromFilter)
                                                                   .headers(headersFromFilter).build();
    PartialRestResponse partialFilterErrorResponse = new PartialRestResponse.Builder().build();
View Full Code Here


  @SuppressWarnings("unchecked")
  @Test
  public void testOnErrorWithFiltersNotHandlingAppEx() throws Exception
  {
    Exception exFromApp = new RuntimeException("Runtime exception from app");
    ErrorResponse appErrorResponse = new ErrorResponse().setStatus(404);
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    final Map<String, String> headersFromApp = Maps.newHashMap();
    headersFromApp.put("Key", "Input");
    final Map<String, String> headersFromFilter = Maps.newHashMap();
    headersFromFilter.put("Key", "Output");
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testOnErrorWithFiltersSuccessfulyHandlingAppEx() throws Exception
  {
    Exception exFromApp = new RuntimeException("Runtime exception from app");
    ErrorResponse appErrorResponse = new ErrorResponse().setStatus(404);
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    final Map<String, String> headersFromApp = Maps.newHashMap();
    headersFromApp.put("Key", "Input");
    final RecordTemplate entityFromFilter = Foo.createFoo("Key", "Two");
    final Map<String, String> headersFromFilter = Maps.newHashMap();
View Full Code Here

  public void testOnErrorWithFiltersExceptionFromFirstFilterSecondFilterDoesNotHandle() throws Exception
  {
    // App stuff.
    RestLiServiceException exFromApp = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "App failure");
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    ErrorResponse appErrorResponse = new ErrorResponse().setStatus(404);
    AugmentedRestLiResponseData responseAppData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_404_NOT_FOUND)
                                                                   .errorResponse(appErrorResponse).build();

    // Filter stuff.
    final Exception exFromFirstFilter = new RuntimeException("Runtime exception from first filter");
    ErrorResponse filterErrorResponse = new ErrorResponse().setStatus(500);
    AugmentedRestLiResponseData responseFilterData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_500_INTERNAL_SERVER_ERROR)
                                                                   .errorResponse(filterErrorResponse).build();

    PartialRestResponse partialResponse = new PartialRestResponse.Builder().build();
View Full Code Here

  public void testOnErrorWithFiltersExceptionFromFirstFilterSecondFilterHandles() throws Exception
  {
    // App stuff.
    RestLiServiceException exFromApp = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "App failure");
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    ErrorResponse appErrorResponse = new ErrorResponse().setStatus(404);
    AugmentedRestLiResponseData responseAppData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_404_NOT_FOUND)
                                                                   .errorResponse(appErrorResponse).build();

    // Filter stuff.
    final Exception exFromFirstFilter = new RuntimeException("Runtime exception from first filter");
    ErrorResponse filterErrorResponse = new ErrorResponse().setStatus(500);
    AugmentedRestLiResponseData responseFilterData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_500_INTERNAL_SERVER_ERROR)
                                                                   .errorResponse(filterErrorResponse).build();
    final RecordTemplate entityFromFilter2 = Foo.createFoo("Key", "Two");
View Full Code Here

  private void buildErrorResponse(List<List<? extends Object>> ret)
  {
    for (ResourceMethod type : ResourceMethod.values())
    {
      ret.add(Arrays.asList(type, null, new ErrorResponse(Foo.createFoo("foo", "bar").data()), null, null, null, null,
                            ImmutableMap.of("key", "value"), HttpStatus.S_404_NOT_FOUND, false));
    }
  }
View Full Code Here

  {
    if (e instanceof RestException)
    {
      final RestException re = (RestException) e;
      final RestResponse response = re.getResponse();
      final ErrorResponse errorResponse;

      try
      {
        errorResponse = getErrorResponse(response);
      }
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());
      }
View Full Code Here

    return new RemoteInvocationException(e);
  }

  private static ErrorResponse getErrorResponse(RestResponse response) throws RestLiDecodingException
  {
    ErrorResponse errorResponse = null;

    final String header = HeaderUtil.getErrorResponseHeaderValue(response.getHeaders());

    if (header != null)
    {
      errorResponse =  ERROR_DECODER.decodeResponse(response).getEntity();
    }

    if (errorResponse == null)
    {
      errorResponse = new ErrorResponse();
    }

    return errorResponse;
  }
View Full Code Here

                                      final int httpCode,
                                      final int appCode,
                                      final ProtocolVersion protocolVersion,
                                      final String errorResponseHeaderName)
  {
    final ErrorResponse er = new ErrorResponse();

    final DataMap errMap = new DataMap();
    errMap.put(errKey, errValue);
    er.setErrorDetails(new ErrorDetails(errMap));
    er.setStatus(httpCode);
    er.setMessage(errMsg);
    er.setServiceErrorCode(appCode);

    final byte[] mapBytes;
    try
    {
      mapBytes = new JacksonDataCodec().mapToBytes(er.data());
    }
    catch (final IOException e)
    {
      throw new RuntimeException(e);
    }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.common.ErrorResponse

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.