Search in sources :

Example 11 with FilterRequestContext

use of com.linkedin.restli.server.filter.FilterRequestContext in project rest.li by linkedin.

the class TestRestLiCallback method testOnSuccessWithFiltersExceptionFromSecondFilter.

@SuppressWarnings("unchecked")
@Test
public void testOnSuccessWithFiltersExceptionFromSecondFilter() throws Exception {
    // App stuff.
    String result = "foo";
    RestLiResponseData<GetResponseEnvelope> appResponseData = ResponseDataBuilderUtil.buildGetResponseData(HttpStatus.S_200_OK, null);
    // Filter stuff.
    ArgumentCaptor<RestLiServiceException> exFromFilterCapture = ArgumentCaptor.forClass(RestLiServiceException.class);
    final Map<String, String> headersFromFilter = Maps.newHashMap();
    headersFromFilter.put("Key", "Error from filter");
    RestLiServiceException exception = new RestLiServiceException(HttpStatus.S_500_INTERNAL_SERVER_ERROR);
    RestLiResponseData<?> filterResponseData = new RestLiResponseDataImpl<>(new GetResponseEnvelope(exception), headersFromFilter, Collections.emptyList());
    RestLiResponse partialFilterErrorResponse = new RestLiResponse.Builder().build();
    final Exception exFromFilter = new RuntimeException("Exception From Filter");
    // Common stuff.
    RestException finalRestException = new RestException(new RestResponseBuilder().build());
    // Setup.
    when((RestLiResponseData<GetResponseEnvelope>) _responseHandler.buildRestLiResponseData(_restRequest, _routingResult, result)).thenReturn(appResponseData);
    when(_restRequest.getHeaders()).thenReturn(null);
    when(_responseHandler.buildExceptionResponseData(eq(_routingResult), exFromFilterCapture.capture(), anyMap(), anyList())).thenReturn(filterResponseData);
    when(_responseHandler.buildPartialResponse(_routingResult, appResponseData)).thenReturn(partialFilterErrorResponse);
    // Mock filter behavior.
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            FilterRequestContext requestContext = (FilterRequestContext) args[0];
            FilterResponseContext responseContext = (FilterResponseContext) args[1];
            RestLiResponseData<GetResponseEnvelope> responseData = (RestLiResponseData<GetResponseEnvelope>) responseContext.getResponseData();
            // The second filter should be invoked with details of the exception thrown by the first
            // filter. Verify incoming data.
            assertEquals(responseData.getResponseEnvelope().getStatus(), HttpStatus.S_200_OK);
            assertNull(responseData.getResponseEnvelope().getRecord());
            assertTrue(responseData.getHeaders().isEmpty());
            // Modify data.
            setStatus(responseContext, HttpStatus.S_402_PAYMENT_REQUIRED);
            responseData.getHeaders().put("first-filter", "success");
            return CompletableFuture.completedFuture(null);
        }
    }).doThrow(exFromFilter).when(_filter).onResponse(eq(_filterRequestContext), any(FilterResponseContext.class));
    // invoke request filters so cursor is in correct place
    when(_filter.onRequest(any(FilterRequestContext.class))).thenReturn(CompletableFuture.completedFuture(null));
    _twoFilterChain.onRequest(_filterRequestContext, _filterResponseContextFactory);
    // Invoke.
    _twoFilterRestLiCallback.onSuccess(result);
    // Verify.
    verify(_responseHandler).buildPartialResponse(_routingResult, appResponseData);
    verify(_responseHandler).buildRestLiResponseData(_restRequest, _routingResult, result);
    verify(_responseHandler).buildPartialResponse(_routingResult, appResponseData);
    ArgumentCaptor<RestLiResponseException> partialRestResponseExceptionCaptor = ArgumentCaptor.forClass(RestLiResponseException.class);
    verify(_callback).onError(partialRestResponseExceptionCaptor.capture());
    verifyNoMoreInteractions(_responseHandler, _callback);
    RestLiResponseException restLiResponseException = partialRestResponseExceptionCaptor.getValue();
    assertTrue(restLiResponseException.getCause() instanceof RestLiServiceException);
    RestLiServiceException restliEx1 = (RestLiServiceException) restLiResponseException.getCause();
    assertNotNull(restliEx1);
    assertEquals(HttpStatus.S_500_INTERNAL_SERVER_ERROR, restliEx1.getStatus());
    assertEquals(exFromFilter.getMessage(), restliEx1.getMessage());
    assertEquals(exFromFilter, restliEx1.getCause());
    Map<String, String> expectedHeaders = buildErrorHeaders();
    expectedHeaders.put("first-filter", "success");
    assertNotNull(appResponseData);
    assertEquals(HttpStatus.S_500_INTERNAL_SERVER_ERROR, appResponseData.getResponseEnvelope().getStatus());
    assertEquals(appResponseData.getHeaders(), expectedHeaders);
    assertNull(appResponseData.getResponseEnvelope().getRecord());
}
Also used : RestException(com.linkedin.r2.message.rest.RestException) RestResponseBuilder(com.linkedin.r2.message.rest.RestResponseBuilder) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RoutingException(com.linkedin.restli.server.RoutingException) RestException(com.linkedin.r2.message.rest.RestException) Answer(org.mockito.stubbing.Answer) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) FilterResponseContext(com.linkedin.restli.server.filter.FilterResponseContext) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 12 with FilterRequestContext

