Code review comment: endpoint is a URL, it is possible that it also contains subpath, can we only override port value for the endpoint?

Code before review:
public WebPubSubAsyncServiceClient buildAsyncClient() {
if (hub == null || hub.isEmpty()) {
logger.logThrowableAsError(
new IllegalStateException("hub is not valid - it must be non-null and non-empty."));
}
if (endpoint == null && credential == null) {
final Map<String, String> csParams = parseConnectionString(connectionString);
if (!csParams.containsKey("endpoint") && !csParams.containsKey("accesskey")) {
logger.logThrowableAsError(new IllegalArgumentException(
"Connection string does not contain required 'endpoint' and 'accesskey' values"));
}
final String accessKey = csParams.get("accesskey");
this.credential = new AzureKeyCredential(accessKey);
this.endpoint = csParams.get("endpoint");
String port = csParams.get("port");
if (!CoreUtils.isNullOrEmpty(port)) {
this.endpoint = this.endpoint + ":" + port;
}
}
final AzureWebPubSubServiceRestAPIImplBuilder innerBuilder = new AzureWebPubSubServiceRestAPIImplBuilder();
if (endpoint == null || endpoint.isEmpty()) {
logger.logThrowableAsError(
new IllegalStateException("endpoint is not valid - it must be non-null and non-empty."));
}
innerBuilder.host(endpoint);
final WebPubSubServiceVersion serviceVersion =
version != null ? version : WebPubSubServiceVersion.getLatest();
WebPubSubAuthenticationPolicy webPubSubAuthPolicy = new WebPubSubAuthenticationPolicy(credential);
if (pipeline != null) {
innerBuilder.pipeline(pipeline);
return buildAsyncClient(innerBuilder, hub, endpoint, webPubSubAuthPolicy, serviceVersion);
}
if (credential == null) {
logger.logThrowableAsError(
new IllegalStateException("No credential has been specified - it must be non-null and non-empty."));
}
final Configuration buildConfiguration =
(configuration == null) ? Configuration.getGlobalConfiguration().clone() : configuration;
final String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
final String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
String applicationId =
clientOptions == null ? httpLogOptions.getApplicationId() : clientOptions.getApplicationId();
final List<HttpPipelinePolicy> policies = new ArrayList<>();
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion,
buildConfiguration));
policies.add(new CookiePolicy());
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy);
policies.add(webPubSubAuthPolicy);
policies.addAll(this.policies);
if (clientOptions != null) {
List<HttpHeader> httpHeaderList = new ArrayList<>();
clientOptions.getHeaders().forEach(header ->
httpHeaderList.add(new HttpHeader(header.getName(), header.getValue())));
policies.add(new AddHeadersPolicy(new HttpHeaders(httpHeaderList)));
}
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
innerBuilder.pipeline(new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.build());
return buildAsyncClient(innerBuilder, hub, endpoint, webPubSubAuthPolicy, serviceVersion);
}

Line under review: this.endpoint = this.endpoint + ":" + port;

Code after addressing the review:
public WebPubSubAsyncServiceClient buildAsyncClient() {
if (hub == null || hub.isEmpty()) {
logger.logThrowableAsError(
new IllegalStateException("hub is not valid - it must be non-null and non-empty."));
}
if (endpoint == null && credential == null) {
final Map<String, String> csParams = parseConnectionString(connectionString);
if (!csParams.containsKey("endpoint") && !csParams.containsKey("accesskey")) {
logger.logThrowableAsError(new IllegalArgumentException(
"Connection string does not contain required 'endpoint' and 'accesskey' values"));
}
final String accessKey = csParams.get("accesskey");
this.credential = new AzureKeyCredential(accessKey);
String csEndpoint = csParams.get("endpoint");
URL url;
try {
url = new URL(csEndpoint);
this.endpoint = csEndpoint;
} catch (MalformedURLException e) {
throw logger.logExceptionAsWarning(new IllegalArgumentException("Connection string contains invalid "
+ "endpoint", e));
}
String port = csParams.get("port");
if (!CoreUtils.isNullOrEmpty(port)) {
this.endpoint = UrlBuilder.parse(url).setPort(port).toString();
}
}
final AzureWebPubSubServiceRestAPIImplBuilder innerBuilder = new AzureWebPubSubServiceRestAPIImplBuilder();
if (endpoint == null || endpoint.isEmpty()) {
logger.logThrowableAsError(
new IllegalStateException("endpoint is not valid - it must be non-null and non-empty."));
}
innerBuilder.host(endpoint);
final WebPubSubServiceVersion serviceVersion =
version != null ? version : WebPubSubServiceVersion.getLatest();
WebPubSubAuthenticationPolicy webPubSubAuthPolicy = new WebPubSubAuthenticationPolicy(credential);
if (pipeline != null) {
innerBuilder.pipeline(pipeline);
return buildAsyncClient(innerBuilder, hub, endpoint, webPubSubAuthPolicy, serviceVersion);
}
if (credential == null) {
logger.logThrowableAsError(
new IllegalStateException("No credential has been specified - it must be non-null and non-empty."));
}
final Configuration buildConfiguration =
(configuration == null) ? Configuration.getGlobalConfiguration().clone() : configuration;
final String clientName = properties.getOrDefault(SDK_NAME, "UnknownName");
final String clientVersion = properties.getOrDefault(SDK_VERSION, "UnknownVersion");
String applicationId =
clientOptions == null ? httpLogOptions.getApplicationId() : clientOptions.getApplicationId();
final List<HttpPipelinePolicy> policies = new ArrayList<>();
policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion,
buildConfiguration));
policies.add(new CookiePolicy());
HttpPolicyProviders.addBeforeRetryPolicies(policies);
policies.add(retryPolicy == null ? DEFAULT_RETRY_POLICY : retryPolicy);
policies.add(webPubSubAuthPolicy);
policies.addAll(this.policies);
if (clientOptions != null) {
List<HttpHeader> httpHeaderList = new ArrayList<>();
clientOptions.getHeaders().forEach(header ->
httpHeaderList.add(new HttpHeader(header.getName(), header.getValue())));
policies.add(new AddHeadersPolicy(new HttpHeaders(httpHeaderList)));
}
HttpPolicyProviders.addAfterRetryPolicies(policies);
policies.add(new HttpLoggingPolicy(httpLogOptions));
innerBuilder.pipeline(new HttpPipelineBuilder()
.policies(policies.toArray(new HttpPipelinePolicy[0]))
.httpClient(httpClient)
.build());
return buildAsyncClient(innerBuilder, hub, endpoint, webPubSubAuthPolicy, serviceVersion);
}