Java Code Examples for javax.ws.rs.QueryParam#value()

The following examples show how to use javax.ws.rs.QueryParam#value() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AnnotationHelper.java    From proteus with Apache License 2.0 6 votes vote down vote up
public static QueryParam createQueryParam(Parameter parameter)
{
    return new QueryParam()
    {
        @Override
        public String value()
        {
            QueryParam annotation = parameter.getAnnotation(QueryParam.class);

            if (annotation != null)
            {
                return annotation.value();
            }

            return parameter.getName();
        }
        @Override
        public Class<? extends Annotation> annotationType()
        {
            return QueryParam.class;
        }
    };
}
 
Example 2
Source File: PortletParamProducer.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
private String _getParamName(Annotation[] annotations) {

		for (Annotation annotation : annotations) {
			Class<? extends Annotation> annotationClass = annotation.getClass();

			if (CookieParam.class.isAssignableFrom(annotationClass)) {
				CookieParam cookieParam = (CookieParam) annotation;

				return cookieParam.value();
			}

			if (FormParam.class.isAssignableFrom(annotationClass)) {
				FormParam formParam = (FormParam) annotation;

				return formParam.value();
			}

			if (HeaderParam.class.isAssignableFrom(annotationClass)) {
				HeaderParam headerParam = (HeaderParam) annotation;

				return headerParam.value();
			}

			if (QueryParam.class.isAssignableFrom(annotationClass)) {
				QueryParam queryParam = (QueryParam) annotation;

				return queryParam.value();
			}
		}

		return null;
	}
 
Example 3
Source File: QueryParamAnnotationProcessor.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@Override
public String getParameterName(QueryParam parameterAnnotation) {
  return parameterAnnotation.value();
}
 
Example 4
Source File: BeanValidationInterceptor.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@AroundInvoke
public Object validateMethodInvocation(InvocationContext invocationContext) throws Exception {

	Validator validator = validatorFactory.getValidator();

	if (validator == null) {
		return invocationContext.proceed();
	}

	Set<ConstraintViolation<Object>> constraintViolations = validator.validate(invocationContext.getTarget());

	for (ConstraintViolation<Object> constraintViolation : constraintViolations) {

		Path propertyPath = constraintViolation.getPropertyPath();

		Path.Node lastPathNode = null;

		for (Path.Node pathNode : propertyPath) {
			lastPathNode = pathNode;
		}

		if ((lastPathNode != null) && (lastPathNode.getKind() == ElementKind.PROPERTY)) {

			Object leafBean = constraintViolation.getLeafBean();
			Class<?> leafBeanClass = leafBean.getClass();

			BeanInfo beanInfo = Introspector.getBeanInfo(leafBean.getClass());

			PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();

			for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
				String propertyDescriptorName = propertyDescriptor.getName();

				if (propertyDescriptorName.equals("targetClass")) {
					Method readMethod = propertyDescriptor.getReadMethod();
					leafBeanClass = (Class<?>) readMethod.invoke(leafBean);
				}
			}

			Field leafBeanField = leafBeanClass.getDeclaredField(lastPathNode.getName());

			String paramName = null;

			Annotation[] annotations = leafBeanField.getAnnotations();

			for (Annotation annotation : annotations) {

				if (annotation instanceof CookieParam) {
					CookieParam cookieParam = (CookieParam) annotation;
					paramName = cookieParam.value();

					break;
				}
				else if (annotation instanceof FormParam) {
					FormParam formParam = (FormParam) annotation;
					paramName = formParam.value();

					break;
				}
				else if (annotation instanceof HeaderParam) {
					HeaderParam headerParam = (HeaderParam) annotation;
					paramName = headerParam.value();

					break;
				}
				else if (annotation instanceof QueryParam) {
					QueryParam queryParam = (QueryParam) annotation;
					paramName = queryParam.value();
				}
			}

			String interpolatedMessage = constraintViolation.getMessage();

			if (messageInterpolator != null) {
				interpolatedMessage = messageInterpolator.interpolate(constraintViolation.getMessageTemplate(),
						new MessageInterpolatorContextImpl(constraintViolation), mvcContext.getLocale());
			}

			mutableBindingResult.addValidationError(new ValidationErrorImpl(paramName, interpolatedMessage,
					constraintViolation));
		}

	}

	return invocationContext.proceed();
}
 
Example 5
Source File: ResourceUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static Parameter getParameter(int index, Annotation[] anns, Class<?> type) {

        Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
        if (ctx != null) {
            return new Parameter(ParameterType.CONTEXT, index, null);
        }

        boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;

        BeanParam bp = AnnotationUtils.getAnnotation(anns, BeanParam.class);
        if (bp != null) {
            return new Parameter(ParameterType.BEAN, index, null, isEncoded, null);
        }

        String dValue = AnnotationUtils.getDefaultParameterValue(anns);

        PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class);
        if (a != null) {
            return new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
        }
        QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
        if (q != null) {
            return new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
        }
        MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
        if (m != null) {
            return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
        }

        FormParam f = AnnotationUtils.getAnnotation(anns, FormParam.class);
        if (f != null) {
            return new Parameter(ParameterType.FORM, index, f.value(), isEncoded, dValue);
        }

        HeaderParam h = AnnotationUtils.getAnnotation(anns, HeaderParam.class);
        if (h != null) {
            return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
        }

        CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
        if (c != null) {
            return new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
        }

        return new Parameter(ParameterType.REQUEST_BODY, index, null);

    }
 
Example 6
Source File: ParamConverterProviderImpl.java    From portals-pluto with Apache License 2.0 3 votes vote down vote up
private String _getParamName(Annotation[] annotations) {

		for (Annotation annotation : annotations) {

			Class<? extends Annotation> annotationClass = annotation.getClass();

			if (CookieParam.class.isAssignableFrom(annotationClass)) {
				CookieParam cookieParam = (CookieParam) annotation;

				return cookieParam.value();
			}

			if (FormParam.class.isAssignableFrom(annotationClass)) {
				FormParam formParam = (FormParam) annotation;

				return formParam.value();
			}

			if (HeaderParam.class.isAssignableFrom(annotationClass)) {
				HeaderParam headerParam = (HeaderParam) annotation;

				return headerParam.value();
			}

			if (QueryParam.class.isAssignableFrom(annotationClass)) {
				QueryParam queryParam = (QueryParam) annotation;

				return queryParam.value();
			}
		}

		return null;
	}