Search in sources :

Example 1 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class MethodAdapterRegistry method buildResponseBuilders.

private Map<ResourceMethod, RestLiResponseBuilder> buildResponseBuilders(ErrorResponseBuilder errorResponseBuilder) {
    Map<ResourceMethod, RestLiResponseBuilder> result = new HashMap<ResourceMethod, RestLiResponseBuilder>(ResourceMethod.values().length);
    result.put(ResourceMethod.GET, new GetResponseBuilder());
    result.put(ResourceMethod.BATCH_GET, new BatchGetResponseBuilder(errorResponseBuilder));
    result.put(ResourceMethod.FINDER, new CollectionResponseBuilder());
    result.put(ResourceMethod.CREATE, new CreateResponseBuilder());
    result.put(ResourceMethod.PARTIAL_UPDATE, new UpdateResponseBuilder());
    result.put(ResourceMethod.UPDATE, new UpdateResponseBuilder());
    result.put(ResourceMethod.DELETE, new UpdateResponseBuilder());
    result.put(ResourceMethod.ACTION, new ActionResponseBuilder());
    result.put(ResourceMethod.BATCH_UPDATE, new BatchUpdateResponseBuilder(errorResponseBuilder));
    result.put(ResourceMethod.BATCH_PARTIAL_UPDATE, new BatchUpdateResponseBuilder(errorResponseBuilder));
    result.put(ResourceMethod.BATCH_CREATE, new BatchCreateResponseBuilder(errorResponseBuilder));
    result.put(ResourceMethod.BATCH_DELETE, new BatchUpdateResponseBuilder(errorResponseBuilder));
    result.put(ResourceMethod.GET_ALL, new CollectionResponseBuilder());
    return Collections.unmodifiableMap(result);
}
Also used : BatchGetResponseBuilder(com.linkedin.restli.internal.server.response.BatchGetResponseBuilder) ActionResponseBuilder(com.linkedin.restli.internal.server.response.ActionResponseBuilder) HashMap(java.util.HashMap) BatchUpdateResponseBuilder(com.linkedin.restli.internal.server.response.BatchUpdateResponseBuilder) UpdateResponseBuilder(com.linkedin.restli.internal.server.response.UpdateResponseBuilder) BatchUpdateResponseBuilder(com.linkedin.restli.internal.server.response.BatchUpdateResponseBuilder) CollectionResponseBuilder(com.linkedin.restli.internal.server.response.CollectionResponseBuilder) BatchCreateResponseBuilder(com.linkedin.restli.internal.server.response.BatchCreateResponseBuilder) CreateResponseBuilder(com.linkedin.restli.internal.server.response.CreateResponseBuilder) BatchCreateResponseBuilder(com.linkedin.restli.internal.server.response.BatchCreateResponseBuilder) BatchGetResponseBuilder(com.linkedin.restli.internal.server.response.BatchGetResponseBuilder) GetResponseBuilder(com.linkedin.restli.internal.server.response.GetResponseBuilder) RestLiResponseBuilder(com.linkedin.restli.internal.server.response.RestLiResponseBuilder) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 2 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class MethodAdapterRegistry method buildAdapterRegistry.

