protected URL getRoutingStrategyDestination ( Object request , Map < String , String > headers ) { for ( RequestRoutingStrategy routingStrategy : MdwServiceRegistry . getInstance ( ) . getRequestRoutingStrategies ( ) ) { URL destination = routingStrategy . getDestination ( request , headers ) ; if ( destination != null ) { // Only return a destination if it is not itself (identical call) - Avoid infinite loop // int queryIdx = destination.toString().indexOf("?"); URL origRequestUrl = null ; try { origRequestUrl = new URL ( headers . get ( Listener . METAINFO_REQUEST_URL ) ) ; } catch ( MalformedURLException e ) { logger . severeException ( "Malformed original RequestURL" , e ) ; } String origHost = origRequestUrl . getHost ( ) . indexOf ( "." ) > 0 ? origRequestUrl . getHost ( ) . substring ( 0 , origRequestUrl . getHost ( ) . indexOf ( "." ) ) : origRequestUrl . getHost ( ) ; int origPort = origRequestUrl . getPort ( ) == 80 || origRequestUrl . getPort ( ) == 443 ? - 1 : origRequestUrl . getPort ( ) ; String origQuery = headers . get ( Listener . METAINFO_REQUEST_QUERY_STRING ) == null ? "" : headers . get ( Listener . METAINFO_REQUEST_QUERY_STRING ) ; String newHost = destination . getHost ( ) . indexOf ( "." ) > 0 ? destination . getHost ( ) . substring ( 0 , destination . getHost ( ) . indexOf ( "." ) ) : destination . getHost ( ) ; int newPort = destination . getPort ( ) == 80 || destination . getPort ( ) == 443 ? - 1 : destination . getPort ( ) ; String newQuery = destination . getQuery ( ) == null ? "" : destination . getQuery ( ) ; if ( ! newHost . equalsIgnoreCase ( origHost ) || ! ( newPort == origPort ) || ! newQuery . equalsIgnoreCase ( origQuery ) || ! origRequestUrl . getPath ( ) . equals ( destination . getPath ( ) ) ) return destination ; } } return null ; }
Returns an instance of the first applicable routing strategy found based on priority of each strategy or null if none return a URL .