public HandlerInfo getHandler ( String requestURL ) { Iterator < HandlerPath > keys = handlerKeys . iterator ( ) ; if ( requestURL == null || keys == null ) { return null ; } // Check to see if we have a direct hit Iterator < ServiceAndServiceReferencePair < RESTHandler > > itr = handlerMap . getServicesWithReferences ( requestURL ) ; if ( itr != null && itr . hasNext ( ) ) { ServiceAndServiceReferencePair < RESTHandler > handler = itr . next ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Found direct URL match: " + handler ) ; } return new HandlerInfo ( handler . getService ( ) , handler . getServiceReference ( ) ) ; } // If no direct match, then try to match each one. Longest match wins. HandlerPath bestMatchRoot = null ; while ( keys . hasNext ( ) ) { HandlerPath key = keys . next ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Checking HandlerPath: " + key . getRegisteredPath ( ) + " | length: " + key . length ( ) ) ; } if ( key . matches ( requestURL ) ) { if ( bestMatchRoot == null || key . length ( ) > bestMatchRoot . length ( ) ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "New best match: " + key . getRegisteredPath ( ) ) ; } bestMatchRoot = key ; } } } // If we found a match... if ( bestMatchRoot != null ) { // Get the iterator. We MUST check hasNext first, because of how // the underlying implementation is written. itr = handlerMap . getServicesWithReferences ( bestMatchRoot . getRegisteredPath ( ) ) ; if ( itr != null && itr . hasNext ( ) ) { ServiceAndServiceReferencePair < RESTHandler > handler = itr . next ( ) ; if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( this , tc , "Final best handler: " + handler ) ; } return new HandlerInfo ( handler . getService ( ) , handler . getServiceReference ( ) , bestMatchRoot ) ; } } return null ; }
Try to find the appropriate RESTHandler and HandlerPath pair for the given URL . Return null if no match found . May return null for the HandlerPath field if the RESTHandler matched an URL that did not contain variables .