private Map<ResourceMethod, RestLiArgumentBuilder> buildAdapterRegistry() {
    Map<ResourceMethod, RestLiArgumentBuilder> result = new HashMap<ResourceMethod, RestLiArgumentBuilder>(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.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)

Example 3 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class TestRestLiResponseHandler method buildRoutingResult.

private final RoutingResult buildRoutingResult(ResourceMethod resourceMethod, RestRequest request, Map<String, String> acceptHeaders) 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, 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 4 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project parseq by linkedin.

the class RequestConfigElement method parse.

static RequestConfigElement parse(String property, String key, Object value) throws RequestConfigKeyParsingException {
    RequestConfigKeyParsingErrorListener errorListener = new RequestConfigKeyParsingErrorListener();
    ANTLRInputStream input = new ANTLRInputStream(key);
    RequestConfigKeyLexer lexer = new RequestConfigKeyLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(errorListener);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    RequestConfigKeyParser parser = new RequestConfigKeyParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(errorListener);
    KeyContext keyTree = parser.key();
    if (!errorListener.hasErrors()) {
        InboundContext inbound = keyTree.inbound();
        OutboundContext outbound = keyTree.outbound();
        Optional<String> inboundName = handlingWildcard(inbound.restResource());
        Optional<String> outboundName = handlingWildcard(outbound.restResource());
        Optional<String> inboundOp = getOpIn(inbound.operationIn());
        Optional<ResourceMethod> outboundOp = getOpOut(outbound.operationOut());
        Optional<String> inboundOpName = inboundOp.flatMap(method -> getOpInName(method, inbound.operationIn()));
        Optional<String> outboundOpName = outboundOp.flatMap(method -> getOpOutName(method, outbound.operationOut()));
        return new RequestConfigElement(key, coerceValue(property, value), property, inboundName, outboundName, inboundOpName, outboundOpName, inboundOp, outboundOp);
    } else {
        throw new RequestConfigKeyParsingException("Error" + ((errorListener.errorsSize() > 1) ? "s" : "") + " parsing key: " + key + "\n" + errorListener);
    }
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) InboundContext(com.linkedin.restli.client.config.RequestConfigKeyParser.InboundContext) OutboundContext(com.linkedin.restli.client.config.RequestConfigKeyParser.OutboundContext) KeyContext(com.linkedin.restli.client.config.RequestConfigKeyParser.KeyContext) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 5 with ResourceMethod

use of com.linkedin.restli.common.ResourceMethod in project rest.li by linkedin.

the class TestCustomMethodAdapterProvider method initClass.

@BeforeClass
public void initClass() throws Exception {
    RestLiConfig config = new RestLiConfig();
    config.setMethodAdapterProvider(new DefaultMethodAdapterProvider(new ErrorResponseBuilder(ErrorResponseFormat.MESSAGE_AND_SERVICECODE)) {

        @Override
        public RestLiArgumentBuilder getArgumentBuilder(ResourceMethod resourceMethod) {
            // Override the behavior of the CREATE argument builder
            if (resourceMethod == ResourceMethod.CREATE) {
                return new CreateArgumentBuilder() {

                    @Override
                    public RestLiRequestData extractRequestData(RoutingResult routingResult, DataMap dataMap) {
                        // Always use the FRIENDLY record regardless of the actual data
                        return new RestLiRequestDataImpl.Builder().entity(FRIENDLY).build();
                    }
                };
            } else {
                return super.getArgumentBuilder(resourceMethod);
            }
        }
    });
    super.init(false, config);
}
Also used : RoutingResult(com.linkedin.restli.internal.server.RoutingResult) DefaultMethodAdapterProvider(com.linkedin.restli.internal.server.methods.DefaultMethodAdapterProvider) CreateArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.CreateArgumentBuilder) ErrorResponseBuilder(com.linkedin.restli.internal.server.response.ErrorResponseBuilder) RestLiRequestDataImpl(com.linkedin.restli.server.RestLiRequestDataImpl) RestLiArgumentBuilder(com.linkedin.restli.internal.server.methods.arguments.RestLiArgumentBuilder) RestLiConfig(com.linkedin.restli.server.RestLiConfig) ResourceMethod(com.linkedin.restli.common.ResourceMethod) DataMap(com.linkedin.data.DataMap) RestLiRequestData(com.linkedin.restli.server.RestLiRequestData) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ResourceMethod (com.linkedin.restli.common.ResourceMethod)54 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)18 ResourceSpecImpl (com.linkedin.restli.common.ResourceSpecImpl)13 DataMap (com.linkedin.data.DataMap)12 TestRecord (com.linkedin.restli.client.test.TestRecord)12 DynamicRecordMetadata (com.linkedin.data.template.DynamicRecordMetadata)10 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 ProtocolVersion (com.linkedin.restli.common.ProtocolVersion)6 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)6 ResourceMethodDescriptor (com.linkedin.restli.internal.server.model.ResourceMethodDescriptor)5 ValidationResult (com.linkedin.data.schema.validation.ValidationResult)4 RecordTemplate (com.linkedin.data.template.RecordTemplate)4 Foo (com.linkedin.pegasus.generator.examples.Foo)4 RoutingResult (com.linkedin.restli.internal.server.RoutingResult)4 ResourceSchemaArray (com.linkedin.restli.restspec.ResourceSchemaArray)4 JClass (com.sun.codemodel.JClass)4 JDefinedClass (com.sun.codemodel.JDefinedClass)4 ByteString (com.linkedin.data.ByteString)3