Search in sources :

Example 11 with RestLiArgumentBuilder

use of com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder in project rest.li by linkedin.

the class TestRestLiMethodInvocation method checkAsyncInvocation.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void checkAsyncInvocation(BaseResource resource, RestLiCallback callback, ResourceMethodDescriptor methodDescriptor, String httpMethod, ProtocolVersion version, String uri, String entityBody, MutablePathKeys pathkeys, boolean isDebugMode) throws Exception {
    try {
        RestRequestBuilder builder = new RestRequestBuilder(new URI(uri)).setMethod(httpMethod).addHeaderValue("Accept", "application/x-pson").setHeader(RestConstants.HEADER_RESTLI_PROTOCOL_VERSION, version.toString());
        if (entityBody != null) {
            builder.setEntity(entityBody.getBytes(Data.UTF_8_CHARSET));
        }
        RestRequest request = builder.build();
        RoutingResult routingResult = new RoutingResult(new ResourceContextImpl(pathkeys, request, new RequestContext()), methodDescriptor);
        RestLiArgumentBuilder argumentBuilder = _methodAdapterProvider.getArgumentBuilder(methodDescriptor.getType());
        RestLiRequestData requestData = argumentBuilder.extractRequestData(routingResult, entityBody != null ? DataMapUtils.readMapWithExceptions(request) : null);
        RestUtils.validateRequestHeadersAndUpdateResourceContext(request.getHeaders(), Collections.emptySet(), routingResult.getContext());
        _invoker.invoke(requestData, routingResult, argumentBuilder, callback);
        EasyMock.verify(resource);
        EasyMock.verify(callback);
        Assert.assertEquals((routingResult.getContext()).getResponseMimeType(), "application/x-pson");
    } catch (RestLiSyntaxException e) {
        throw new RoutingException("syntax exception", 400);
    } finally {
        EasyMock.reset(callback, resource);
        callback.onSuccess(EasyMock.anyObject());
        EasyMock.expectLastCall().once();
        EasyMock.replay(callback);
    }
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) RoutingException(com.linkedin.restli.server.RoutingException) RestRequest(com.linkedin.r2.message.rest.RestRequest) RestLiSyntaxException(com.linkedin.restli.internal.server.util.RestLiSyntaxException) RestRequestBuilder(com.linkedin.r2.message.rest.RestRequestBuilder) FilterRequestContext(com.linkedin.restli.server.filter.FilterRequestContext) RequestContext(com.linkedin.r2.message.RequestContext) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) URI(java.net.URI) ResourceContextImpl(com.linkedin.restli.internal.server.ResourceContextImpl) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData)

Example 12 with RestLiArgumentBuilder

use of com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder in project rest.li by linkedin.

the class DefaultMethodAdapterProvider method buildAdapterRegistry.

private Map<ResourceMethod, RestLiArgumentBuilder> buildAdapterRegistry() {
    Map<ResourceMethod, RestLiArgumentBuilder> result = new HashMap<>(ResourceMethod.values().length);
    result.put(ResourceMethod.GET, new GetArgumentBuilder());
    result.put(ResourceMethod.BATCH_GET, new BatchGetArgumentBuilder());
    result.put(ResourceMethod.FINDER, new CollectionArgumentBuilder());
    result.put(ResourceMethod.BATCH_FINDER, new CollectionArgumentBuilder());
    result.put(ResourceMethod.CREATE, new CreateArgumentBuilder());
    result.put(ResourceMethod.PARTIAL_UPDATE, new PatchArgumentBuilder());
    result.put(ResourceMethod.UPDATE, new UpdateArgumentBuilder());
    result.put(ResourceMethod.DELETE, new GetArgumentBuilder());
    result.put(ResourceMethod.ACTION, new ActionArgumentBuilder());
    result.put(ResourceMethod.BATCH_UPDATE, new BatchUpdateArgumentBuilder());
    result.put(ResourceMethod.BATCH_PARTIAL_UPDATE, new BatchPatchArgumentBuilder());
    result.put(ResourceMethod.BATCH_CREATE, new BatchCreateArgumentBuilder());
    result.put(ResourceMethod.BATCH_DELETE, new BatchDeleteArgumentBuilder());
    result.put(ResourceMethod.GET_ALL, new CollectionArgumentBuilder());
    return Collections.unmodifiableMap(result);
}
Also used : PatchArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.PatchArgumentBuilder) BatchPatchArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchPatchArgumentBuilder) CreateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.CreateArgumentBuilder) BatchCreateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchCreateArgumentBuilder) HashMap(java.util.HashMap) BatchPatchArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchPatchArgumentBuilder) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) UpdateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.UpdateArgumentBuilder) BatchUpdateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchUpdateArgumentBuilder) BatchGetArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchGetArgumentBuilder) BatchGetArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchGetArgumentBuilder) GetArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.GetArgumentBuilder) BatchCreateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchCreateArgumentBuilder) BatchDeleteArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchDeleteArgumentBuilder) ActionArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.ActionArgumentBuilder) ResourceMethod(com.linkedin.restli.common.ResourceMethod) CollectionArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.CollectionArgumentBuilder) BatchUpdateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.BatchUpdateArgumentBuilder)

Aggregations

RestLiArgumentBuilder (com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder)12 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)7 RestLiRequestData (com.linkedin.restli.server.RestLiRequestData)6 FilterRequestContext (com.linkedin.restli.server.filter.FilterRequestContext)6 RestRequest (com.linkedin.r2.message.rest.RestRequest)5 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)5 ResourceContextImpl (com.linkedin.restli.internal.server.ResourceContextImpl)5 FilterChainCallback (com.linkedin.restli.internal.server.filter.FilterChainCallback)5 RestLiFilterChain (com.linkedin.restli.internal.server.filter.RestLiFilterChain)5 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)5 RestLiSyntaxException (com.linkedin.restli.internal.server.util.RestLiSyntaxException)5 RoutingException (com.linkedin.restli.server.RoutingException)5 URI (java.net.URI)5 RequestContext (com.linkedin.r2.message.RequestContext)4 ServerResourceContext (com.linkedin.restli.internal.server.ServerResourceContext)4 FilterChainCallbackImpl (com.linkedin.restli.internal.server.filter.FilterChainCallbackImpl)4 FilterRequestContextInternalImpl (com.linkedin.restli.internal.server.filter.FilterRequestContextInternalImpl)4 RestLiFilterResponseContextFactory (com.linkedin.restli.internal.server.filter.RestLiFilterResponseContextFactory)4 ResourceMethod (com.linkedin.restli.common.ResourceMethod)3 RestLiCallback (com.linkedin.restli.internal.server.RestLiCallback)3