use of com.linkedin.restli.server.ResourceConfigException in project rest.li by linkedin.
the class RestLiAnnotationReader method getActionTyperefDataSchema.
private static TyperefDataSchema getActionTyperefDataSchema(ResourceModel model, Action actionAnno, String actionName) {
TyperefDataSchema returnTyperefSchema = null;
Class<? extends TyperefInfo> typerefInfoClass = actionAnno.returnTyperef();
try {
returnTyperefSchema = getSchemaFromTyperefInfo(typerefInfoClass);
} catch (Exception e) {
throw new ResourceConfigException("Typeref @Action method named '" + actionName + "' on class '" + model.getResourceClass().getName() + "' cannot be instantiated, " + e.getMessage());
}
return returnTyperefSchema;
}
use of com.linkedin.restli.server.ResourceConfigException in project rest.li by linkedin.
the class RestLiAnnotationReader method buildQueryParam.
private static Parameter<?> buildQueryParam(final Method method, final AnnotationSet annotations, final Class<?> paramType) {
QueryParam queryParam = annotations.get(QueryParam.class);
Optional optional = annotations.get(Optional.class);
String paramName = queryParam.value();
if (INVALID_CHAR_PATTERN.matcher(paramName).find()) {
throw new ResourceConfigException("Unsupported character in the parameter name :" + paramName);
}
Class<? extends TyperefInfo> typerefInfoClass = queryParam.typeref();
try {
@SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter(queryParam.value(), paramType, getDataSchema(paramType, getSchemaFromTyperefInfo(typerefInfoClass)), optional != null, getDefaultValueData(optional), Parameter.ParamType.QUERY, true, annotations);
return param;
} catch (TemplateRuntimeException e) {
throw new ResourceConfigException("DataSchema for parameter '" + paramName + "' of type " + paramType.getSimpleName() + " on " + buildMethodMessage(method) + "cannot be found; type is invalid or requires typeref", e);
} catch (Exception e) {
throw new ResourceConfigException("Typeref for parameter '" + paramName + "' on " + buildMethodMessage(method) + " cannot be instantiated, " + e.getMessage(), e);
}
}
use of com.linkedin.restli.server.ResourceConfigException in project rest.li by linkedin.
the class RestLiAnnotationReader method validateFinderMethod.
private static void validateFinderMethod(final ResourceMethodDescriptor finderMethodDescriptor, final ResourceModel resourceModel) {
Method method = finderMethodDescriptor.getMethod();
Class<?> valueClass = resourceModel.getValueClass();
Class<?> returnType, elementType;
try {
returnType = getLogicalReturnClass(method);
final List<Class<?>> typeArguments;
if (List.class.isAssignableFrom(returnType)) {
typeArguments = ReflectionUtils.getTypeArguments(List.class, returnType.asSubclass(List.class));
} else if (CollectionResult.class.isAssignableFrom(returnType)) {
typeArguments = ReflectionUtils.getTypeArguments(CollectionResult.class, returnType.asSubclass(CollectionResult.class));
} else {
throw new ResourceConfigException("@Finder method '" + method.getName() + "' on class '" + resourceModel.getResourceClass().getName() + "' has an unsupported return type");
}
if (typeArguments == null || typeArguments.get(0) == null) {
// the return type may leave value type as parameterized and specify in runtime
final ParameterizedType collectionType = (ParameterizedType) getLogicalReturnType(method);
elementType = (Class<?>) collectionType.getActualTypeArguments()[0];
} else {
elementType = typeArguments.get(0);
}
} catch (ClassCastException e) {
throw new ResourceConfigException("@Finder method '" + method.getName() + "' on class '" + resourceModel.getResourceClass().getName() + "' has an invalid return or a data template type", e);
}
if (!List.class.isAssignableFrom(returnType) && !CollectionResult.class.isAssignableFrom(returnType)) {
throw new ResourceConfigException("@Finder method '" + method.getName() + "' on class '" + resourceModel.getResourceClass().getName() + "' has an invalid return type '" + returnType.getName() + "'. Expected " + "List<" + valueClass.getName() + "> or CollectionResult<" + valueClass.getName() + ">");
}
String collectionClassName = returnType.getSimpleName();
if (!RecordTemplate.class.isAssignableFrom(elementType) || !resourceModel.getValueClass().equals(elementType)) {
throw new ResourceConfigException("@Finder method '" + method.getName() + "' on class '" + resourceModel.getResourceClass().getName() + "' has an invalid return type. Expected " + collectionClassName + "<" + valueClass.getName() + ">, but found " + collectionClassName + "<" + elementType + '>');
}
ResourceMethodDescriptor existingFinder = resourceModel.findNamedMethod(finderMethodDescriptor.getFinderName());
if (existingFinder != null) {
throw new ResourceConfigException("Found duplicate @Finder method named '" + finderMethodDescriptor.getFinderName() + "' on class '" + resourceModel.getResourceClass().getName() + '\'');
}
// query parameters are checked in getQueryParameters method
}
use of com.linkedin.restli.server.ResourceConfigException in project rest.li by linkedin.
the class RestLiAnnotationReader method buildAlternativeKey.
/**
* Create an {@link com.linkedin.restli.server.AlternativeKey} object from an {@link com.linkedin.restli.server.annotations.AlternativeKey} annotation.
*
* @param resourceName Name of the resource.
* @param altKeyAnnotation The {@link com.linkedin.restli.server.annotations.AlternativeKey} annotation.
* @return {@link com.linkedin.restli.server.AlternativeKey} object.
*/
private static com.linkedin.restli.server.AlternativeKey<?, ?> buildAlternativeKey(String resourceName, AlternativeKey altKeyAnnotation) {
String keyName = altKeyAnnotation.name();
Class<?> keyType = altKeyAnnotation.keyType();
Class<? extends TyperefInfo> altKeyTyperef = altKeyAnnotation.keyTyperefClass();
KeyCoercer<?, ?> keyCoercer;
try {
keyCoercer = altKeyAnnotation.keyCoercer().newInstance();
} catch (InstantiationException e) {
throw new ResourceConfigException(String.format("KeyCoercer for alternative key '%s' on resource %s cannot be instantiated, %s", keyName, resourceName, e.getMessage()), e);
} catch (IllegalAccessException e) {
throw new ResourceConfigException(String.format("KeyCoercer for alternative key '%s' on resource %s cannot be instantiated, %s", keyName, resourceName, e.getMessage()), e);
}
try {
@SuppressWarnings("unchecked") com.linkedin.restli.server.AlternativeKey<?, ?> altKey = new com.linkedin.restli.server.AlternativeKey(keyCoercer, keyType, getDataSchema(keyType, getSchemaFromTyperefInfo(altKeyTyperef)));
return altKey;
} catch (TemplateRuntimeException e) {
throw new ResourceConfigException(String.format("DataSchema for alternative key '%s' of type %s on resource %s cannot be found; type is invalid or requires typeref.", keyName, keyType, resourceName), e);
} catch (Exception e) {
throw new ResourceConfigException(String.format("Typeref for alternative key '%s' on resource %s cannot be instantiated, %s", keyName, resourceName, e.getMessage()), e);
}
}
use of com.linkedin.restli.server.ResourceConfigException in project rest.li by linkedin.
the class RestLiAnnotationReader method buildHeaderParam.
private static Parameter<?> buildHeaderParam(final AnnotationSet annotations, final Class<?> paramType) {
if (!paramType.equals(String.class)) {
throw new ResourceConfigException("Incorrect data type for param: @" + HeaderParam.class.getSimpleName() + " parameter annotation must be of type String");
}
Optional optional = annotations.get(Optional.class);
@SuppressWarnings({ "unchecked", "rawtypes" }) Parameter<?> param = new Parameter("", paramType, null, optional != null, "", Parameter.ParamType.HEADER, false, annotations);
return param;
}
Aggregations