Package com.linkedin.restli.server

Examples of com.linkedin.restli.server.ResourceConfigException


                                              final Class<?> paramType,
                                              final AnnotationSet annotations)
  {
    if (!Callback.class.equals(paramType))
    {
      throw new ResourceConfigException(String.format("%s '%s' of class '%s' does not have a proper callback",
                                                      methodType,
                                                      method.getName(),
                                                      method.getDeclaringClass()
                                                            .getName()));
    }
View Full Code Here


                                                                                final AnnotationSet annotations,
                                                                                final Class<?> paramAnnotationType)
  {
    if (!com.linkedin.parseq.Context.class.equals(paramType))
    {
      throw new ResourceConfigException("Incorrect data type for param: @" + ParSeqContextParam.class.getSimpleName() + " or @" + ParSeqContext.class.getSimpleName() +
              " parameter annotation must be of type " +  com.linkedin.parseq.Context.class.getName());
    }
    if (getInterfaceType(method) != InterfaceType.PROMISE)
    {
      throw new ResourceConfigException("Cannot have ParSeq context on non-promise method");
    }
    Parameter.ParamType parameter = null;
    if(paramAnnotationType.equals(ParSeqContext.class))
    {
      parameter = Parameter.ParamType.PARSEQ_CONTEXT;
    }
    else if (paramAnnotationType.equals(ParSeqContextParam.class))
    {
      parameter = Parameter.ParamType.PARSEQ_CONTEXT_PARAM;
    }
    else
    {
      throw new ResourceConfigException("Param Annotation type must be 'ParseqContextParam' or the deprecated 'ParseqContext' for ParseqContext");
    }
    return new Parameter<com.linkedin.parseq.Context>("",
                                                      com.linkedin.parseq.Context.class,
                                                      null,
                                                      false,
View Full Code Here

                                        final Class<?> actualParamType)
  {
    String paramName = param.getName();
    if (!paramName.isEmpty() && paramNames.contains(paramName))
    {
      throw new ResourceConfigException("Parameter '" + paramName + "' on "
          + buildMethodMessage(method) + " is specified more than once");
    }
    paramNames.add(paramName);

    if (!actualParamType.isAssignableFrom(param.getType()))
    {
      throw new ResourceConfigException("Parameter '" + paramName + "' on "
          + buildMethodMessage(method) + " is not a valid type '" + actualParamType
          + "'.  Must be assignable from '" + param.getType() + "'.");
    }

    if (methodType == ResourceMethod.ACTION)
    {
      if (annotations.contains(QueryParam.class))
      {
        throw new ResourceConfigException("Parameter '" + paramName + "' on "
                                              + buildMethodMessage(method) + " is a @QueryParam but action method cannot have @QueryParam");
      }

      if (param.getParamType() == Parameter.ParamType.POST
          && !(checkParameterType(param.getType(), RestModelConstants.VALID_ACTION_PARAMETER_TYPES) ||
               checkParameterHasTyperefSchema(param)))
      {
        throw new ResourceConfigException("Parameter '" + paramName + "' on "
                                              + buildMethodMessage(method) + " is not a valid type (" + param.getType() + ')');
      }
    }
    else if (param.getParamType() == Parameter.ParamType.QUERY
          && !(checkParameterType(param.getType(), RestModelConstants.VALID_QUERY_PARAMETER_TYPES) ||
               checkParameterHasTyperefSchema(param)))
    {
        throw new ResourceConfigException("Parameter '" + paramName + "' on "
                                              + buildMethodMessage(method) + " is not a valid type (" + param.getType() + ')');
    }

    if (param.getType().isPrimitive() && param.isOptional() && !param.hasDefaultValue())
    {
      throw new ResourceConfigException("Parameter '"
          + paramName
          + "' on "
          + buildMethodMessage(method)
          + " is a primitive type, but does not specify a default value in the @Optional annotation");
    }

    final String checkTyperefMessage = checkTyperefSchema(param.getType(), param.getDataSchema());
    if (checkTyperefMessage != null)
    {
      throw new ResourceConfigException("Parameter '" + paramName + "' on "
          + buildMethodMessage(method) + ", " + checkTyperefMessage);
    }

    if (annotationCount(annotations) > 1)
    {
      throw new ResourceConfigException(buildMethodMessage(method)
          + "' must declare only one of @QueryParam, @ActionParam, @AssocKeyParam, @PagingContextParam, or @CallbackParam");
    }
  }
View Full Code Here

      {
        dataSchema = ((ArrayDataSchema) dataSchema).getItems();
      }
      else
      {
        throw new ResourceConfigException(
            "Array typed parameter " + parameter.getName() + " must have an array schema.");
      }
    }

    if (dataSchema instanceof TyperefDataSchema)
