List of usage examples for com.google.common.net InternetDomainName from
public static InternetDomainName from(String domain)
From source file:org.archive.crawler.prefetch.HostQuotaEnforcer.java
@Override protected boolean shouldProcess(CrawlURI curi) { String uriHostname = serverCache.getHostFor(curi.getUURI()).getHostName(); if (getApplyToSubdomains() && InternetDomainName.isValid(host) && InternetDomainName.isValid(uriHostname)) { InternetDomainName h = InternetDomainName.from(host); InternetDomainName uriHostOrAncestor = InternetDomainName.from(uriHostname); while (true) { if (uriHostOrAncestor.equals(h)) { return true; }/*from w w w . j av a 2 s. com*/ if (uriHostOrAncestor.hasParent()) { uriHostOrAncestor = uriHostOrAncestor.parent(); } else { break; } } return false; } else { return serverCache.getHostFor(curi.getUURI()) == serverCache.getHostFor(host); } }
From source file:google.registry.dns.DnsQueue.java
/** * Adds a task to the queue to refresh the DNS information for the specified subordinate host. */// w ww . java2 s . co m public TaskHandle addHostRefreshTask(String fullyQualifiedHostName) { Optional<InternetDomainName> tld = Registries .findTldForName(InternetDomainName.from(fullyQualifiedHostName)); checkArgument(tld.isPresent(), String.format("%s is not a subordinate host to a known tld", fullyQualifiedHostName)); return addToQueue(TargetType.HOST, fullyQualifiedHostName, tld.get().toString()); }
From source file:google.registry.dns.PublishDnsUpdatesAction.java
/** Steps through the domain and host refreshes contained in the parameters and processes them. */ private void processBatch() { try (DnsWriter writer = dnsWriterProxy.getForTld(tld)) { for (String domain : nullToEmpty(domains)) { if (!DomainNameUtils.isUnder(InternetDomainName.from(domain), InternetDomainName.from(tld))) { dnsMetrics.incrementPublishDomainRequests(tld, Status.REJECTED); logger.severefmt("%s: skipping domain %s not under tld", tld, domain); } else { dnsMetrics.incrementPublishDomainRequests(tld, Status.ACCEPTED); writer.publishDomain(domain); }//from w ww . j a v a 2 s.co m } for (String host : nullToEmpty(hosts)) { if (!DomainNameUtils.isUnder(InternetDomainName.from(host), InternetDomainName.from(tld))) { dnsMetrics.incrementPublishHostRequests(tld, Status.REJECTED); logger.severefmt("%s: skipping host %s not under tld", tld, host); } else { dnsMetrics.incrementPublishHostRequests(tld, Status.ACCEPTED); writer.publishHost(host); } } } }
From source file:google.registry.tools.UpdateClaimsNoticeCommand.java
private void updateClaimsNotice(String applicationId, LaunchNotice launchNotice) throws InvalidChecksumException { ofy().assertInTransaction();//ww w . jav a2s . c o m DateTime now = ofy().getTransactionTime(); // Load the domain application. DomainApplication domainApplication = loadDomainApplication(applicationId, now); checkArgument(domainApplication != null, "Domain application does not exist"); // Make sure this isn't a sunrise application. checkArgument(domainApplication.getEncodedSignedMarks().isEmpty(), "Can't update claims notice on sunrise applications."); // Validate the new launch notice checksum. String domainLabel = InternetDomainName.from(domainApplication.getFullyQualifiedDomainName()).parts() .get(0); launchNotice.validate(domainLabel); DomainApplication updatedApplication = domainApplication.asBuilder().setLaunchNotice(launchNotice) .setLastEppUpdateTime(now).setLastEppUpdateClientId(domainApplication.getCurrentSponsorClientId()) .build(); // Create a history entry (with no XML or Trid) to record that we are updating the application. HistoryEntry newHistoryEntry = new HistoryEntry.Builder() .setType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE).setParent(domainApplication) .setModificationTime(now).setClientId(domainApplication.getCurrentSponsorClientId()) .setBySuperuser(true).build(); // Save entities to datastore. ofy().save().<Object>entities(updatedApplication, newHistoryEntry); }
From source file:nl.surfsara.warcexamples.hadoop.wet.NERMapper.java
@Override public void map(LongWritable key, WarcRecord value, Context context) throws IOException, InterruptedException { context.setStatus(Counters.CURRENT_RECORD + ": " + key.get()); // Only process text/plain content if ("text/plain".equals(value.header.contentTypeStr)) { context.getCounter(Counters.NUM_TEXT_RECORDS).increment(1); // Get the text payload Payload payload = value.getPayload(); if (payload == null) { // NOP } else {//from w w w . ja v a 2 s .com // BIG TEMP BLOCK String url = ""; try { url = new URI("http://utwente.nl/").getHost(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } InternetDomainName tmp = InternetDomainName.from(url); // this actually seems to work =D if (numrecords < MAX_RECORDS) { String warcContent = IOUtils.toString(payload.getInputStreamComplete()); if (warcContent == null && "".equals(warcContent)) { // NOP } else { // Classify text List<List<CoreLabel>> classify = classifier.classify(warcContent); for (List<CoreLabel> coreLabels : classify) { for (CoreLabel coreLabel : coreLabels) { String term = coreLabel.word(); String tag = coreLabel.get(CoreAnnotations.AnswerAnnotation.class); if (!"O".equals(tag)) { context.write(new Text(tag), new Text(term)); } } } numrecords++; } } } } }
From source file:google.registry.flows.domain.DomainPricingLogic.java
/** Returns a new create price for the Pricer. */ public FeesAndCredits getCreatePrice(Registry registry, String domainName, DateTime date, int years) throws EppException { CurrencyUnit currency = registry.getCurrency(); // Get the vanilla create cost. BaseFee createFeeOrCredit = Fee.create(getDomainCreateCost(domainName, date, years).getAmount(), FeeType.CREATE);/*from ww w.j av a 2 s .c o m*/ // Create fees for the cost and the EAP fee, if any. Fee eapFee = registry.getEapFeeFor(date); FeesAndCredits.Builder feesBuilder = new FeesAndCredits.Builder().setCurrency(currency) .addFeeOrCredit(createFeeOrCredit); if (!eapFee.hasZeroCost()) { feesBuilder.addFeeOrCredit(eapFee); } // Apply custom logic to the create fee, if any. return customLogic.customizeCreatePrice(CreatePriceParameters.newBuilder() .setFeesAndCredits(feesBuilder.build()).setRegistry(registry) .setDomainName(InternetDomainName.from(domainName)).setAsOfDate(date).setYears(years).build()); }
From source file:google.registry.tools.UpdateSmdCommand.java
private void updateSmd(String applicationId, EncodedSignedMark encodedSignedMark, String reason) throws EppException { ofy().assertInTransaction();/*from www . j a v a 2 s.c o m*/ DateTime now = ofy().getTransactionTime(); // Load the domain application. DomainApplication domainApplication = loadDomainApplication(applicationId, now); checkArgument(domainApplication != null, "Domain application does not exist"); // Make sure this is a sunrise application. checkArgument(!domainApplication.getEncodedSignedMarks().isEmpty(), "Can't update SMD on a landrush application."); // Verify the new SMD. String domainLabel = InternetDomainName.from(domainApplication.getFullyQualifiedDomainName()).parts() .get(0); tmchUtils.verifyEncodedSignedMark(encodedSignedMark, domainLabel, now); DomainApplication updatedApplication = domainApplication.asBuilder() .setEncodedSignedMarks(ImmutableList.of(encodedSignedMark)).setLastEppUpdateTime(now) .setLastEppUpdateClientId(domainApplication.getCurrentSponsorClientId()).build(); // Create a history entry (with no XML or Trid) to record that we are updating the application. HistoryEntry newHistoryEntry = new HistoryEntry.Builder() .setType(HistoryEntry.Type.DOMAIN_APPLICATION_UPDATE).setParent(domainApplication) .setModificationTime(now).setClientId(domainApplication.getCurrentSponsorClientId()) .setBySuperuser(true).setReason("UpdateSmdCommand" + (reason != null ? ": " + reason : "")).build(); // Save entities to datastore. ofy().save().<Object>entities(updatedApplication, newHistoryEntry); }
From source file:uk.bl.wa.extract.LinkExtractor.java
/** * Attempt to parse out the private domain. Fall back on host if things go * awry.//from ww w . j a va 2s . c o m * * @param host * @return */ public static String extractPrivateSuffixFromHost(String host) { if (host == null) return null; // Parse out the public suffix: InternetDomainName domainName; try { domainName = InternetDomainName.from(host); } catch (Exception e) { return host; } InternetDomainName suffix = null; // It appears the IDN class does not know about the various UK // second-level domains. // If it's a UK host, override the result by assuming three levels: if (host.endsWith(".uk")) { ImmutableList<String> parts = domainName.parts(); if (parts.size() >= 3) { suffix = InternetDomainName.from(parts.get(parts.size() - 3) + "." + parts.get(parts.size() - 2) + "." + parts.get(parts.size() - 1)); } } else { if (domainName.isTopPrivateDomain() || domainName.isUnderPublicSuffix()) { suffix = domainName.topPrivateDomain(); } else { suffix = domainName; } } // If it all failed for some reason, fall back on the host value: if (suffix == null) suffix = domainName; return suffix.toString(); }
From source file:com.linkedin.pinot.common.response.ServerInstance.java
/** * As per <a href="https://tools.ietf.org/html/rfc952">RFC-952</a> domain names should begin with a letter. * That said, <a href="https://tools.ietf.org/html/rfc1123#page-13">RFC-1123</a> updated it say that it may also begin * with a digit. Indeed, <a href="http://9292.nl/">this</a> is a valid domain name. Only the top-level domain (i.e. the * last portion) has to be non-numeric. More clarification on this matter is in * <a href="https://tools.ietf.org/html/rfc3696#section-2">RFC-3696</a> * * A potentially faster solution is/*from ww w . j a v a 2 s .co m*/ * * if (first char is a digit) { * it is probably ipv4; * return name; * } else { * it could be ipv6 (in which case no dots), or a hostname * return substring before the first dot. * } * * It will fail if there are host names starting with a digit, but will work right otherwise. */ private String makeShortHostName(final String name) { try { InternetDomainName domainName = InternetDomainName.from(name); return domainName.parts().get(0); } catch (Exception e) { return name; } }
From source file:org.mayocat.multitenancy.DefaultTenantResolver.java
private String extractSlugFromHost(String host) { String rootDomain;// w w w. j a va2 s .c o m 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; } }