private boolean isDocAvailable(Annotation[] anns) { return AnnotationUtils.getAnnotation(anns, Description.class) != null || AnnotationUtils.getAnnotation(anns, Descriptions.class) != null; }
static int comparePriorityStatus(Class<?> cl1, Class<?> cl2) { Integer value1 = AnnotationUtils.getBindingPriority(cl1); Integer value2 = AnnotationUtils.getBindingPriority(cl2); return value1.compareTo(value2); }
protected static boolean isPrematching(Class<?> filterCls) { return AnnotationUtils.getClassAnnotation(filterCls, PreMatching.class) != null; }
private void checkEncoded() { encoded = AnnotationUtils.getMethodAnnotation(annotatedMethod, Encoded.class) != null; if (!encoded && classResourceInfo != null) { encoded = AnnotationUtils.getClassAnnotation(classResourceInfo.getServiceClass(), Encoded.class) != null; } }
public static Constructor<?> findResourceConstructor(Class<?> resourceClass, boolean perRequest) { List<Constructor<?>> cs = new LinkedList<>(); for (Constructor<?> c : resourceClass.getConstructors()) { Class<?>[] params = c.getParameterTypes(); Annotation[][] anns = c.getParameterAnnotations(); boolean match = true; for (int i = 0; i < params.length; i++) { if (!perRequest) { if (AnnotationUtils.getAnnotation(anns[i], Context.class) == null) { match = false; break; } } else if (!AnnotationUtils.isValidParamAnnotations(anns[i])) { match = false; break; } } if (match) { cs.add(c); } } Collections.sort(cs, new Comparator<Constructor<?>>() { public int compare(Constructor<?> c1, Constructor<?> c2) { int p1 = c1.getParameterTypes().length; int p2 = c2.getParameterTypes().length; return p1 > p2 ? -1 : p1 < p2 ? 1 : 0; } }); return cs.isEmpty() ? null : cs.get(0); }
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 (AnnotationUtils.isMethodAnnotation(a)) { return m; if (isValidParamAnnotations(paramAnnotations)) { LOG.warning("Method " + m.getName() + " in " + m.getDeclaringClass().getName() + " has no JAX-RS Path or HTTP Method annotations"); if (superC != null && Object.class != superC) { try { Method method = doGetAnnotatedMethod(serviceClass, superC.getMethod(m.getName(), m.getParameterTypes())); if (method != null) { Method method = doGetAnnotatedMethod(serviceClass, i.getMethod(m.getName(), m.getParameterTypes())); if (method != null) { for (Class<?> i : serviceClass.getInterfaces()) { try { Method method = doGetAnnotatedMethod(serviceClass, i.getMethod(m.getName(), m.getParameterTypes())); if (method != null) {
for (Method m : serviceClass.getMethods()) { Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m); String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod); Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
private static <T> void mapContainerFilters(Map<NameKey, ProviderInfo<T>> map, List<ProviderInfo<T>> postMatchFilters, boolean ascending) { Collections.sort(postMatchFilters, new PostMatchFilterComparator(ascending)); for (ProviderInfo<T> p : postMatchFilters) { List<String> names = AnnotationUtils.getNameBindings( p.getProvider().getClass().getAnnotations()); names = names.isEmpty() ? Collections.singletonList(DEFAULT_FILTER_NAME_BINDING) : names; for (String name : names) { map.put(new NameKey(name, AnnotationUtils.getBindingPriority(p.getProvider().getClass())), p); } } }
private static void evaluateResourceMethod(ClassResourceInfo cri, boolean enableStatic, MethodDispatcher md, Method m, Method annotatedMethod) { String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod); Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
private Map<String, BeanPair> getValuesFromBeanParam(Object bean, Class<? extends Annotation> annClass) { Map<String, BeanPair> values = new HashMap<String, BeanPair>(); for (Method m : bean.getClass().getMethods()) { Annotation annotation = m.getAnnotation(annClass); if (annotation != null) { try { String propertyName = m.getName().substring(3); Method getter = bean.getClass().getMethod("get" + propertyName, new Class[]{}); Object value = getter.invoke(bean, new Object[]{}); if (value != null) { String annotationValue = AnnotationUtils.getAnnotationValue(annotation); values.put(annotationValue, new BeanPair(value, m.getParameterAnnotations()[0])); } } catch (Throwable t) { // ignore } } } return values; }
public static Method getAnnotatedMethod(Class<?> serviceClass, Method m) { Method annotatedMethod = doGetAnnotatedMethod(serviceClass, m); return annotatedMethod == null ? m : annotatedMethod; }
private void checkMediaTypes(String consumeMediaTypes, String produceMediaTypes) { if (consumeMediaTypes != null) { consumeMimes = JAXRSUtils.sortMediaTypes(consumeMediaTypes, null); } else { Consumes cm = AnnotationUtils.getMethodAnnotation(annotatedMethod, Consumes.class); if (cm != null) { consumeMimes = JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(cm.value()), null); } else if (classResourceInfo != null) { consumeMimes = JAXRSUtils.sortMediaTypes(classResourceInfo.getConsumeMime(), null); } } if (produceMediaTypes != null) { produceMimes = JAXRSUtils.sortMediaTypes(produceMediaTypes, JAXRSUtils.MEDIA_TYPE_QS_PARAM); } else { Produces pm = AnnotationUtils.getMethodAnnotation(annotatedMethod, Produces.class); if (pm != null) { produceMimes = JAXRSUtils.sortMediaTypes(JAXRSUtils.getMediaTypes(pm.value()), JAXRSUtils.MEDIA_TYPE_QS_PARAM); } else if (classResourceInfo != null) { produceMimes = JAXRSUtils.sortMediaTypes(classResourceInfo.getProduceMime(), JAXRSUtils.MEDIA_TYPE_QS_PARAM); } } }
private static void evaluateResourceClass(ClassResourceInfo cri, boolean enableStatic) { MethodDispatcher md = new MethodDispatcher(); Class<?> serviceClass = cri.getServiceClass(); final Set<Method> annotatedMethods = new HashSet<>(); for (Method m : serviceClass.getMethods()) { if (!m.isBridge() && !m.isSynthetic()) { //do real methods first Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m); if (!annotatedMethods.contains(annotatedMethod)) { evaluateResourceMethod(cri, enableStatic, md, m, annotatedMethod); annotatedMethods.add(annotatedMethod); } } } for (Method m : serviceClass.getMethods()) { if (m.isBridge() || m.isSynthetic()) { //if a bridge/synthetic method isn't already mapped to something, go ahead and do it Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(serviceClass, m); if (!annotatedMethods.contains(annotatedMethod)) { evaluateResourceMethod(cri, enableStatic, md, m, annotatedMethod); annotatedMethods.add(annotatedMethod); } } } cri.setMethodDispatcher(md); }
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);
for (int i = 0; i < params.length; i++) { if (!perRequest) { if (AnnotationUtils.getAnnotation(anns[i], Context.class) == null) { match = false; break; } else if (!AnnotationUtils.isValidParamAnnotations(anns[i])) { match = false; break;
private void checkEncoded() { encoded = AnnotationUtils.getMethodAnnotation(annotatedMethod, Encoded.class) != null; if (!encoded && classResourceInfo != null) { encoded = AnnotationUtils.getClassAnnotation(classResourceInfo.getServiceClass(), Encoded.class) != null; } }
if (AnnotationUtils.isMethodAnnotation(a)) { return m; if (isValidParamAnnotations(paramAnnotations)) { LOG.warning("Method " + m.getName() + " in " + m.getDeclaringClass().getName() + " has no JAX-RS Path or HTTP Method annotations"); if (superC != null && Object.class != superC) { try { Method method = doGetAnnotatedMethod(serviceClass, superC.getMethod(m.getName(), m.getParameterTypes())); if (method != null) { Method method = doGetAnnotatedMethod(serviceClass, i.getMethod(m.getName(), m.getParameterTypes())); if (method != null) { for (Class<?> i : serviceClass.getInterfaces()) { try { Method method = doGetAnnotatedMethod(serviceClass, i.getMethod(m.getName(), m.getParameterTypes())); if (method != null) {
protected boolean getValuesFromBeanParamField(Object bean, Field f, Class<? extends Annotation> annClass, Map<String, BeanPair> values) { boolean jaxrsParamAnnAvailable = false; Annotation fieldAnnotation = f.getAnnotation(annClass); if (fieldAnnotation != null) { jaxrsParamAnnAvailable = true; Object value = ReflectionUtil.accessDeclaredField(f, bean, Object.class); if (value != null) { String annotationValue = AnnotationUtils.getAnnotationValue(fieldAnnotation); values.put(annotationValue, new BeanPair(value, f.getAnnotations())); } } return jaxrsParamAnnAvailable; }
public static Method getAnnotatedMethod(Class<?> serviceClass, Method m) { Method annotatedMethod = doGetAnnotatedMethod(serviceClass, m); return annotatedMethod == null ? m : annotatedMethod; }