Search in sources :

Example 1 with QueryParam

use of com.linkedin.restli.server.annotations.QueryParam 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);
    }
}
Also used : Optional(com.linkedin.restli.server.annotations.Optional) QueryParam(com.linkedin.restli.server.annotations.QueryParam) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) TemplateRuntimeException(com.linkedin.data.template.TemplateRuntimeException) ResourceConfigException(com.linkedin.restli.server.ResourceConfigException) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException)

Aggregations

TemplateRuntimeException (com.linkedin.data.template.TemplateRuntimeException)1 RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)1 ResourceConfigException (com.linkedin.restli.server.ResourceConfigException)1 Optional (com.linkedin.restli.server.annotations.Optional)1 QueryParam (com.linkedin.restli.server.annotations.QueryParam)1