Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.ResourceConfigException


    if (resourceMethod != null)
    {
      if (!Modifier.isPublic(method.getModifiers()))
      {
        throw new ResourceConfigException(String.format("Resource '%s' contains non-public CRUD method '%s'.",
                                                        model.getName(),
                                                        method.getName()));
      }

      DataMap annotationsMap = ResourceModelAnnotation.getAnnotationsMap(method.getAnnotations());
View Full Code Here


          RestMethod.getResourceMethod(methodAnnotation.annotationType());
      if (resourceMethod != null)
      {
        if (restMethodAnnotationFound)
        {
          throw new ResourceConfigException("Multiple rest method annotations in method "
              + method.getName());
        }
        restMethodAnnotationFound = true;

        if (!Modifier.isPublic(method.getModifiers()))
        {
          throw new ResourceConfigException(String.format("Resource '%s' contains non-public CRUD method '%s'.",
                                                          model.getName(),
                                                          method.getName()));
        }

        DataMap annotationsMap = ResourceModelAnnotation.getAnnotationsMap(method.getAnnotations());
View Full Code Here

    TyperefDataSchema returnTyperefSchema = getActionTyperefDataSchema(model, actionAnno, actionName);
    validateActionReturnType(model, method, returnClass, returnTyperefSchema);

    if (!Modifier.isPublic(method.getModifiers()))
    {
      throw new ResourceConfigException(String.format("Resource '%s' contains non-public action method '%s'.",
                                                      model.getName(),
                                                      method.getName()));
    }

    RecordDataSchema recordDataSchema = DynamicRecordMetadata.buildSchema(method.getName(),
                                                                          parameters);

    RecordDataSchema actionReturnRecordDataSchema;
    FieldDef<?> returnFieldDef;
    if(returnClass != Void.TYPE)
    {
      @SuppressWarnings({"unchecked", "rawtypes"})
      FieldDef<?> nonVoidFieldDef = new FieldDef(ActionResponse.VALUE_NAME, returnClass, getDataSchema(returnClass, returnTyperefSchema));
      returnFieldDef = nonVoidFieldDef;
      actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(ActionResponse.class.getName(), Collections.singleton((returnFieldDef)));
    }
    else
    {
      returnFieldDef = null;
      actionReturnRecordDataSchema = DynamicRecordMetadata.buildSchema(ActionResponse.class.getName(), Collections.<FieldDef<?>>emptyList());
    }

    if (model.getResourceLevel() == ResourceLevel.ENTITY && actionAnno.resourceLevel() == ResourceLevel.COLLECTION)
    {
      throw new ResourceConfigException(
          String.format("Resource '%s' is a simple resource, it cannot contain actions at resource level \"COLLECTION\".",
            model.getName()));
    }

    DataMap annotationsMap = ResourceModelAnnotation.getAnnotationsMap(method.getAnnotations());
View Full Code Here

    {
      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;
  }
View Full Code Here

    final Type returnType = getLogicalReturnType(method);
    ResourceMethodDescriptor existingMethodDescriptor =
        model.findActionMethod(actionName, getActionResourceLevel(actionAnno, model));
    if (existingMethodDescriptor != null)
    {
      throw new ResourceConfigException("Found duplicate @Action method named '"
          + actionName + "' on class '" + model.getResourceClass().getName() + '\'');

    }

    Class<?> returnClass = getBoxedTypeFromPrimitive(getLogicalReturnClass(method));
    if (ActionResult.class.isAssignableFrom(returnClass))
    {
      assert(returnType instanceof ParameterizedType);
      final ParameterizedType paramReturnType = (ParameterizedType) returnType;
      final Type[] actualReturnTypes = paramReturnType.getActualTypeArguments();
      assert(actualReturnTypes.length == 1);
      if (!(actualReturnTypes[0] instanceof Class<?>))
      {
        throw new ResourceConfigException("Unsupported type parameter for ActionResult<?>.");
      }
      returnClass = (Class<?>) actualReturnTypes[0];

      if (returnClass == Void.class)
      {
View Full Code Here

    {
      Class<?> returnType = getLogicalReturnClass(method);

      if (!checkParameterType(returnType, RestModelConstants.VALID_ACTION_RETURN_TYPES))
      {
        throw new ResourceConfigException("@Action method '" + method.getName()
            + "' on class '" + method.getDeclaringClass().getName()
            + "' has an invalid return type '" + returnType.getName()
            + "'. Expected a DataTemplate or a primitive");
      }
    }

    final String checkTyperefMessage = checkTyperefSchema(returnClass, returnTyperefSchema);
    if (checkTyperefMessage != null)
    {
      throw new ResourceConfigException("Typeref @Action method named '" + method.getAnnotation(Action.class).name()
                                            + "' on class '" + model.getResourceClass().getName() + "', "
                                            + checkTyperefMessage);
    }
  }
View Full Code Here

      {
        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
View Full Code Here

    boolean callback = getParamIndex(method, Callback.class) != -1;
    boolean isVoid = method.getReturnType().equals(Void.TYPE);

    if (callback && !isVoid)
    {
      throw new ResourceConfigException(String.format("%s has both callback and return value",
                                                      method));
      // note that !callback && !isVoid is a legal synchronous action method
    }

    if (callback)
View Full Code Here

        {
          where = i;
        }
        else
        {
          throw new ResourceConfigException(String.format("method '%s' has too many '%s' parameters",
                                                          method,
                                                          type));
        }
      }
    }
View Full Code Here

          result = ValueConverter.coerceString(defaultValueString, getType());
        }
      }
      catch (TemplateOutputCastException e)
      {
        throw new ResourceConfigException(e.getMessage(), e);
      }
      catch (IllegalArgumentException e)
      {
        throw new ResourceConfigException("Default value for parameter of type \""
                                              + getType().getName() + "\" is not supported: " + e.getMessage(), e);
      }
      catch (IOException e)
      {
        throw new ResourceConfigException("Default value for parameter of type \""
                                              + getType().getName() + "\" is not supported: " + e.getMessage(), e);
      }
    }
    else
    {
View Full Code Here

TOP

Related Classes of com.linkedin.restli.server.ResourceConfigException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.