private void checkForNonPublicMethodIssues() { final MethodList allDeclaredMethods = new MethodList(getAllDeclaredMethods(handlerClass)); // non-public resource methods for (AnnotatedMethod m : allDeclaredMethods.withMetaAnnotation(HttpMethod.class) .withoutAnnotation(Path.class).isNotPublic()) { Errors.warning(handlerClass, LocalizationMessages.NON_PUB_RES_METHOD(m.getMethod().toGenericString())); } // non-public sub-resource methods for (AnnotatedMethod m : allDeclaredMethods.withMetaAnnotation(HttpMethod.class) .withAnnotation(Path.class).isNotPublic()) { Errors.warning(handlerClass, LocalizationMessages.NON_PUB_SUB_RES_METHOD(m.getMethod().toGenericString())); } // non-public sub-resource locators for (AnnotatedMethod m : allDeclaredMethods.withoutMetaAnnotation(HttpMethod.class) .withAnnotation(Path.class).isNotPublic()) { Errors.warning(handlerClass, LocalizationMessages.NON_PUB_SUB_RES_LOC(m.getMethod().toGenericString())); } }
/** * Get a new sub-list of methods containing all the methods from this method * list that are not public. * * @return new filtered method sub-list. */ public MethodList isNotPublic() { return filter(new Filter() { @Override public boolean keep(AnnotatedMethod m) { return !Modifier.isPublic(m.getMethod().getModifiers()); } }); }
/** * Create new method list for a class. * * The method list contains {@link Class#getMethods() all methods} available * on the class or {@link Class#getDeclaredMethods() declared methods} only, * depending on the value of the {@code declaredMethods} parameter. * * The {@link Method#isBridge() bridge methods} and methods declared directly * on the {@link Object} class are filtered out. * * @param c class from which the method list is created. * @param declaredMethods if {@code true} only the {@link Class#getDeclaredMethods() * declared methods} will be included in the method list; otherwise * {@link Class#getMethods() all methods} will be listed. */ public MethodList(Class<?> c, boolean declaredMethods) { this(declaredMethods ? getAllDeclaredMethods(c) : getMethods(c)); }
private void checkResourceClassSetters(final MethodList methodList, final boolean encodedFlag, Collection<Parameter> injectableParameters) { for (AnnotatedMethod method : methodList.withoutMetaAnnotation(HttpMethod.class) .withoutAnnotation(Path.class) .hasNumParams(1) .hasReturnType(void.class) .nameStartsWith("set")) { Parameter p = Parameter.create( handlerClass, method.getMethod().getDeclaringClass(), encodedFlag || method.isAnnotationPresent(Encoded.class), method.getParameterTypes()[0], method.getGenericParameterTypes()[0], method.getAnnotations()); if (null != p) { ResourceMethodValidator.validateParameter(p, method.getMethod(), method.getMethod().toGenericString(), "1", InvocableValidator.isSingleton(handlerClass)); // we do not inject entity parameters into class instance fields and properties. if (p.getSource() != Parameter.Source.ENTITY) { injectableParameters.add(p); } } } }
private void addResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withoutAnnotation(Path.class)) { ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
private void addSubResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { Resource.Builder childResourceBuilder = resourceBuilder.addChildResource(am.getAnnotation(Path.class).value()); ResourceMethod.Builder methodBuilder = childResourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
private void addSubResourceLocators( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final boolean extended) { for (AnnotatedMethod am : methodList.withoutMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { final String path = am.getAnnotation(Path.class).value(); Resource.Builder builder = resourceBuilder; if (path != null && !path.isEmpty() && !"/".equals(path)) { builder = resourceBuilder.addChildResource(path); } builder.addMethod() .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); } } }
/** * Created a new method list containing only the methods supported by the * {@link Filter method list filter}. * * @param filter method list filter. * * @return new filtered method list. */ public MethodList filter(Filter filter) { List<AnnotatedMethod> result = new ArrayList<>(); for (AnnotatedMethod m : methods) { if (filter.keep(m)) { result.add(m); } } return new MethodList(result.toArray(new AnnotatedMethod[result.size()])); } }
MethodList methods = new MethodList(link.resource()); methods = methods.withMetaAnnotation(HttpMethod.class); for (AnnotatedMethod method : methods) { if (!Objects.equals(method.getMethod().getName(), link.method())) {
private void checkResourceClassSetters(final MethodList methodList, final boolean encodedFlag, Collection<Parameter> injectableParameters) { for (AnnotatedMethod method : methodList.withoutMetaAnnotation(HttpMethod.class) .withoutAnnotation(Path.class) .hasNumParams(1) .hasReturnType(void.class) .nameStartsWith("set")) { Parameter p = Parameter.create( handlerClass, method.getMethod().getDeclaringClass(), encodedFlag || method.isAnnotationPresent(Encoded.class), method.getParameterTypes()[0], method.getGenericParameterTypes()[0], method.getAnnotations()); if (null != p) { ResourceMethodValidator.validateParameter(p, method.getMethod(), method.getMethod().toGenericString(), "1", InvocableValidator.isSingleton(handlerClass)); // we do not inject entity parameters into class instance fields and properties. if (p.getSource() != Parameter.Source.ENTITY) { injectableParameters.add(p); } } } }
private void addResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withoutAnnotation(Path.class)) { ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
private void addSubResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { Resource.Builder childResourceBuilder = resourceBuilder.addChildResource(am.getAnnotation(Path.class).value()); ResourceMethod.Builder methodBuilder = childResourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
private void addSubResourceLocators( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final boolean extended) { for (AnnotatedMethod am : methodList.withoutMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { final String path = am.getAnnotation(Path.class).value(); Resource.Builder builder = resourceBuilder; if (path != null && !path.isEmpty() && !"/".equals(path)) { builder = resourceBuilder.addChildResource(path); } builder.addMethod() .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); } } }
/** * Created a new method list containing only the methods supported by the * {@link Filter method list filter}. * * @param filter method list filter. * * @return new filtered method list. */ public MethodList filter(Filter filter) { List<AnnotatedMethod> result = new ArrayList<>(); for (AnnotatedMethod m : methods) { if (filter.keep(m)) { result.add(m); } } return new MethodList(result.toArray(new AnnotatedMethod[result.size()])); } }
private void checkForNonPublicMethodIssues() { final MethodList allDeclaredMethods = new MethodList(getAllDeclaredMethods(handlerClass)); // non-public resource methods for (AnnotatedMethod m : allDeclaredMethods.withMetaAnnotation(HttpMethod.class) .withoutAnnotation(Path.class).isNotPublic()) { Errors.warning(handlerClass, LocalizationMessages.NON_PUB_RES_METHOD(m.getMethod().toGenericString())); } // non-public sub-resource methods for (AnnotatedMethod m : allDeclaredMethods.withMetaAnnotation(HttpMethod.class) .withAnnotation(Path.class).isNotPublic()) { Errors.warning(handlerClass, LocalizationMessages.NON_PUB_SUB_RES_METHOD(m.getMethod().toGenericString())); } // non-public sub-resource locators for (AnnotatedMethod m : allDeclaredMethods.withoutMetaAnnotation(HttpMethod.class) .withAnnotation(Path.class).isNotPublic()) { Errors.warning(handlerClass, LocalizationMessages.NON_PUB_SUB_RES_LOC(m.getMethod().toGenericString())); } }
private void checkResourceClassSetters(final MethodList methodList, final boolean encodedFlag, Collection<Parameter> injectableParameters) { for (AnnotatedMethod method : methodList.withoutMetaAnnotation(HttpMethod.class) .withoutAnnotation(Path.class) .hasNumParams(1) .hasReturnType(void.class) .nameStartsWith("set")) { Parameter p = Parameter.create( handlerClass, method.getMethod().getDeclaringClass(), encodedFlag || method.isAnnotationPresent(Encoded.class), method.getParameterTypes()[0], method.getGenericParameterTypes()[0], method.getAnnotations()); if (null != p) { ResourceMethodValidator.validateParameter(p, method.getMethod(), method.getMethod().toGenericString(), "1", InvocableValidator.isSingleton(handlerClass)); // we do not inject entity parameters into class instance fields and properties. if (p.getSource() != Parameter.Source.ENTITY) { injectableParameters.add(p); } } } }
/** * Get a new sub-list of methods containing all the methods from this method * list that are not public. * * @return new filtered method sub-list. */ public MethodList isNotPublic() { return filter(new Filter() { @Override public boolean keep(AnnotatedMethod m) { return !Modifier.isPublic(m.getMethod().getModifiers()); } }); }
private void addResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withoutAnnotation(Path.class)) { ResourceMethod.Builder methodBuilder = resourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
private void addSubResourceMethods( final Resource.Builder resourceBuilder, final MethodList methodList, final List<Parameter> resourceClassParameters, // parameters derived from fields and setters on the resource class final boolean encodedParameters, final List<MediaType> defaultConsumedTypes, final List<MediaType> defaultProducedTypes, final Collection<Class<? extends Annotation>> defaultNameBindings, final boolean extended ) { for (AnnotatedMethod am : methodList.withMetaAnnotation(HttpMethod.class).withAnnotation(Path.class)) { Resource.Builder childResourceBuilder = resourceBuilder.addChildResource(am.getAnnotation(Path.class).value()); ResourceMethod.Builder methodBuilder = childResourceBuilder.addMethod(am.getMetaMethodAnnotations(HttpMethod.class).get(0).value()) .consumes(resolveConsumedTypes(am, defaultConsumedTypes)) .produces(resolveProducedTypes(am, defaultProducedTypes)) .encodedParameters(encodedParameters || am.isAnnotationPresent(Encoded.class)) .nameBindings(defaultNameBindings) .nameBindings(am.getAnnotations()) .handledBy(handlerClass, am.getMethod()) .handlingMethod(am.getDeclaredMethod()) .handlerParameters(resourceClassParameters) .extended(extended || am.isAnnotationPresent(ExtendedResource.class)); introspectAsyncFeatures(am, methodBuilder); } }
/** * Create new method list for a class. * * The method list contains {@link Class#getMethods() all methods} available * on the class or {@link Class#getDeclaredMethods() declared methods} only, * depending on the value of the {@code declaredMethods} parameter. * * The {@link Method#isBridge() bridge methods} and methods declared directly * on the {@link Object} class are filtered out. * * @param c class from which the method list is created. * @param declaredMethods if {@code true} only the {@link Class#getDeclaredMethods() * declared methods} will be included in the method list; otherwise * {@link Class#getMethods() all methods} will be listed. */ public MethodList(Class<?> c, boolean declaredMethods) { this(declaredMethods ? getAllDeclaredMethods(c) : getMethods(c)); }