Class ResourceAnalyzer
- Since:
- 25.09.2025
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ResourceMethodInfoanalyzeMethodCall(Class<T> resource, Caller<T> consumer) Use resource method call to collect data, required to call this rest method (like method path, query or path params).static ResourceMethodInfoanalyzeMethodCall(MethodCall call) Analyze resource method, using method call arguments.static ResourceMethodInfoanalyzeSingleCall(MethodCall call) Analyze method call, ignoring sub callsMethodCall.getSubCall().static MethodfindAnnotatedMethod(Method method) Search method, annotated withPath.static Class<?>findAnnotatedResource(Class<?> resource) Search for the actual resource annotations source (might be superclass of interface).static StringfindHttpMethod(Method method) Resolve http method by searching for method annotations likeGETorPOST.static MethodfindMethod(Class<?> resource, String method) Search for method with provided name in resource.static MethodfindMethod(Class<?> resource, String methodName, Class<?>... parameters) Shortcut forclass.getMethod(Par1.class, Par2.class).getHttpMethod(Method method) Search http annotations on method (likeGET).static StringgetMethodPath(Class<?> resource, String method) Search for resource method@Pathannotation.static StringgetMethodPath(Method method) Search for the actual annotated method (could be superclass or interface) and read the configured path.static StringgetResourcePath(Class<?> resource) Search forPathannotation on resource class or it's superclasses or interfaces.static booleanisJerseyAnnotated(Method method) Check if provided method is annotated with jersey annotations.static voidvalidateResourceMethod(Class<?> resource, Method method) Check that provided method belongs to resource class hierarchy (it might be superclass method or interface method).
-
Method Details
-
validateResourceMethod
Check that provided method belongs to resource class hierarchy (it might be superclass method or interface method).- Parameters:
resource- resource classmethod- target method to verify
-
getResourcePath
Search forPathannotation on resource class or it's superclasses or interfaces.The result is normalized: will always start with slash and will never end with slash (simpler for concatenation).
- Parameters:
resource- resource class to analyze- Returns:
- path annotation value
- Throws:
IllegalStateException- if path annotation is not found on a resource or any of it's super classes and interfaces
-
getMethodPath
Search for the actual annotated method (could be superclass or interface) and read the configured path.The result is normalized: will always start with slash and will never end with slash (simpler for concatenation).
- Parameters:
method- resource method- Returns:
- value of
Pathannotation on metho - Throws:
IllegalStateException- if annotation not found
-
getMethodPath
Search for resource method@Pathannotation. If multiple methods selected, will select method without arguments. If there is no matching no-args method found throws exception (about multiple methods found).- Parameters:
resource- resource classmethod- method name- Returns:
- resource method
@Pathannotation value - Throws:
IllegalStateException- if method with annotations not found
-
findAnnotatedResource
Search for the actual resource annotations source (might be superclass of interface).- Parameters:
resource- resource class- Returns:
- resource class or its superclass or interface where
Pathannotation declared
-
findMethod
Shortcut forclass.getMethod(Par1.class, Par2.class).- Parameters:
resource- resource classmethodName- method nameparameters- method parameter types- Returns:
- method instance
- Throws:
IllegalStateException- when method not found
-
findMethod
Search for method with provided name in resource. If multiple methods selected, will select method without arguments. If there is no matching no-args method found throws exception (about multiple methods found). This no-args behavior is required to comply with arguments-based search (it would be otherwise impossible to search for no-args method).Returned method might be not the resource method, but a super method from a subclass or interface, where jersey annotations declared.
- Parameters:
resource- resource clasmethod- method name- Returns:
- resource method with jersey annotations
- Throws:
IllegalStateException- if the method is not found or multiple methods found
-
findAnnotatedMethod
Search method, annotated withPath. Jersey supports declaring annotations in superclass or on interface, so the resource method may miss actual annotations.- Parameters:
method- method to search annotated for- Returns:
- annotated method
- Throws:
IllegalStateException- if method with annotations not found
-
isJerseyAnnotated
Check if provided method is annotated with jersey annotations. Http methods must have http method annotation (likeGET), but may lackPathannotation. Sub-resource lookup method must haveannotation. So target method must be checked to contain one of possible annotations.Note that it is impossible to have Path and http method annotation on different methods (jersey requirement).
- Parameters:
method- method to check- Returns:
- true if method contains jersey annotations
-
findHttpMethod
Resolve http method by searching for method annotations likeGETorPOST.WARNING: does not search the correct annotated method (see
findAnnotatedMethod(java.lang.reflect.Method)) - assumed correct method was already found.- Parameters:
method- method to read annotations on- Returns:
- http method string (from method annotations)
- Throws:
IllegalStateException- if annotation not found
-
getHttpMethod
Search http annotations on method (likeGET).- Parameters:
method- method to find annotation on- Returns:
- http method or null
-
analyzeMethodCall
Use resource method call to collect data, required to call this rest method (like method path, query or path params). Method associate provided method arguments with data required for call (like pre-declared query or path params).Provided consumer must call one resource method with any arguments:
analyzeMethod(Res.class, Res mock -> mock.someMethod(12, "foo", null))where resource method is:Response someMethod(@QueryParam("p1") int p1, @PathParam("pp") String pp, @Context UriInfo info. From the call above we can:- find
Pathmethod annotation to get the path - find http method annotation
- record required query param value: p1=12
- record required path param value: pp="foo"
Sub method calls assumed to be a sub-resource calls like
resource.subResource(args).method(args). For sub-resource calls, returned info will contain root resource as base resource, but resource method path will include all paths from locator methods (class-levelPathannotation is ignored for sub-resources!).- Type Parameters:
T- resource type- Parameters:
resource- resource classconsumer- consumer calling exactly one resource method- Returns:
- method analysis info
- find
-
analyzeMethodCall
Analyze resource method, using method call arguments. Recognize query params, path params, headers, cookies, etc. from method parameter annotations for non-null arguments.Sub method calls assumed to be a sub-resource calls like
resource.subResource(args).method(args). For sub-resource calls, returned info will contain root resource as base resource, but resource method path will include all paths from locator methods (class-levelPathannotation is ignored for sub-resources!).Method call could be intercepted with
ResourceMethodLookup.getMethodCalls(Class, ru.vyarus.dropwizard.guice.url.util.Caller).- Parameters:
call- intercepted method call- Returns:
- analysis result
-
analyzeSingleCall
Analyze method call, ignoring sub callsMethodCall.getSubCall(). SeeanalyzeMethodCall(MethodCall)for complete analysis.- Parameters:
call- method call- Returns:
- single call analysis info
-