Search in sources :

Example 31 with ResourceMethod

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

the class RestClient method sendStreamRequest.

private <T> void sendStreamRequest(final Request<T> request, RequestContext requestContext, Callback<StreamResponse> callback) {
    RecordTemplate input = request.getInputRecord();
    getProtocolVersionForService(request, requestContext, new Callback<ProtocolVersion>() {

        @Override
        public void onError(Throwable e) {
            callback.onError(e);
        }

        @Override
        public void onSuccess(ProtocolVersion protocolVersion) {
            TimingContextUtil.beginTiming(requestContext, FrameworkTimingKeys.CLIENT_REQUEST_RESTLI_URI_ENCODE.key());
            URI requestUri = RestliUriBuilderUtil.createUriBuilder(request, _uriPrefix, protocolVersion).build();
            TimingContextUtil.endTiming(requestContext, FrameworkTimingKeys.CLIENT_REQUEST_RESTLI_URI_ENCODE.key());
            final ResourceMethod method = request.getMethod();
            final String methodName = request.getMethodName();
            addDisruptContext(request.getBaseUriTemplate(), method, methodName, requestContext);
            sendStreamRequestImpl(requestContext, requestUri, method, input != null ? RequestBodyTransformer.transform(request, protocolVersion) : null, request.getHeaders(), CookieUtil.encodeCookies(request.getCookies()), methodName, protocolVersion, request.getRequestOptions(), request.getStreamingAttachments(), callback);
        }
    });
}
Also used : RecordTemplate(com.linkedin.data.template.RecordTemplate) ByteString(com.linkedin.data.ByteString) ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) URI(java.net.URI) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 32 with ResourceMethod

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

the class DisruptRestClient method doEvaluateDisruptContext.

/**
 * Evaluates if a {@link Request} should be disrupted, against the {@link DisruptRestController}
 * and store the corresponding {@link DisruptContext} into the {@link RequestContext}. However,
 * if disrupt source is already set in the ReuqestContext, the method does not evaluate further.
 *
 * @param request Request
 * @param requestContext Context associated with the request
 * @param <T> Request template
 */
private <T> void doEvaluateDisruptContext(Request<T> request, RequestContext requestContext) {
    addDisruptContextIfNotPresent(requestContext, _controller.getClass(), () -> {
        final ResourceMethod method = request.getMethod();
        final String resource = request.getBaseUriTemplate();
        final String name = request.getMethodName();
        if (name == null) {
            return _controller.getDisruptContext(resource, method);
        } else {
            return _controller.getDisruptContext(resource, method, name);
        }
    });
}
Also used : ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 33 with ResourceMethod

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

the class ErrorResponseBuilder method buildRestLiResponseData.

public RestLiResponseData<?> buildRestLiResponseData(RoutingResult routingResult, RestLiServiceException exceptionResult, Map<String, String> headers, List<HttpCookie> cookies) {
    assert routingResult != null && routingResult.getResourceMethod() != null;
    if (_errorResponseFormat.showHeaders()) {
        final ProtocolVersion protocolVersion = ProtocolVersionUtil.extractProtocolVersion(headers);
        headers.put(HeaderUtil.getErrorResponseHeaderName(protocolVersion), RestConstants.HEADER_VALUE_ERROR);
    }
    ResourceMethod type = routingResult.getResourceMethod().getMethodType();
    return buildErrorResponseData(type, exceptionResult, headers, cookies);
}
Also used : ProtocolVersion(com.linkedin.restli.common.ProtocolVersion) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Example 34 with ResourceMethod

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

the class TestRestLiResourceModels method testCustomCrudParams.

@Test
public void testCustomCrudParams() throws Exception {
    ResourceModel model = buildResourceModel(CombinedResources.CollectionWithCustomCrudParams.class);
    checkCollectionModel(model, "test", String.class, "testId", Foo.class, false, CombinedResources.CollectionWithCustomCrudParams.class);
    checkEntityModel(model, String.class, "testId", Foo.class, Collections.<String, Class<?>>emptyMap());
    ResourceMethod[] crudMethods = { ResourceMethod.GET, ResourceMethod.CREATE, ResourceMethod.UPDATE, ResourceMethod.PARTIAL_UPDATE, ResourceMethod.DELETE, ResourceMethod.BATCH_GET, ResourceMethod.BATCH_CREATE, ResourceMethod.BATCH_DELETE, ResourceMethod.BATCH_UPDATE, ResourceMethod.BATCH_PARTIAL_UPDATE };
    assertHasMethods(model, crudMethods);
    for (ResourceMethod method : crudMethods) {
        ResourceMethodDescriptor descriptor = model.findMethod(method);
        List<Parameter<?>> params = descriptor.getParameters();
        boolean foundIntParam = false;
        boolean foundStringParam = false;
        for (Parameter<?> param : params) {
            if (param.getName().equals("intParam")) {
                foundIntParam = true;
                Assert.assertEquals(param.getType(), int.class);
                Assert.assertTrue(param.isOptional());
                Assert.assertEquals(param.getDefaultValue(), Integer.valueOf(42));
            } else if (param.getName().equals("stringParam")) {
                foundStringParam = true;
                Assert.assertEquals(param.getType(), String.class);
                Assert.assertFalse(param.isOptional());
                Assert.assertFalse(param.hasDefaultValue());
            }
        }
        Assert.assertTrue(foundIntParam);
        Assert.assertTrue(foundStringParam);
    }
}
Also used : CombinedResources(com.linkedin.restli.server.combined.CombinedResources) 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) Parameter(com.linkedin.restli.internal.server.model.Parameter) ResourceMethod(com.linkedin.restli.common.ResourceMethod) Test(org.testng.annotations.Test)

Example 35 with ResourceMethod

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

the class ResourceSchemaToResourceSpecTranslator method buildResourceSpec.

private ResourceSpec buildResourceSpec(StringArray supports, TypeSpec<?> key, ComplexKeySpec<?, ?> complexKeyType, Map<String, ?> keyParts, String entitySchemaString, ActionSchemaArray actions, ActionSchemaArray entityActions) {
    Set<ResourceMethod> supportedMethods = toResourceMethods(supports);
    ActionCollectionMetadata actionCollectionMetadata = toDynamicRecordMetadata(actions, entityActions);
    Map<String, DynamicRecordMetadata> actionRequestMetadata = actionCollectionMetadata._request;
    Map<String, DynamicRecordMetadata> actionResponseMetadata = actionCollectionMetadata._response;
    DataSchema entitySchema = entitySchemaString == null ? null : RestSpecCodec.textToSchema(entitySchemaString, _schemaResolver);
    TypeSpec<? extends RecordTemplate> value = toValueType(entitySchema);
    return new ResourceSpecImpl(supportedMethods, actionRequestMetadata, actionResponseMetadata, key, complexKeyType, value, keyParts);
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) DynamicRecordMetadata(com.linkedin.data.template.DynamicRecordMetadata) ResourceSpecImpl(com.linkedin.restli.common.ResourceSpecImpl) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

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