Search in sources :

Example 66 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestRestLiResponseHandler method buildUnstructuredDataRoutingResult.

private RoutingResult buildUnstructuredDataRoutingResult(RestRequest request) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
    Method method = FeedDownloadResource.class.getMethod("get", Long.class, UnstructuredDataWriter.class);
    ResourceModel model = RestLiTestHelper.buildResourceModel(FeedDownloadResource.class);
    ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(ResourceMethod.GET, method, InterfaceType.SYNC);
    model.addResourceMethodDescriptor(methodDescriptor);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    return new RoutingResult(context, methodDescriptor);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Method(java.lang.reflect.Method) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 67 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestRestLiResponseHandler method buildRoutingResultFinder.

private RoutingResult buildRoutingResultFinder(RestRequest request, Map<String, String> acceptHeaders) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
    Method method = ProjectionTestFixture.class.getMethod("find");
    ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(ResourceMethod.FINDER, method, InterfaceType.SYNC);
    model.addResourceMethodDescriptor(methodDescriptor);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, Collections.emptySet(), context);
    return new RoutingResult(context, methodDescriptor);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Method(java.lang.reflect.Method) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 68 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestRestLiResponseHandler method testBuildRestException.

@Test(dataProvider = TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "basicData")
@SuppressWarnings("deprecation")
void testBuildRestException(AcceptTypeData acceptTypeData, ProtocolVersion protocolVersion, String errorResponseHeaderName) throws Exception {
    final RestRequest request = buildRequest(acceptTypeData.acceptHeaders, protocolVersion);
    final RoutingResult routingResult = buildRoutingResult(request, acceptTypeData.acceptHeaders);
    Map<String, String> requestHeaders = new HashMap<>();
    requestHeaders.put(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, protocolVersion.toString());
    RestLiServiceException ex = new RestLiServiceException(HttpStatus.S_404_NOT_FOUND, "freeway not found").setServiceErrorCode(237);
    RestLiResponseData<?> responseData = _responseHandler.buildExceptionResponseData(routingResult, ex, requestHeaders, Collections.emptyList());
    RestLiResponse response = _responseHandler.buildPartialResponse(routingResult, responseData);
    checkResponse(response, 404, 2, // The response Content-Type should always be 'application/json'
    true, true, errorResponseHeaderName);
    DataMap dataMap = response.getDataMap();
    assertEquals(dataMap.getInteger("status"), Integer.valueOf(404));
    assertEquals(dataMap.getString("message"), "freeway not found");
    assertEquals(dataMap.getInteger("serviceErrorCode"), Integer.valueOf(237));
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) HashMap(java.util.HashMap) RestLiResponse(com.linkedin.restli.internal.server.response.RestLiResponse) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 69 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestRestLiResponseHandler method buildRoutingResult.

private RoutingResult buildRoutingResult(ResourceMethod resourceMethod, RestRequest request, Map<String, String> acceptHeaders, Set<String> customTypes) throws SecurityException, NoSuchMethodException, RestLiSyntaxException {
    Method method = ProjectionTestFixture.class.getMethod("batchGet", Set.class);
    ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
    ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForRestful(resourceMethod, method, InterfaceType.SYNC);
    model.addResourceMethodDescriptor(methodDescriptor);
    ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
    RestUtils.validateRequestHeadersAndUpdateResourceContext(acceptHeaders, customTypes, context);
    return new RoutingResult(context, methodDescriptor);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) ServerResourceContext(com.linkedin.restli.internal.server.ServerResourceContext) PathKeysImpl(com.linkedin.restli.internal.server.PathKeysImpl) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) RestLiTestHelper.buildResourceModel(com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Method(java.lang.reflect.Method) RequestContext(com.linkedin.r2.message.RequestContext) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl)

Example 70 with RoutingResult

use of com.linkedin.restli.internal.server.RoutingResult in project rest.li by linkedin.

the class TestCreateArgumentBuilder method testFailure.

@Test(dataProvider = "failureEntityData", dataProviderClass = RestLiArgumentBuilderTestHelper.class)
public void testFailure(String entity) {
    RestRequest request = RestLiArgumentBuilderTestHelper.getMockRequest(false, entity, 1);
    ResourceModel model = RestLiArgumentBuilderTestHelper.getMockResourceModel(MyComplexKey.class, null, false);
    ResourceMethodDescriptor descriptor = RestLiArgumentBuilderTestHelper.getMockResourceMethodDescriptor(model, 1, null);
    RoutingResult routingResult = RestLiArgumentBuilderTestHelper.getMockRoutingResult(descriptor, 1, null, 0);
    RestLiArgumentBuilder argumentBuilder = new CreateArgumentBuilder();
    try {
        argumentBuilder.extractRequestData(routingResult, request);
        fail("Expected RoutingException");
    } catch (RoutingException e) {
        assertTrue(e.getMessage().contains("Error parsing entity body"));
    }
    verify(request, model, descriptor, routingResult);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) ResourceMethodDescriptor(com.linkedin.restli.internal.server.model.ResourceMethodDescriptor) ResourceModel(com.linkedin.restli.internal.server.model.ResourceModel) Test(org.testng.annotations.Test)

Aggregations

RoutingResult (com.linkedin.restli.internal.server.RoutingResult)114 Test (org.testng.annotations.Test)89 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)72 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)71 RestRequest (com.linkedin.r2.message.rest.RestRequest)56 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)29 ResourceModel (com.linkedin.restli.internal.server.model.ResourceModel)28 RequestContext (com.linkedin.r2.message.RequestContext)24 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)20 URI (java.net.URI)20 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)19 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)18 RoutingException (com.linkedin.restli.server.RoutingException)18 HashMap (java.util.HashMap)17 DataMap (com.linkedin.data.DataMap)16 Foo (com.linkedin.pegasus.generator.examples.Foo)16 RestLiResponse (com.linkedin.restli.internal.server.response.RestLiResponse)14 Parameter (com.linkedin.restli.internal.server.model.Parameter)12 RestLiTestHelper.buildResourceModel (com.linkedin.restli.server.test.RestLiTestHelper.buildResourceModel)11 Callback (com.linkedin.common.callback.Callback)10