List of usage examples for org.apache.http.client.utils DateUtils parseDate
public static Date parseDate(final String dateValue)
From source file:org.apache.http.impl.client.cache.CachingHttpAsyncClient.java
private boolean revalidationResponseIsTooOld(final HttpResponse backendResponse, final HttpCacheEntry cacheEntry) { final Header entryDateHeader = cacheEntry.getFirstHeader(HTTP.DATE_HEADER); final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER); if (entryDateHeader != null && responseDateHeader != null) { final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue()); final Date respDate = DateUtils.parseDate(responseDateHeader.getValue()); if (respDate != null && respDate.before(entryDate)) { return true; }// ww w. java 2 s. c o m } return false; }
From source file:org.apache.http.impl.client.cache.CachingHttpAsyncClient.java
private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final HttpRequest request, final HttpResponse backendResponse) { HttpCacheEntry existing = null;/*w w w.j a v a 2 s .co m*/ try { existing = this.responseCache.getCacheEntry(target, request); } catch (final IOException ioe) { // nop } if (existing == null) { return false; } final Header entryDateHeader = existing.getFirstHeader(HTTP.DATE_HEADER); if (entryDateHeader == null) { return false; } final Header responseDateHeader = backendResponse.getFirstHeader(HTTP.DATE_HEADER); if (responseDateHeader == null) { return false; } final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue()); final Date responseDate = DateUtils.parseDate(responseDateHeader.getValue()); return responseDate != null && responseDate.before(entryDate); }
From source file:org.artifactory.repo.HttpRepo.java
private static long getLastModified(HttpResponse response) { Header lastModifiedHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED); if (lastModifiedHeader == null) { return -1; }/*from ww w . j av a 2 s . c o m*/ String lastModifiedString = lastModifiedHeader.getValue(); //try { Date lastModifiedDate = DateUtils.parseDate(lastModifiedString); if (lastModifiedDate != null) { return lastModifiedDate.getTime(); } else { log.warn("Unable to parse Last-Modified header : " + lastModifiedString); return System.currentTimeMillis(); } }
From source file:org.opensextant.xtext.collectors.web.DefaultWebCrawl.java
/** * recursive folder crawl through a site. This is where docs are * converted and recorded./*from w ww.j a v a 2s . c o m*/ * As hashing algorithms are used in defining concise output paths, NoSuchAlgorithmException is thrown. * * @param _link * a URL * @param startingSite * the top level site * @throws IOException * on err * @throws NoSuchAlgorithmException * error that never happens */ public void collectItems(String _link, URL startingSite) throws IOException, NoSuchAlgorithmException { String link = startingSite.toString(); if (_link != null) { link = _link; } HyperLink thisLink = new HyperLink(link, new URL(link), getSite()); if (errorPages.contains(thisLink.getAbsoluteURL())) { log.debug("Do not visit error pages tracked in this session; link: {}", link); return; } HttpResponse page = getPage(prepURL(link)); /* * As of XText 1.4, this HTTP header does not appear to be avaiable often using this http API: */ Header lastModStr = page.getFirstHeader("Last-Modified"); Date lastMod = null; if (lastModStr != null) { lastMod = DateUtils.parseDate(lastModStr.getValue()); } /* * 1. Capture the page content represented by the requested link. * It is saved to FILE.html */ String rawData = WebClient.readTextStream(page.getEntity().getContent()); String thisPath = thisLink.getNormalPath(); //if (StringUtils.isEmpty(thisPath)) { // return; //} if (thisLink.isDynamic() && (!thisPath.endsWith("html"))) { thisPath = String.format("%s.html", thisPath); } File thisPage = createArchiveFile(thisPath, thisLink.isFolder()); // OVERWRITE: if (!thisPage.exists()) { FileUtility.writeFile(rawData, thisPage.getAbsolutePath()); } log.info("Starting in on {} from {} @ depth=" + depth, link, site); pause(); ++depth; collectItemsOnPage(rawData, thisLink.getURL(), getSite()); }