Package com.linkedin.restli.server.filter

Examples of com.linkedin.restli.server.filter.FilterResponseContext


        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable
        {
          Object[] args = invocation.getArguments();
          FilterRequestContext requestContext = (FilterRequestContext) args[0];
          FilterResponseContext responseContext = (FilterResponseContext) args[1];
          // Verify the scratch pad value.
          assertTrue(requestContext.getFilterScratchpad().get(spKey) == spValue);
          RecordTemplate entity = responseContext.getResponseData().getEntityResponse();
          if (entity != null && requestContext.getMethodType() == ResourceMethod.GET
              && responseContext.getHttpStatus() == HttpStatus.S_200_OK)
          {
            Greeting greeting = new Greeting(entity.data());
            if (greeting.hasTone())
            {
              greeting.setTone(mapToneForOutgoingResponse(greeting.getTone()));
              responseContext.getResponseData().setEntityResponse(greeting);
            }
          }
          ErrorResponse errorResponse = responseContext.getResponseData().getErrorResponse();
          if (errorResponse != null && requestContext.getMethodType() == ResourceMethod.CREATE
              && responseContext.getHttpStatus() == REQ_FILTER_ERROR_STATUS)
          {
            errorResponse.setMessage(RESP_FILTER_ERROR_MESSAGE);
            responseContext.setHttpStatus(RESP_FILTER_ERROR_STATUS);
          }
          return null;
        }
      }).when(_responseFilter).onResponse(any(FilterRequestContext.class), any(FilterResponseContext.class));
      respFilters = Arrays.asList(_responseFilter);