View Full Code Here

    {
      return new Key(keyName, keyType, getDataSchema(keyType, getSchemaFromTyperefInfo(typerefInfoClass)));
    }
    catch (TemplateRuntimeException e)
    {
      throw new ResourceConfigException("DataSchema for key '" + keyName + "' of type " + keyType + " on resource "
                                                + resourceName + "cannot be found; type is invalid or requires typeref", e);
    }
    catch (Exception e)
    {
      throw new ResourceConfigException("Typeref for parameter '" + keyName + "' on resource "
                                                + resourceName + " cannot be instantiated, " + e.getMessage(), e);
    }

  }
View Full Code Here

  private static Parameter<?> buildProjectionParam(final AnnotationSet annotations, final Class<?> paramType,
      final Parameter.ParamType projectionType)
  {
    if (!paramType.equals(MaskTree.class))
    {
      throw new ResourceConfigException("Incorrect data type for param: @" + ProjectionParam.class.getSimpleName() +
          ", @" + Projection.class.getSimpleName() +
          ", @" + MetadataProjectionParam.class.getSimpleName() +
          " or @" + PagingProjectionParam.class.getSimpleName() +
          " parameter annotation must be of type " + MaskTree.class.getName());
    }
View Full Code Here

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

  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("",
View Full Code Here

                                                      final Class<?> paramType,
                                                      final Class<?> paramAnnotationType)
  {
    if (!paramType.equals(PagingContext.class))
    {
      throw new ResourceConfigException("Incorrect data type for param: @" + PagingContextParam.class.getSimpleName() + " or @" + Context.class.getSimpleName() +
              " parameter annotation must be of type " +  PagingContext.class.getName());
    }

    PagingContext defaultContext = null;
    Parameter.ParamType parameter = null;
    if(paramAnnotationType.equals(PagingContextParam.class))
    {
      PagingContextParam pagingContextParam = annotations.get(PagingContextParam.class);
      defaultContext = new PagingContext(pagingContextParam.defaultStart(), pagingContextParam.defaultCount(), false, false);
      parameter = Parameter.ParamType.PAGING_CONTEXT_PARAM;
    }
    else if (paramAnnotationType.equals(Context.class))
    {
      Context contextParam = annotations.get(Context.class);
      defaultContext = new PagingContext(contextParam.defaultStart(), contextParam.defaultCount(), false, false);
      parameter = Parameter.ParamType.CONTEXT;
    }
    else
    {
      throw new ResourceConfigException("Param Annotation type must be 'PagingContextParam' or the deprecated 'Context' for PagingContext");
    }
    Optional optional = annotations.get(Optional.class);
    @SuppressWarnings({"unchecked", "rawtypes"})
    Parameter<?> param =
        new Parameter("",
View Full Code Here

      assocKeyParamValue = annotations.get(AssocKeyParam.class).value();
      typerefInfoClass = annotations.get(AssocKeyParam.class).typeref();
    }
    else
    {
      throw new ResourceConfigException("Param Annotation type must be 'AssocKeysParam' or the deprecated 'AssocKey' for AssocKey");
    }
    Optional optional = annotations.get(Optional.class);

    if (!checkAssocKey(model.getKeys(), assocKeyParamValue))
    {
      throw new ResourceConfigException("Non-existing assocKey '" + assocKeyParamValue + "' on " + buildMethodMessage(method));
    }

    try
    {
      @SuppressWarnings({"unchecked", "rawtypes"})
      Parameter<?> param =
          new Parameter(assocKeyParamValue,
                        paramType,
                        getDataSchema(paramType, getSchemaFromTyperefInfo(typerefInfoClass)),
                        optional != null,
                        getDefaultValueData(optional),
                        parameter,
                        true,
                        annotations);
      return param;
    }
    catch (TemplateRuntimeException e)
    {
      throw new ResourceConfigException("DataSchema for assocKey '" + assocKeyParamValue + "' 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 assocKey '" + assocKeyParamValue + "' on "
                                                + buildMethodMessage(method) + " cannot be instantiated, " + e.getMessage(), e);
    }
  }
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.