use of com.linkedin.restli.server.filter.FilterRequestContext in project rest.li by linkedin.

the class TestRestLiMethodInvocation method checkInvocation.

private void checkInvocation(Object resource, RequestContext requestContext, ResourceMethodDescriptor resourceMethodDescriptor, ResourceMethodConfig resourceMethodConfig, String httpMethod, ProtocolVersion version, String uri, String entityBody, MutablePathKeys pathkeys, final Callback<RestResponse> callback, final boolean isDebugMode, final boolean expectRoutingException, final RestLiAttachmentReader expectedRequestAttachments, final RestLiResponseAttachments expectedResponseAttachments) throws Exception {
    assertNotNull(resource);
    assertNotNull(resourceMethodDescriptor);
    try {
        EasyMock.replay(resource);
        RestRequestBuilder builder = new RestRequestBuilder(new URI(uri)).setMethod(httpMethod).addHeaderValue("Accept", "application/json").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
        if (entityBody != null) {
            builder.setEntity(entityBody.getBytes(Data.UTF_8_CHARSET));
        }
        if (expectedResponseAttachments != null) {
            builder.addHeaderValue(RestConstants.HEADER_ACCEPT, RestConstants.HEADER_VALUE_MULTIPART_RELATED);
        }
        RestRequest request = builder.build();
        if (isDebugMode) {
            requestContext.putLocalAttr(RestLiMethodInvoker.ATTRIBUTE_PROMISE_LISTENER, new PromiseListener<Object>() {

                @Override
                public void onResolved(Promise<Object> promise) {
                    // PromiseListener is invoked with a task.
                    if (promise instanceof Task) {
                        requestContext.putLocalAttr(ATTRIBUTE_PARSEQ_TRACE, ((Task<?>) promise).getTrace());
                    }
                }
            });
        }
        final ServerResourceContext resourceContext = new ResourceContextImpl(pathkeys, request, requestContext);
        resourceContext.setRequestAttachmentReader(expectedRequestAttachments);
        if (expectedResponseAttachments != null) {
            resourceContext.setResponseAttachments(expectedResponseAttachments);
        }
        RoutingResult routingResult = new RoutingResult(resourceContext, resourceMethodDescriptor, resourceMethodConfig);
        RestLiArgumentBuilder argumentBuilder = _methodAdapterProvider.getArgumentBuilder(resourceMethodDescriptor.getType());
        RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, entityBody != null && !entityBody.isEmpty() ? DataMapUtils.readMapWithExceptions(request) : null);
        FilterRequestContext filterContext = new FilterRequestContextInternalImpl(routingResult.getContext(), resourceMethodDescriptor, requestData);
        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch expectedRoutingExceptionLatch = new CountDownLatch(1);
        RestLiResponseHandler restLiResponseHandler = new RestLiResponseHandler(_methodAdapterProvider, _errorResponseBuilder);
        Callback<RestLiResponse> executionCallback = new Callback<RestLiResponse>() {

            @Override
            public void onError(Throwable e) {
                if (e.getCause() != null && e.getCause().getCause() instanceof RoutingException) {
                    expectedRoutingExceptionLatch.countDown();
                }
                if (callback != null) {
                    callback.onError(e);
                }
                Assert.assertEquals(resourceContext.getRequestAttachmentReader(), expectedRequestAttachments);
                Assert.assertEquals(resourceContext.getResponseAttachments(), expectedResponseAttachments);
                latch.countDown();
            }

            @Override
            public void onSuccess(final RestLiResponse result) {
                if (callback != null) {
                    callback.onSuccess(ResponseUtils.buildResponse(routingResult, result));
                }
                Assert.assertEquals(resourceContext.getResponseAttachments(), expectedResponseAttachments);
                latch.countDown();
            }
        };
        FilterChainDispatcher filterChainDispatcher = new FilterChainDispatcherImpl(routingResult, _invoker, argumentBuilder);
        FilterChainCallback filterChainCallback = new FilterChainCallbackImpl(routingResult, restLiResponseHandler, executionCallback, _errorResponseBuilder);
        final RestLiCallback outerCallback = new RestLiCallback(filterContext, new RestLiFilterResponseContextFactory(request, routingResult, restLiResponseHandler), new RestLiFilterChain(null, filterChainDispatcher, filterChainCallback));
        RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), Collections.emptySet(), routingResult.getContext());
        _invoker.invoke(requestData, routingResult, argumentBuilder, outerCallback);
        try {
            latch.await();
            if (expectRoutingException) {
                expectedRoutingExceptionLatch.await();
            }
        } catch (InterruptedException e) {
        // Ignore
        }
        EasyMock.verify(resource);
        Assert.assertEquals((routingResult.getContext()).getResponseMimeType(), "application/json");
    } catch (RestLiSyntaxException e) {
        throw new RoutingException("syntax exception", 400);
    } finally {
        EasyMock.reset(resource);
        EasyMock.makeThreadSafe(resource, true);
    }
}
Also used : FilterRequestContextInternalImpl(com.linkedin.restli.internal.server.filter.FilterRequestContextInternalImpl) RoutingException(com.linkedin.restli.server.RoutingException) Task(com.linkedin.parseq.Task) BaseTask(com.linkedin.parseq.BaseTask) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) FilterChainDispatcherImpl(com.linkedin.restli.internal.server.filter.FilterChainDispatcherImpl) URI(java.net.URI) RestLiFilterChain(com.linkedin.restli.internal.server.filter.RestLiFilterChain) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) FilterChainDispatcher(com.linkedin.restli.internal.server.filter.FilterChainDispatcher) RestLiResponseHandler(com.linkedin.restli.internal.server.response.RestLiResponseHandler) FilterChainCallbackImpl(com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) RestLiResponse(com.linkedin.restli.internal.server.response.RestLiResponse) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) RestLiFilterResponseContextFactory(com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory) RestRequest(com.linkedin.r2.message.rest.RestRequest) Callback(com.linkedin.common.callback.Callback) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData)

