String hostName;
try {
hostName = NetworkUtils.getLocalHostname();
} catch (SocketException e) {
throw new UsageException("Error getting host name for the registry usage event payload",
e);
}
ConfigurationContextService configurationContextService = PublisherUtils.
getConfigurationContextService();
ConfigurationContext configurationContext;
if (configurationContextService != null) {
configurationContext = configurationContextService.getServerConfigContext();
} else {
throw new UsageException("ConfigurationContext is null");
}
// int port = CarbonUtils.getTransportPort(configurationContext, "https");
String carbonHttpsPort = System.getProperty("carbon." + TRANSPORT + ".port");
if (carbonHttpsPort == null) {
carbonHttpsPort = Integer.toString(
CarbonUtils.getTransportPort(configurationContext, TRANSPORT));
}
String baseServerUrl = TRANSPORT + "://" + hostName + ":" + carbonHttpsPort;
String context = configurationContext.getContextRoot();
String tenantDomain = null;
try {
Tenant tenant = Util.getRealmService().getTenantManager().getTenant(tenantId);
if(tenant!=null){
tenantDomain = tenant.getDomain();
}
} catch (org.wso2.carbon.user.api.UserStoreException e) {
throw new UsageException("Failed to get tenant domain", e);
}
if ((tenantDomain != null) &&
!(tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME))) {
serverName = baseServerUrl + context + "t/" + tenantDomain;