final InternetDomainName topPrivateDomain = InternetDomainName.from(uriHost).topPrivateDomain(); topPrivateDomain.name();
public static String hostToPublicSuffix(String host) { InternetDomainName idn; try { idn = InternetDomainName.fromLenient(host); } catch(IllegalArgumentException e) { return host; } InternetDomainName tmp = idn.publicSuffix(); if(tmp == null) { return host; } String pubSuff = tmp.name(); int idx = host.lastIndexOf(".", host.length() - (pubSuff.length()+2)); if(idx == -1) { return host; } return host.substring(idx+1); }
private String extractSlugFromHost(String host) { String rootDomain; String siteName = siteSettings.getWebDomainName().or(siteSettings.getDomainName()); if (Strings.emptyToNull(siteName) == null) { InternetDomainName domainName = InternetDomainName.from(host); if (domainName.hasPublicSuffix()) { // Domain is under a valid TLD, extract the TLD + first child rootDomain = domainName.topPrivateDomain().name(); } else if (host.indexOf(".") > 0 && host.indexOf(".") < host.length()) { // Otherwise, best guess : strip everything before the first dot. rootDomain = host.substring(host.indexOf(".") + 1); } else { rootDomain = host; } } else { rootDomain = StringUtils.substringBefore(siteSettings.getDomainName(), ":"); } if (host.indexOf("." + rootDomain) > 0) { return host.substring(0, host.indexOf("." + rootDomain)); } else { return host; } }
@Override @SuppressWarnings("unchecked") public <R extends HttpRequest> R bindToRequest(R request, Object payload) { checkNotNull(payload, "hostprefix"); checkArgument(isValid(request.getEndpoint().getHost()), "this is only valid for hostnames: " + request); InternetDomainName name = from(request.getEndpoint().getHost()).child(payload.toString()); return (R) request.toBuilder().endpoint(uriBuilder(request.getEndpoint()).host(name.name()).build()).build(); } }
@Override @SuppressWarnings("unchecked") public <R extends HttpRequest> R bindToRequest(R request, Object payload) { checkNotNull(payload, "hostprefix"); checkArgument(isValid(request.getEndpoint().getHost()), "this is only valid for hostnames: " + request); InternetDomainName name = from(request.getEndpoint().getHost()).child(payload.toString()); return (R) request.toBuilder().endpoint(uriBuilder(request.getEndpoint()).host(name.name()).build()).build(); } }
return new HostSpecifier(domain.name());
return new HostSpecifier(domain.name());
return new HostSpecifier(domain.name());
return new HostSpecifier(domain.name());
return new HostSpecifier(domain.name());
return new HostSpecifier(domain.name());
return new HostSpecifier(domain.name());