use of com.linkedin.restli.internal.server.PathKeysImpl in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResultAction.
/**
* Creates a RoutingResult for an Action with the given returnType.
*
* @param actionReturnType the return type of the action.
* @return a RoutingResult
*/
private final RoutingResult buildRoutingResultAction(Class<?> actionReturnType, RestRequest request, Map<String, String> headers) throws NoSuchMethodException, RestLiSyntaxException, URISyntaxException {
if (actionReturnType == Void.class) {
actionReturnType = Void.TYPE;
}
// actual method passed in is irrelevant, since we are constructing a ResourceMethodDescriptor by hand.
Method method = ProjectionTestFixture.class.getMethod("batchGet", Set.class);
ResourceModel model = RestLiTestHelper.buildResourceModel(StatusCollectionResource.class);
String actionName = "return" + actionReturnType.getSimpleName();
List<Parameter<?>> parameters = Collections.<Parameter<?>>emptyList();
RecordDataSchema actionReturnRecordDataSchema;
FieldDef<?> returnFieldDef;
if (actionReturnType != Void.TYPE) {
@SuppressWarnings({ "unchecked", "rawtypes" }) FieldDef<?> nonVoidFieldDef = new FieldDef(ActionResponse.VALUE_NAME, actionReturnType, DataTemplateUtil.getSchema(actionReturnType));
returnFieldDef = nonVoidFieldDef;
actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(actionName, Collections.singleton(returnFieldDef));
} else {
returnFieldDef = null;
actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(actionName, Collections.<FieldDef<?>>emptyList());
}
ResourceMethodDescriptor methodDescriptor = ResourceMethodDescriptor.createForAction(method, parameters, actionName, ResourceLevel.COLLECTION, returnFieldDef, actionReturnRecordDataSchema, DynamicRecordMetadata.buildSchema(actionName, parameters), InterfaceType.SYNC, new DataMap());
model.addResourceMethodDescriptor(methodDescriptor);
ServerResourceContext resourceContext = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, resourceContext);
return new RoutingResult(resourceContext, methodDescriptor);
}
use of com.linkedin.restli.internal.server.PathKeysImpl in project rest.li by linkedin.
the class TestRestLiResponseHandler method buildRoutingResultFinder.
private final 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, context);
return new RoutingResult(context, methodDescriptor);
}
use of com.linkedin.restli.internal.server.PathKeysImpl 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);
}
use of com.linkedin.restli.internal.server.PathKeysImpl in project rest.li by linkedin.
the class TestRestLiResponseHandler method invokeResponseHandler.
private RestResponse invokeResponseHandler(String uri, ResourceMethodDescriptor methodDescriptor, Object result, Map<String, String> headers, ProtocolVersion protocolVersion) throws IOException, URISyntaxException, RestLiSyntaxException {
RestRequest request = buildRequest(uri, headers, protocolVersion);
ServerResourceContext context = new ResourceContextImpl(new PathKeysImpl(), request, new RequestContext());
RestUtils.validateRequestHeadersAndUpdateResourceContext(headers, context);
RoutingResult routingResult = new RoutingResult(context, methodDescriptor);
RestResponse response;
response = _responseHandler.buildResponse(request, routingResult, result);
return response;
}
use of com.linkedin.restli.internal.server.PathKeysImpl in project rest.li by linkedin.
the class RestLiAnnotationReader method buildPathKeysParam.
private static Parameter<?> buildPathKeysParam(final AnnotationSet annotations, final Class<?> paramType, final Class<?> paramAnnotationType) {
if (!paramType.equals(PathKeys.class)) {
throw new ResourceConfigException("Incorrect data type for param: @" + PathKeysParam.class.getSimpleName() + " or @" + Keys.class.getSimpleName() + " parameter annotation must be of type " + PathKeys.class.getName());
}
Optional optional = annotations.get(Optional.class);
Parameter.ParamType parameter = null;
if (paramAnnotationType.equals(Keys.class)) {
parameter = Parameter.ParamType.PATH_KEYS;
} else if (paramAnnotationType.equals(PathKeysParam.class)) {
parameter = Parameter.ParamType.PATH_KEYS_PARAM;
} else {
throw new ResourceConfigException("Param Annotation type must be 'PathKeysParam' or the deprecated 'Keys' for PathKeys");
}
@SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter("", paramType, null, optional != null, new PathKeysImpl(), parameter, false, annotations);
return param;
}
Aggregations