*/
public CloudApplicationURL getCloudApplicationURL(String url) throws CoreException {
IStatus isValidStatus = simpleValidation(url);
if (!isValidStatus.isOK()) {
throw new CoreException(isValidStatus);
}
if (domainsPerActiveSpace == null || domainsPerActiveSpace.isEmpty()) {
throw new CoreException(
CloudFoundryPlugin
.getErrorStatus(Messages.ApplicationUrlLookupService_ERROR_GET_CLOUD_URL));
}
// String url = domain.getName();
// url = url.replace("http://", "");
URI newUri;
try {
newUri = URI.create(url);
}
catch (IllegalArgumentException e) {
throw new CoreException(CloudFoundryPlugin.getErrorStatus(e));
}
String authority = newUri.getScheme() != null ? newUri.getAuthority() : newUri.getPath();
String parsedDomainName = null;
String parsedSubdomainName = null;
if (authority != null) {
for (CloudDomain domain : domainsPerActiveSpace) {
// Be sure to check for last segment rather than last String
// value
// otherwise: Example: "validdomain" is a valid domain:
// sub.domainvaliddomain will be parsed
// successfully as a valid application URL, even though
// "domainvaliddomain" is not a valid domain. Instead, this
// should be the correct
// URL: sub.domain.validdomain. A URL with just "validdomain"
// should also
// parse the domain part correctly (but no subdomain)
String domainName = domain.getName();
String domainSegment = '.' + domainName;
if (authority.equals(domainName)) {
parsedDomainName = domainName;
break;
}
else if (authority.endsWith(domainSegment)) {
parsedDomainName = domainName;
// Any portion of the authority before the separating '.' is
// the
// subdomain. To avoid including the separating '.' between
// subdomain and domain itself as being part of the
// subdomain, only parse the subdomain if there
// is an actual '.' before the domain value in the authority
if (domainSegment.length() < authority.length()) {
parsedSubdomainName = authority.substring(0, authority.lastIndexOf(domainSegment));
}
break;
}
}
}
if (parsedDomainName == null || parsedDomainName.trim().length() == 0) {
throw new CoreException(CloudFoundryPlugin.getErrorStatus(NLS.bind(
Messages.ERROR_NO_DOMAIN_RESOLVED_FOR_URL, url)));
}
if (parsedSubdomainName == null || parsedSubdomainName.trim().length() == 0l) {
throw new CoreException(CloudFoundryPlugin.getErrorStatus(NLS.bind(Messages.ERROR_INVALID_SUBDOMAIN, url,
parsedDomainName)));
}
return new CloudApplicationURL(parsedSubdomainName, parsedDomainName);
}