Example 13 with FilterRequestContext

use of com.linkedin.restli.server.filter.FilterRequestContext in project rest.li by linkedin.

the class TestRestLiMethodInvocation method testInvokerWithFilters.

@Test(dataProvider = "provideFilterConfig")
public void testInvokerWithFilters(final boolean throwExceptionFromFirstFilter) throws Exception {
    RestLiArgumentBuilder mockArgumentBuilder = createMock(RestLiArgumentBuilder.class);
    Filter mockFilter = createMock(Filter.class);
    @SuppressWarnings("unchecked") Callback<Object> mockCallback = createMock(Callback.class);
    FilterRequestContext mockFilterContext = createMock(FilterRequestContext.class);
    RestLiRequestData requestData = new RestLiRequestDataImpl.Builder().key("Key").build();
    RestLiMethodInvoker invokerWithFilters = new RestLiMethodInvoker(_resourceFactory, _engine, ErrorResponseBuilder.DEFAULT_INTERNAL_ERROR_MESSAGE);
    Map<String, ResourceModel> resourceModelMap = buildResourceModels(StatusCollectionResource.class, LocationResource.class, DiscoveredItemsResource.class);
    ResourceModel statusResourceModel = resourceModelMap.get("/statuses");
    ResourceMethodDescriptor resourceMethodDescriptor = statusResourceModel.findMethod(ResourceMethod.GET);
    final StatusCollectionResource resource = getMockResource(StatusCollectionResource.class);
    RestRequestBuilder builder = new RestRequestBuilder(new URI("/statuses/1")).setMethod("GET").addHeaderValue("Accept", "application/json").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, AllProtocolVersions.LATEST_PROTOCOL_VERSION.toString());
    RestRequest request = builder.build();
    RoutingResult routingResult = new RoutingResult(new ResourceContextImpl(buildPathKeys("statusID", 1L), request, new RequestContext()), resourceMethodDescriptor);
    expectLastCall();
    FilterChainDispatcher filterChainDispatcher = new FilterChainDispatcher() {

        @Override
        public void onRequestSuccess(RestLiRequestData requestData, RestLiCallback restLiCallback) {
            // only invoke if filter chain's requests were successful
            invokerWithFilters.invoke(requestData, routingResult, mockArgumentBuilder, restLiCallback);
        }
    };
    FilterChainCallback filterChainCallback = new FilterChainCallback() {

        @Override
        public void onResponseSuccess(RestLiResponseData<?> responseData) {
        // unused
        }

        @Override
        public void onError(Throwable th, RestLiResponseData<?> responseData) {
        // unused
        }
    };
    final Exception exFromFilter = new RuntimeException("Exception from filter!");
    if (throwExceptionFromFirstFilter) {
        mockFilter.onRequest(eq(mockFilterContext));
        expectLastCall().andThrow(exFromFilter);
        mockCallback.onError(eq(exFromFilter));
    } else {
        expect(mockFilterContext.getRequestData()).andReturn(requestData).times(3);
        mockFilter.onRequest(eq(mockFilterContext));
        expectLastCall().andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                FilterRequestContext filterContext = (FilterRequestContext) getCurrentArguments()[0];
                RestLiRequestData data = filterContext.getRequestData();
                // Verify incoming data.
                assertEquals(data.getKey(), "Key");
                // Update data.
                data.setKey("Key-Filter1");
                return CompletableFuture.completedFuture(null);
            }
        }).andAnswer(new IAnswer<Object>() {

            @Override
            public Object answer() throws Throwable {
                FilterRequestContext filterContext = (FilterRequestContext) getCurrentArguments()[0];
                RestLiRequestData data = filterContext.getRequestData();
                // Verify incoming data.
                assertEquals(data.getKey(), "Key-Filter1");
                // Update data.
                data.setKey("Key-Filter2");
                return CompletableFuture.completedFuture(null);
            }
        });
        Long[] argsArray = { 1L };
        expect(mockArgumentBuilder.buildArguments(requestData, routingResult)).andReturn(argsArray);
        expect(resource.get(eq(1L))).andReturn(null).once();
        mockCallback.onSuccess(eq(null));
    }
    replay(resource, mockArgumentBuilder, mockFilterContext, mockFilter, mockCallback);
    RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), Collections.emptySet(), routingResult.getContext());
    RestLiFilterChain filterChain = new RestLiFilterChain(Arrays.asList(mockFilter, mockFilter), filterChainDispatcher, filterChainCallback);
    filterChain.onRequest(mockFilterContext, new RestLiFilterResponseContextFactory(request, routingResult, new RestLiResponseHandler(_methodAdapterProvider, _errorResponseBuilder)));
    verifyRecording(mockArgumentBuilder, mockFilterContext, mockFilter);
    if (throwExceptionFromFirstFilter) {
        assertEquals(requestData.getKey(), "Key");
    } else {
        assertEquals(requestData.getKey(), "Key-Filter2");
        verify(resource);
    }
    EasyMock.reset(resource);
    EasyMock.makeThreadSafe(resource, true);
}
Also used : RestLiMethodInvoker(com.linkedin.restli.internal.server.RestLiMethodInvoker) RestLiMethodConfigBuilder(com.linkedin.restli.server.config.RestLiMethodConfigBuilder) EngineBuilder(com.linkedin.parseq.EngineBuilder) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) ErrorResponseBuilder(com.linkedin.restli.internal.server.response.ErrorResponseBuilder) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ByteString(com.linkedin.data.ByteString) CustomString(com.linkedin.restli.server.custom.types.CustomString) URI(java.net.URI) RestLiFilterChain(com.linkedin.restli.internal.server.filter.RestLiFilterChain) RoutingResult(com.linkedin.restli.internal.server.RoutingResult) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) FilterChainDispatcher(com.linkedin.restli.internal.server.filter.FilterChainDispatcher) RestLiResponseHandler(com.linkedin.restli.internal.server.response.RestLiResponseHandler) RestLiCallback(com.linkedin.restli.internal.server.RestLiCallback) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) TaskStatusCollectionResource(com.linkedin.restli.server.twitter.TaskStatusCollectionResource) StatusCollectionResource(com.linkedin.restli.server.twitter.StatusCollectionResource) AsyncStatusCollectionResource(com.linkedin.restli.server.twitter.AsyncStatusCollectionResource) CustomStatusCollectionResource(com.linkedin.restli.server.twitter.CustomStatusCollectionResource) PromiseStatusCollectionResource(com.linkedin.restli.server.twitter.PromiseStatusCollectionResource) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) RestLiResponseData(com.linkedin.restli.server.RestLiResponseData) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) RestException(com.linkedin.r2.message.rest.RestException) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) RoutingException(com.linkedin.restli.server.RoutingException) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) IAnswer(org.easymock.IAnswer) RestLiFilterResponseContextFactory(com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory) RestRequest(com.linkedin.r2.message.rest.RestRequest) Filter(com.linkedin.restli.server.filter.Filter) CustomLong(com.linkedin.restli.server.custom.types.CustomLong) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Example 14 with FilterRequestContext

