List of usage examples for com.google.common.net InternetDomainName name
String name
To view the source code for com.google.common.net InternetDomainName name.
Click Source Link
From source file:edu.uga.cs.fluxbuster.utils.DomainNameUtils.java
/** * Extracts the effective second level domain name. * * @param domainname the full domain name * @return the second level domain name or null on error */// w ww .jav a2s .c o m public static String extractEffective2LD(String domainname) { String retval = null; try { InternetDomainName idn = InternetDomainName.from(domainname); InternetDomainName sld = idn.topPrivateDomain(); retval = sld.name(); } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("Unable to extract 2LD.", e); } } return retval; }
From source file:org.jclouds.rest.binders.BindAsHostPrefix.java
@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();//from www. j a v a 2s . co m }
From source file:org.apache.commons.httpclient.cookie.CookieSpecBase.java
/** * Return an array of {@link Cookie}s that should be submitted with a * request with given attributes, <tt>false</tt> otherwise. * //w ww . j a va2s.co m * If the SortedMap comes from an HttpState and is not itself * thread-safe, it may be necessary to synchronize on the HttpState * instance to protect against concurrent modification. * * @param host the host to which the request is being submitted * @param port the port to which the request is being submitted (currently * ignored) * @param path the path to which the request is being submitted * @param secure <tt>true</tt> if the request is using a secure protocol * @param cookies SortedMap of <tt>Cookie</tt>s to be matched * @return an array of <tt>Cookie</tt>s matching the criterium */ @Override public Cookie[] match(String host, int port, String path, boolean secure, final SortedMap<String, Cookie> cookies) { LOG.trace("enter CookieSpecBase.match(" + "String, int, String, boolean, SortedMap)"); if (cookies == null) { return null; } List<Cookie> matching = new LinkedList<Cookie>(); InternetDomainName domain; try { domain = InternetDomainName.fromLenient(host); } catch (IllegalArgumentException e) { domain = null; } String candidate = (domain != null) ? domain.name() : host; while (candidate != null) { Iterator<Cookie> iter = cookies.subMap(candidate, candidate + Cookie.DOMAIN_OVERBOUNDS).values() .iterator(); while (iter.hasNext()) { Cookie cookie = (Cookie) (iter.next()); if (match(host, port, path, secure, cookie)) { addInPathOrder(matching, cookie); } } StoredIterator.close(iter); if (domain != null && domain.isUnderPublicSuffix()) { domain = domain.parent(); candidate = domain.name(); } else { candidate = null; } } return (Cookie[]) matching.toArray(new Cookie[matching.size()]); }