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);
}
});
}
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);
}
});
}
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);
}
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);
}
}
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);
}
Aggregations