private static String createFingerprintForUrl ( final URI url ) { StringBuilder truncatedUrl = new StringBuilder ( url . getHost ( ) ) ; String path = url . getPath ( ) ; if ( path != null ) { truncatedUrl . append ( path ) ; } String query = url . getQuery ( ) ; if ( query != null ) { truncatedUrl . append ( "?" ) ; String [ ] queryParams = url . getQuery ( ) . split ( "&" ) ; List < String > queryParamList = Arrays . asList ( queryParams ) ; queryParamList . stream ( ) . sorted ( String :: compareToIgnoreCase ) . forEachOrdered ( truncatedUrl :: append ) ; } return DigestUtils . sha256Hex ( truncatedUrl . toString ( ) ) ; }
Creates the fingerprint of the given URL . If the URL contains query parameters it sorts them . This way URLs with different order of query parameters get the same fingerprint .