33import org .slf4j .Logger ;
44import org .slf4j .LoggerFactory ;
55
6- import java .net .MalformedURLException ;
76import java .net .URI ;
87import java .net .URISyntaxException ;
9- import java .net .URL ;
108
119class AddressNormalizer {
1210 private static final Logger logger = LoggerFactory .getLogger (AddressNormalizer .class );
@@ -22,10 +20,11 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
2220 throw new SDKException ("error trying to parse URL [" + urlString + "]" , e );
2321 }
2422
23+ final String scheme = usePlaintext ? "http" : "https" ;
2524 if (uri .getHost () == null ) {
2625 // if there is no host then we are likely dealing with a host and port
2726 try {
28- uri = new URI (usePlaintext ? "http" : "https" , null , uri .getScheme (), Integer .parseInt (uri .getSchemeSpecificPart ()), null , null , null );
27+ uri = new URI (scheme , null , uri .getScheme (), Integer .parseInt (uri .getSchemeSpecificPart ()), null , null , null );
2928 } catch (URISyntaxException e ) {
3029 throw new SDKException ("error trying to create URL for host and port[" + urlString + "]" , e );
3130 }
@@ -36,7 +35,6 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
3635 } else {
3736 port = uri .getPort ();
3837 }
39- final String scheme = usePlaintext ? "http" : "https" ;
4038
4139 try {
4240 var returnUrl = new URI (scheme , null , uri .getHost (), port , null , null , null ).toString ();
@@ -46,19 +44,4 @@ static String normalizeAddress(String urlString, boolean usePlaintext) {
4644 throw new SDKException ("error creating KAS address" , e );
4745 }
4846 }
49-
50- private static URI tryParseHostAndPort (String urlString ) {
51- URI uri ;
52- try {
53- uri = new URI (null , urlString , null , null , null ).parseServerAuthority ();
54- } catch (URISyntaxException e ) {
55- throw new SDKException ("error trying to parse host and port" , e );
56- }
57-
58- try {
59- return new URI (uri .getPort () == 443 ? "https" : "http" , null , uri .getHost (), uri .getPort (), "" , "" , "" );
60- } catch (URISyntaxException e ) {
61- throw new SDKException ("error trying to create URL from host and port" , e );
62- }
63- }
6447}
0 commit comments