protected UriComponents normalize ( final String resource ) { val builder = UriComponentsBuilder . newInstance ( ) ; val matcher = RESOURCE_NORMALIZED_PATTERN . matcher ( resource ) ; if ( ! matcher . matches ( ) ) { LOGGER . error ( "Unable to match the resource [{}] against pattern [{}] for normalization" , resource , matcher . pattern ( ) . pattern ( ) ) ; return null ; } builder . scheme ( matcher . group ( PATTERN_GROUP_INDEX_SCHEME ) ) ; builder . userInfo ( matcher . group ( PATTERN_GROUP_INDEX_USERINFO ) ) ; builder . host ( matcher . group ( PATTERN_GROUP_INDEX_HOST ) ) ; val port = matcher . group ( PATTERN_GROUP_INDEX_PORT ) ; if ( ! StringUtils . isBlank ( port ) ) { builder . port ( Integer . parseInt ( port ) ) ; } builder . path ( matcher . group ( PATTERN_GROUP_INDEX_PATH ) ) ; builder . query ( matcher . group ( PATTERN_GROUP_INDEX_QUERY ) ) ; builder . fragment ( matcher . group ( PATTERN_GROUP_INDEX_FRAGMENT ) ) ; val currentBuilder = builder . build ( ) ; if ( StringUtils . isBlank ( currentBuilder . getScheme ( ) ) ) { if ( ! StringUtils . isBlank ( currentBuilder . getUserInfo ( ) ) && StringUtils . isBlank ( currentBuilder . getPath ( ) ) && StringUtils . isBlank ( currentBuilder . getQuery ( ) ) && currentBuilder . getPort ( ) < 0 ) { builder . scheme ( "acct" ) ; } else { builder . scheme ( "https" ) ; } } builder . fragment ( null ) ; return builder . build ( ) ; }
Normalize uri components .