View Full Code Here


    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // Verify incoming data.
        assertEquals(HttpStatus.S_200_OK, context.getHttpStatus());
        assertEquals(headersFromApp, context.getResponseHeaders());
        assertEquals(entityFromApp, context.getResponseData().getEntityResponse());
        // Modify data in filter.
        context.setHttpStatus(HttpStatus.S_400_BAD_REQUEST);
        context.getResponseData().setEntityResponse(entityFromFilter1);
        context.getResponseHeaders().clear();
        return null;
      }
    }).doAnswer(new Answer<Object>()
    // Mock the behavior of the first filter.
    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // Verify incoming data.
        assertEquals(HttpStatus.S_400_BAD_REQUEST, context.getHttpStatus());
        assertTrue(context.getResponseHeaders().isEmpty());
        assertEquals(context.getResponseData().getEntityResponse(), entityFromFilter1);
        // Modify data in filter.
        context.setHttpStatus(HttpStatus.S_403_FORBIDDEN);
        context.getResponseData().setEntityResponse(entityFromFilter2);
        context.getResponseHeaders().putAll(headersFromFilters);
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    RestResponse restResponse = new RestResponseBuilder().build();
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // The second filter should be invoked with details of the exception thrown by the first
        // filter.
        assertEquals(context.getHttpStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR);
        assertNull(context.getResponseData().getEntityResponse());
        assertEquals(context.getResponseHeaders(), headersFromFilter);
        assertEquals(context.getResponseData().getErrorResponse(), errorResponseFromFilter);

        // Modify data.
        context.setHttpStatus(HttpStatus.S_402_PAYMENT_REQUIRED);
        // The second filter handles the exception thrown by the first filter (i.e.) sets an entity
        // response in the response data.
        context.getResponseData().setEntityResponse(entityFromFilter);
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    // Invoke.
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // The second filter should be invoked with details of the exception thrown by the first
        // filter.
        assertEquals(context.getHttpStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR);
        assertNull(context.getResponseData().getEntityResponse());
        assertEquals(context.getResponseHeaders(), headersFromFilter);

        // Modify data.
        context.setHttpStatus(HttpStatus.S_402_PAYMENT_REQUIRED);
        // The second filter handles the exception thrown by the first filter (i.e.) does not throw
        // another exception.
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // The second filter should be invoked with details of the exception thrown by the first
        // filter. Verify incoming data.
        assertEquals(context.getHttpStatus(), HttpStatus.S_200_OK);
        assertNull(context.getResponseData().getEntityResponse());
        assertTrue(context.getResponseHeaders().isEmpty());
        // Modify data.
        context.setHttpStatus(HttpStatus.S_402_PAYMENT_REQUIRED);
        return null;
      }
    }).doThrow(exFromFilter).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    // Invoke.
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // Verify incoming data.
        assertEquals(HttpStatus.S_404_NOT_FOUND, context.getHttpStatus());
        assertEquals(headersFromApp, context.getResponseHeaders());
        assertNull(context.getResponseData().getEntityResponse());
        // Modify data in filter.
        context.setHttpStatus(HttpStatus.S_400_BAD_REQUEST);
        context.getResponseHeaders().clear();
        return null;
      }
    }).doAnswer(new Answer<Object>()
    // Mock the behavior of the second filter.
    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // Verify incoming data.
        assertEquals(HttpStatus.S_400_BAD_REQUEST, context.getHttpStatus());
        assertTrue(context.getResponseHeaders().isEmpty());
        assertNull(context.getResponseData().getEntityResponse());
        // Modify data in filter.
        context.setHttpStatus(HttpStatus.S_403_FORBIDDEN);
        context.getResponseHeaders().putAll(headersFromFilter);
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));
    RestException restException = new RestException(new RestResponseBuilder().build());
    when(_responseHandler.buildRestException(exFromApp, partialResponse)).thenReturn(restException);
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // Verify incoming data.
        assertEquals(HttpStatus.S_404_NOT_FOUND, context.getHttpStatus());
        assertEquals(headersFromApp, context.getResponseHeaders());
        assertNull(context.getResponseData().getEntityResponse());
        // Modify data in filter.
        context.setHttpStatus(HttpStatus.S_400_BAD_REQUEST);
        context.getResponseHeaders().clear();
        return null;
      }
    }).doAnswer(new Answer<Object>()
    // Mock the behavior of the second filter.
    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // Verify incoming data.
        assertEquals(HttpStatus.S_400_BAD_REQUEST, context.getHttpStatus());
        assertTrue(context.getResponseHeaders().isEmpty());
        assertNull(context.getResponseData().getEntityResponse());
        // Modify data in filter.
        context.setHttpStatus(HttpStatus.S_403_FORBIDDEN);
        context.getResponseData().setEntityResponse(entityFromFilter);
        context.getResponseHeaders().putAll(headersFromFilter);
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    RestResponse restResponse = new RestResponseBuilder().build();
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // The second filter should be invoked with details of the exception thrown by the first
        // filter. Verify incoming data.
        assertEquals(context.getHttpStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR);
        assertNull(context.getResponseData().getEntityResponse());
        assertTrue(context.getResponseHeaders().isEmpty());
        assertTrue(context.getResponseData().isErrorResponse());

        // Modify data.
        context.setHttpStatus(HttpStatus.S_402_PAYMENT_REQUIRED);
        // The second filter does not handle the exception thrown by the first filter (i.e.) the
        // response data still has the error response corresponding to the exception from the first
        // filter.
        return null;
      }
View Full Code Here

    {
      @Override
      public Object answer(InvocationOnMock invocation) throws Throwable
      {
        Object[] args = invocation.getArguments();
        FilterResponseContext context = (FilterResponseContext) args[1];
        // The second filter should be invoked with details of the exception thrown by the first
        // filter. Verify incoming data.
        assertEquals(context.getHttpStatus(), HttpStatus.S_500_INTERNAL_SERVER_ERROR);
        assertNull(context.getResponseData().getEntityResponse());
        assertTrue(context.getResponseHeaders().isEmpty());
        assertTrue(context.getResponseData().isErrorResponse());

        // Modify data.
        context.setHttpStatus(HttpStatus.S_402_PAYMENT_REQUIRED);
        // The second filter does handles the exception thrown by the first filter (i.e.) clears the
        // error response corresponding to the exception from the first
        // filter.
        context.getResponseData().setEntityResponse(entityFromFilter2);
        return null;
      }
    }).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));

    // Invoke.
View Full Code Here

    {
      @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));
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.filter.FilterResponseContext

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.