use of com.linkedin.restli.server.filter.FilterRequestContext in project rest.li by linkedin.

the class BaseRestLiServer method handleResourceRequest.

/**
 * Handles a request by building arguments and invoking the Rest.li resource method. All the arguments are processed
 * by the filters in the filter chain before invoking the resource method. The result is also processed by the
 * filters after invoking the resource method.
 *
 * @param request   The request to handle. Only the URI, method, and the headers can be accessed from this request. The
 *                  body should have already been parse to a DataMap.
 * @param callback
 */
protected final void handleResourceRequest(Request request, RoutingResult routingResult, DataMap entityDataMap, Callback<RestLiResponse> callback) {
    ServerResourceContext context = routingResult.getContext();
    ResourceMethodDescriptor method = routingResult.getResourceMethod();
    FilterRequestContext filterContext;
    RestLiArgumentBuilder argumentBuilder;
    try {
        argumentBuilder = lookupArgumentBuilder(method);
        // Unstructured data is not available in the Rest.Li filters
        RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, entityDataMap);
        filterContext = new FilterRequestContextInternalImpl(context, method, requestData);
    } catch (Exception e) {
        // would not trigger response filters because request filters haven't run yet
        callback.onError(buildPreRoutingError(e, request));
        return;
    }
    RestLiFilterResponseContextFactory filterResponseContextFactory = new RestLiFilterResponseContextFactory(request, routingResult, _responseHandler);
    FilterChainCallback filterChainCallback = new FilterChainCallbackImpl(routingResult, _responseHandler, callback, _errorResponseBuilder);
    FilterChainDispatcher filterChainDispatcher = new FilterChainDispatcherImpl(routingResult, _methodInvoker, argumentBuilder);
    RestLiFilterChain filterChain = new RestLiFilterChain(_filters, filterChainDispatcher, filterChainCallback);
    TimingContextUtil.beginTiming(routingResult.getContext().getRawRequestContext(), FrameworkTimingKeys.SERVER_REQUEST_RESTLI_FILTER_CHAIN.key());
    filterChain.onRequest(filterContext, filterResponseContextFactory);
}
Also used : FilterRequestContextInternalImpl(com.linkedin.restli.internal.server.filter.FilterRequestContextInternalImpl) FilterChainDispatcherImpl(com.linkedin.restli.internal.server.filter.FilterChainDispatcherImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) RestLiResponseException(com.linkedin.restli.internal.server.response.RestLiResponseException) RestLiFilterChain(com.linkedin.restli.internal.server.filter.RestLiFilterChain) FilterChainCallback(com.linkedin.restli.internal.server.filter.FilterChainCallback) RestLiFilterResponseContextFactory(com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory) FilterChainDispatcher(com.linkedin.restli.internal.server.filter.FilterChainDispatcher) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) FilterChainCallbackImpl(com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext)

