public static Map < RouteDefinition , Method > get ( Class clazz ) { Map < RouteDefinition , Method > out = new HashMap <> ( ) ; Map < RouteDefinition , Method > candidates = collect ( clazz ) ; // Final check if definitions are OK for ( RouteDefinition definition : candidates . keySet ( ) ) { if ( definition . getMethod ( ) == null ) { // skip non REST methods continue ; } Method method = candidates . get ( definition ) ; Assert . notNull ( definition . getRoutePath ( ) , getClassMethod ( clazz , method ) + " - Missing route @Path!" ) ; int bodyParamCount = 0 ; for ( MethodParameter param : definition . getParameters ( ) ) { if ( bodyParamCount > 0 && ( ParameterType . body . equals ( param . getType ( ) ) || ParameterType . unknown . equals ( param . getType ( ) ) ) ) { // OK we have to body params ... throw new IllegalArgumentException ( getClassMethod ( clazz , method ) + " - to many body arguments given. " + "Missing argument annotation (@PathParam, @QueryParam, @FormParam, @HeaderParam, @CookieParam or @Context) for: " + param . getType ( ) + " " + param . getName ( ) + "!" ) ; } if ( ParameterType . unknown . equals ( param . getType ( ) ) ) { // proclaim as body param // check if method allows for a body param Assert . isTrue ( definition . requestHasBody ( ) , getClassMethod ( clazz , method ) + " - " + "Missing argument annotation (@PathParam, @QueryParam, @FormParam, @HeaderParam, @CookieParam or @Context) for: " + param . getName ( ) + "!" ) ; param . setType ( ParameterType . body ) ; } if ( ParameterType . body . equals ( param . getType ( ) ) ) { bodyParamCount ++ ; } } out . put ( definition , method ) ; } return out ; }
Extracts all JAX - RS annotated methods from class and all its subclasses and interfaces