void configureEndpoints ( Reflections reflections ) { // [Re]initialise the api: api = new HashMap <> ( ) ; log . info ( "Scanning for endpoint classes.." ) ; Set < Class < ? > > endpoints = reflections . getTypesAnnotatedWith ( Api . class ) ; // log.info(reflections.getConfiguration().getUrls()); log . info ( "Found {} endpoint classes." , endpoints . size ( ) ) ; log . info ( "Examining endpoint class methods:" ) ; // Configure the classes: for ( Class < ? > endpointClass : endpoints ) { Route route = getEndpoint ( endpointClass ) ; route . endpointClass = endpointClass ; for ( Method method : endpointClass . getMethods ( ) ) { // Skip Object methods if ( method . getDeclaringClass ( ) == Object . class ) { continue ; } // Find public methods: if ( Modifier . isPublic ( method . getModifiers ( ) ) ) { // Which HTTP method(s) will this method respond to? annotation : for ( Annotation annotation : method . getAnnotations ( ) ) { HttpMethod httpMethod = HttpMethod . method ( annotation ) ; if ( httpMethod != null ) { log . info ( "Http method: {}" , httpMethod ) ; RequestHandler requestHandler = new RequestHandler ( ) ; requestHandler . handlerMethod = method ; log . info ( "Java method: {}" , method . getName ( ) ) ; // Look for an optional Json message type parameter: for ( Class < ? > parameterType : method . getParameterTypes ( ) ) { if ( ! HttpServletRequest . class . isAssignableFrom ( parameterType ) && ! HttpServletResponse . class . isAssignableFrom ( parameterType ) ) { if ( requestHandler . requestMessageType != null ) { log . error ( "Too many parameters on {} method {}. " + "Message type already set to {} but also found a {} parameter." , httpMethod , method . getName ( ) , requestHandler . requestMessageType . getSimpleName ( ) , parameterType . getSimpleName ( ) ) ; break annotation ; } requestHandler . requestMessageType = parameterType ; log . info ( "request Json: {}" , requestHandler . requestMessageType . getSimpleName ( ) ) ; } } // Check the response Json message type: if ( method . getReturnType ( ) != void . class ) { requestHandler . responseMessageType = method . getReturnType ( ) ; log . info ( "Response Json: {}" , requestHandler . responseMessageType . getSimpleName ( ) ) ; } route . requestHandlers . put ( httpMethod , requestHandler ) ; } } } } } }
Searches for and configures all your lovely endpoints .