Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.RestLiServiceException


  @SuppressWarnings("unchecked")
  @Test
  public void testOnErrorWithFiltersExceptionFromSecondFilter() throws Exception
  {
    // App stuff.
    RestLiServiceException exFromApp = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "App failure");
    RequestExecutionReport executionReport = new RequestExecutionReportBuilder().build();
    AugmentedRestLiResponseData responseAppData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_404_NOT_FOUND).build();
    // Filter stuff.
    final Exception exFromSecondFilter = new RuntimeException("Runtime exception from second filter");
    AugmentedRestLiResponseData responseFilterData =
        new AugmentedRestLiResponseData.Builder(ResourceMethod.GET).status(HttpStatus.S_500_INTERNAL_SERVER_ERROR).build();

    PartialRestResponse partialResponse = new PartialRestResponse.Builder().build();

    ArgumentCaptor<RestLiServiceException> wrappedExCapture = ArgumentCaptor.forClass(RestLiServiceException.class);
    RestException restException = new RestException(new RestResponseBuilder().build());

    // Setup.
    when(
         _responseHandler.buildErrorResponseData(eq(_restRequest), eq(_routingResult),
                                                 wrappedExCapture.capture(), anyMap())).thenReturn(responseAppData)
                                                                                       .thenReturn(responseFilterData);
    when(_responseHandler.buildPartialResponse(_routingResult, responseFilterData)).thenReturn(partialResponse);
    when(_restRequest.getHeaders()).thenReturn(null);
    when(_responseHandler.buildRestException(exFromSecondFilter, partialResponse)).thenReturn(restException);

    // Mock filter behavior.
    doAnswer(new Answer<Object>()
    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        assertEquals(context.getHttpStatus(), HttpStatus.S_404_NOT_FOUND);
        assertNull(context.getResponseData().getEntityResponse());
        assertTrue(context.getResponseHeaders().isEmpty());

        // Modify data.
        context.setHttpStatus(HttpStatus.S_402_PAYMENT_REQUIRED);
        return null;
      }
    }).doThrow(exFromSecondFilter).when(_filter)
      .onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    // Invoke.
    _twoFilterRestLiCallback.onError(exFromApp, executionReport);

    // Verify.
    verify(_responseHandler, times(2)).buildErrorResponseData(eq(_restRequest), eq(_routingResult),
                                                              wrappedExCapture.capture(), anyMap());
    verify(_responseHandler).buildPartialResponse(_routingResult, responseFilterData);
    verify(_responseHandler).buildRestException(exFromSecondFilter, partialResponse);
    verify(_callback).onError(restException, executionReport);
    verify(_restRequest, times(2)).getHeaders();
    verifyZeroInteractions(_routingResult);
    verifyNoMoreInteractions(_restRequest, _responseHandler, _callback);
    assertNotNull(responseFilterData);
    assertEquals(HttpStatus.S_500_INTERNAL_SERVER_ERROR, responseFilterData.getStatus());
    assertTrue(responseFilterData.getHeaders().isEmpty());
    assertNull(responseFilterData.getEntityResponse());
    RestLiServiceException restliEx = wrappedExCapture.getAllValues().get(0);
    assertNotNull(restliEx);
    assertEquals(exFromApp.getStatus(), restliEx.getStatus());
    assertEquals(exFromApp.getMessage(), restliEx.getMessage());
    restliEx = wrappedExCapture.getAllValues().get(1);
    assertNotNull(restliEx);
    assertEquals(HttpStatus.S_500_INTERNAL_SERVER_ERROR, restliEx.getStatus());
    assertEquals(exFromSecondFilter.getMessage(), restliEx.getMessage());
    assertEquals(exFromSecondFilter, restliEx.getCause());
  }
View Full Code Here


                                             "\u0009\n\u000B\u000C" +
                                             "\r\u000E\u000F\u0010") ||
        !"I'm String".equals(union.getString()) ||
        record.getIntParameter() != 7 || !record.getStringParameter().equals("success"))
    {
      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR);
    }

    return Collections.emptyList();
  }
View Full Code Here

    }
    catch (ArrayIndexOutOfBoundsException e)
    {
      Greeting details = new Greeting().setMessage("Hello, Sorry for the mess");

      throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "error processing request", e)
              .setServiceErrorCode(42).setErrorDetails(details.data());
    }
    return null;
  }
View Full Code Here

  @RestMethod.Create
  public CreateResponse create(Greeting g)
  {
    if(g.hasTone() && g.getTone() == Tone.INSULTING)
    {
      RestLiServiceException notAcceptableException = new RestLiServiceException(HttpStatus.S_406_NOT_ACCEPTABLE,
                                                                          "I will not tolerate your insolence!");
      DataMap details = new DataMap();
      details.put("reason", "insultingGreeting");
      notAcceptableException.setErrorDetails(details);
      notAcceptableException.setServiceErrorCode(999);
      throw notAcceptableException;
    }
    else
    {
      return new CreateResponse(g.getId(), HttpStatus.S_201_CREATED);
View Full Code Here

      {
        batch.put(id, g);
      }
      else
      {
        errors.put(id, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
      }
    }

    return new BatchResult<String, Message>(batch, errors);
  }
View Full Code Here

    CompoundKey c2 = new CompoundKey().append("a", "a2").append("b", 2);
    CompoundKey c3 = new CompoundKey().append("a", "a3").append("b", 3);
    Map<CompoundKey, UpdateResponse> results = new HashMap<CompoundKey, UpdateResponse>();
    results.put(c1, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
    results.put(c2, new UpdateResponse(HttpStatus.S_202_ACCEPTED));
    RestLiServiceException restLiServiceException = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND);

    BatchUpdateResult<CompoundKey, Foo> batchUpdateResult = new BatchUpdateResult<CompoundKey, Foo>(results,
                                                                                                    Collections.singletonMap(c3, restLiServiceException));

    UpdateStatus updateStatus = new UpdateStatus().setStatus(202);
View Full Code Here

  void validateAuth(String auth)
  {
    if (auth==null || ! auth.equals("PLEASE"))
    {
      throw new RestLiServiceException(HttpStatus.S_401_UNAUTHORIZED, "Invalid auth token");
    }
  }
View Full Code Here

   * An example action throwing an exception.
   */
  @Action(name = "exceptionTest")
  public void exceptionTest()
  {
    throw new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR, "Test Exception");
  }
View Full Code Here

  {
    // For create construct a key based on the memberID and groupID in the membership
    // object
    if (!groupMembership.getId().hasMemberID() || !groupMembership.getId().hasGroupID())
    {
      throw new RestLiServiceException(S_400_BAD_REQUEST,
                                       "groupID and memberID fields must be set while creating a ComplexKeyGroupMembership.");
    }
    GroupMembershipKey groupMembershipKey = new GroupMembershipKey();
    groupMembershipKey.setMemberID(groupMembership.getId().getMemberID());
    groupMembershipKey.setGroupID(groupMembership.getId().getGroupID());
View Full Code Here

      {
        result.put(key, membership);
      }
      else
      {
        errors.put(key, new RestLiServiceException(HttpStatus.S_404_NOT_FOUND));
      }
    }
    return new BatchResult<ComplexResourceKey<GroupMembershipKey, GroupMembershipParam>, ComplexKeyGroupMembership>(result,
                                                                                                          errors);
  }
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.RestLiServiceException

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.