Example 15 with FilterRequestContext

use of com.linkedin.restli.server.filter.FilterRequestContext in project rest.li by linkedin.

the class TestFilterRequestContextInternalImpl method testFilterScratchpad.

@Test
public void testFilterScratchpad() {
    FilterRequestContext filterContext = new FilterRequestContextInternalImpl(context, resourceMethod, null);
    Object spValue = new Object();
    String spKey = UUID.randomUUID().toString();
    filterContext.getFilterScratchpad().put(spKey, spValue);
    assertSame(filterContext.getFilterScratchpad().get(spKey), spValue);
}
Also used : FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)21 Test (org.testng.annotations.Test)17 BeforeTest (org.testng.annotations.BeforeTest)16 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)14 RoutingException (com.linkedin.restli.server.RoutingException)12 FilterResponseContext (com.linkedin.restli.server.filter.FilterResponseContext)12 RestException (com.linkedin.r2.message.rest.RestException)11 InvocationOnMock (org.mockito.invocation.InvocationOnMock)11 RestLiResponseData (com.linkedin.restli.server.RestLiResponseData)9 RecordTemplate (com.linkedin.data.template.RecordTemplate)7 Answer (org.mockito.stubbing.Answer)6 RestResponseBuilder (com.linkedin.r2.message.rest.RestResponseBuilder)4 DataMap (com.linkedin.data.DataMap)3 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)3 FilterChainDispatcher (com.linkedin.restli.internal.server.filter.FilterChainDispatcher)3 RestLiFilterChain (com.linkedin.restli.internal.server.filter.RestLiFilterChain)3 RestLiFilterResponseContextFactory (com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory)3 RestLiArgumentBuilder (com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder)3 RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)3 RestLiResponseAttachments (com.linkedin.restli.server.RestLiResponseAttachments)3