當前位置: 首頁>>代碼示例>>Java>>正文


Java DateUtils.parseDate方法代碼示例

本文整理匯總了Java中org.apache.http.impl.cookie.DateUtils.parseDate方法的典型用法代碼示例。如果您正苦於以下問題:Java DateUtils.parseDate方法的具體用法?Java DateUtils.parseDate怎麽用?Java DateUtils.parseDate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.impl.cookie.DateUtils的用法示例。


在下文中一共展示了DateUtils.parseDate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: revalidationResponseIsTooOld

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
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) {
        try {
            final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
            final Date respDate = DateUtils.parseDate(responseDateHeader.getValue());
            if (respDate.before(entryDate)) {
                return true;
            }
        } catch (final DateParseException e) {
            // either backend response or cached entry did not have a valid
            // Date header, so we can't tell if they are out of order
            // according to the origin clock; thus we can skip the
            // unconditional retry recommended in 13.2.6 of RFC 2616.
        }
    }
    return false;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:21,代碼來源:CachingHttpClient.java

示例2: checkVetoHeaders

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
protected void checkVetoHeaders(HttpResponse response, boolean checkExpires) throws Exception {
  Header head = response.getFirstHeader("Cache-Control");
  assertNotNull("We got no Cache-Control header", head);
  assertTrue("We got no no-cache in the Cache-Control header ["+head+"]", head.getValue().contains("no-cache"));
  assertTrue("We got no no-store in the Cache-Control header ["+head+"]", head.getValue().contains("no-store"));

  head = response.getFirstHeader("Pragma");
  assertNotNull("We got no Pragma header", head);
  assertEquals("no-cache", head.getValue());

  if (checkExpires) {
    head = response.getFirstHeader("Expires");
    assertNotNull("We got no Expires header:" + Arrays.asList(response.getAllHeaders()), head);
    Date d = DateUtils.parseDate(head.getValue());
    assertTrue("We got no Expires header far in the past", System
        .currentTimeMillis()
        - d.getTime() > 100000);
  }
}
 
開發者ID:europeana,項目名稱:search,代碼行數:20,代碼來源:CacheHeaderTest.java

示例3: entryDateHeaderNewerThenResponse

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
private boolean entryDateHeaderNewerThenResponse(HttpCacheEntry entry,
		HttpResponse response) {
	try {
		Date entryDate = DateUtils.parseDate(entry.getFirstHeader(
				HTTP.DATE_HEADER).getValue());
		Date responseDate = DateUtils.parseDate(response.getFirstHeader(
				HTTP.DATE_HEADER).getValue());

		if (!entryDate.after(responseDate)) {
			return false;
		}
	} catch (DateParseException e) {
		return false;
	}

	return true;
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:18,代碼來源:CacheEntryUpdater.java

示例4: alreadyHaveNewerCacheEntry

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
private boolean alreadyHaveNewerCacheEntry(HttpHost target,
		HttpRequest request, HttpResponse backendResponse)
		throws IOException {
	HttpCacheEntry existing = null;
	try {
		existing = responseCache.getCacheEntry(target, request);
	} catch (IOException ioe) {
		// nop
	}
	if (existing == null)
		return false;
	Header entryDateHeader = existing.getFirstHeader("Date");
	if (entryDateHeader == null)
		return false;
	Header responseDateHeader = backendResponse.getFirstHeader("Date");
	if (responseDateHeader == null)
		return false;
	try {
		Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
		Date responseDate = DateUtils.parseDate(responseDateHeader
				.getValue());
		return responseDate.before(entryDate);
	} catch (DateParseException e) {
	}
	return false;
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:27,代碼來源:CachingHttpClient.java

示例5: getExpiresDate

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
private Date getExpiresDate() {
	String expires = get("Expires", this.response);

	try {
		return DateUtils.parseDate(expires);
	} catch(Exception e) { // if not present or parsable... just ignore
		return OLD;
	}
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:10,代碼來源:InMemoryCacheEntry.java

示例6: parseDate

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
protected Date parseDate(final String expires) {
	try {
		return DateUtils.parseDate(expires);
	} catch (DateParseException e) {
		throw MechanizeExceptionFactory.newException(e);
	}
}
 
開發者ID:Coffeeboys,項目名稱:RenewPass,代碼行數:8,代碼來源:InMemoryCacheEntry.java

示例7: alreadyHaveNewerCacheEntry

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final HttpRequest request,
        final HttpResponse backendResponse) {
    HttpCacheEntry existing = null;
    try {
        existing = 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;
    }
    try {
        final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
        final Date responseDate = DateUtils.parseDate(responseDateHeader.getValue());
        return responseDate.before(entryDate);
    } catch (final DateParseException e) {
        // Empty on Purpose
    }
    return false;
}
 
開發者ID:MyPureCloud,項目名稱:purecloud-iot,代碼行數:29,代碼來源:CachingHttpClient.java

示例8: getDateValue

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
protected Date getDateValue(final HttpCacheEntry entry) {
	Header dateHdr = entry.getFirstHeader(HTTP.DATE_HEADER);
	if (dateHdr == null)
		return null;
	try {
		return DateUtils.parseDate(dateHdr.getValue());
	} catch (DateParseException dpe) {
		// ignore malformed date
	}
	return null;
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:12,代碼來源:CacheValidityPolicy.java

示例9: getLastModifiedValue

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
protected Date getLastModifiedValue(final HttpCacheEntry entry) {
	Header dateHdr = entry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
	if (dateHdr == null)
		return null;
	try {
		return DateUtils.parseDate(dateHdr.getValue());
	} catch (DateParseException dpe) {
		// ignore malformed date
	}
	return null;
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:12,代碼來源:CacheValidityPolicy.java

示例10: getExpirationDate

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
protected Date getExpirationDate(final HttpCacheEntry entry) {
	Header expiresHeader = entry.getFirstHeader(HeaderConstants.EXPIRES);
	if (expiresHeader == null)
		return null;
	try {
		return DateUtils.parseDate(expiresHeader.getValue());
	} catch (DateParseException dpe) {
		// malformed expires header
	}
	return null;
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:12,代碼來源:CacheValidityPolicy.java

示例11: hasValidDateField

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
private boolean hasValidDateField(HttpRequest request, String headerName) {
	for (Header h : request.getHeaders(headerName)) {
		try {
			DateUtils.parseDate(h.getValue());
			return true;
		} catch (DateParseException dpe) {
			// ignore malformed dates
		}
	}
	return false;
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:12,代碼來源:CachedResponseSuitabilityChecker.java

示例12: consumeWarnDate

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
protected void consumeWarnDate() {
	int curr = offs;
	Matcher m = WARN_DATE_PATTERN.matcher(src.substring(offs));
	if (!m.lookingAt())
		parseError();
	offs += m.end();
	try {
		warnDate = DateUtils.parseDate(src.substring(curr + 1, offs - 1));
	} catch (DateParseException e) {
		throw new IllegalStateException("couldn't parse a parseable date");
	}
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:13,代碼來源:WarningValue.java

示例13: doLastModified

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
@Override
protected void doLastModified(String method) throws Exception {
  // We do a first request to get the last modified
  // This must result in a 200 OK response
  HttpRequestBase get = getSelectMethod(method);
  HttpResponse response = getClient().execute(get);
  checkResponseBody(method, response);

  assertEquals("Got no response code 200 in initial request", 200, response.
      getStatusLine().getStatusCode());

  Header head = response.getFirstHeader("Last-Modified");
  assertNotNull("We got no Last-Modified header", head);

  Date lastModified = DateUtils.parseDate(head.getValue());

  // If-Modified-Since tests
  get = getSelectMethod(method);
  get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date()));

  response = getClient().execute(get);
  checkResponseBody(method, response);
  assertEquals("Expected 304 NotModified response with current date", 304,
      response.getStatusLine().getStatusCode());

  get = getSelectMethod(method);
  get.addHeader("If-Modified-Since", DateUtils.formatDate(new Date(
      lastModified.getTime() - 10000)));
  response = getClient().execute(get);
  checkResponseBody(method, response);
  assertEquals("Expected 200 OK response with If-Modified-Since in the past",
      200, response.getStatusLine().getStatusCode());

  // If-Unmodified-Since tests
  get = getSelectMethod(method);
  get.addHeader("If-Unmodified-Since", DateUtils.formatDate(new Date(
      lastModified.getTime() - 10000)));

  response = getClient().execute(get);
  checkResponseBody(method, response);
  assertEquals(
      "Expected 412 Precondition failed with If-Unmodified-Since in the past",
      412, response.getStatusLine().getStatusCode());

  get = getSelectMethod(method);
  get.addHeader("If-Unmodified-Since", DateUtils
          .formatDate(new Date()));
  response = getClient().execute(get);
  checkResponseBody(method, response);
  assertEquals(
      "Expected 200 OK response with If-Unmodified-Since and current date",
      200, response.getStatusLine().getStatusCode());
}
 
開發者ID:europeana,項目名稱:search,代碼行數:54,代碼來源:CacheHeaderTest.java

示例14: testGetRFC1123NextYear

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
@Test
public void testGetRFC1123NextYear() throws DateParseException {
  Date date = DateUtils.parseDate(service.getRFC1123NextYear());
  assertThat(date.getTime()).isLessThan(System.currentTimeMillis() + 366L * 24 * 60 * 60 * 1000);
}
 
開發者ID:nodchip,項目名稱:QMAClone,代碼行數:6,代碼來源:ImageProxyServletStubTest.java

示例15: isResponseCacheable

import org.apache.http.impl.cookie.DateUtils; //導入方法依賴的package包/類
/**
 * Determines if an HttpResponse can be cached.
 * 
 * @param httpMethod
 *            What type of request was this, a GET, PUT, other?
 * @param response
 *            The origin response
 * @return <code>true</code> if response is cacheable
 */
public boolean isResponseCacheable(String httpMethod, HttpResponse response) {
	boolean cacheable = false;

	if (!HeaderConstants.GET_METHOD.equals(httpMethod)) {
		log.debug("Response was not cacheable.");
		return false;
	}

	switch (response.getStatusLine().getStatusCode()) {
	case HttpStatus.SC_OK:
	case HttpStatus.SC_NON_AUTHORITATIVE_INFORMATION:
	case HttpStatus.SC_MULTIPLE_CHOICES:
	case HttpStatus.SC_MOVED_PERMANENTLY:
	case HttpStatus.SC_GONE:
		// these response codes MAY be cached
		cacheable = true;
		log.debug("Response was cacheable");
		break;
	case HttpStatus.SC_PARTIAL_CONTENT:
		// we don't implement Range requests and hence are not
		// allowed to cache partial content
		log.debug("Response was not cacheable (Partial Content)");
		return cacheable;

	default:
		// If the status code is not one of the recognized
		// available codes in HttpStatus Don't Cache
		log.debug("Response was not cacheable (Unknown Status code)");
		return cacheable;
	}

	Header contentLength = response.getFirstHeader(HTTP.CONTENT_LEN);
	if (contentLength != null) {
		int contentLengthValue = Integer.parseInt(contentLength.getValue());
		if (contentLengthValue > this.maxObjectSizeBytes)
			return false;
	}

	Header[] ageHeaders = response.getHeaders(HeaderConstants.AGE);

	if (ageHeaders.length > 1)
		return false;

	Header[] expiresHeaders = response.getHeaders(HeaderConstants.EXPIRES);

	if (expiresHeaders.length > 1)
		return false;

	Header[] dateHeaders = response.getHeaders(HTTP.DATE_HEADER);

	if (dateHeaders.length != 1)
		return false;

	try {
		DateUtils.parseDate(dateHeaders[0].getValue());
	} catch (DateParseException dpe) {
		return false;
	}

	for (Header varyHdr : response.getHeaders(HeaderConstants.VARY)) {
		for (HeaderElement elem : varyHdr.getElements()) {
			if ("*".equals(elem.getName())) {
				return false;
			}
		}
	}

	if (isExplicitlyNonCacheable(response))
		return false;

	return (cacheable || isExplicitlyCacheable(response));
}
 
開發者ID:apigee,項目名稱:apigee-android-sdk,代碼行數:82,代碼來源:ResponseCachingPolicy.java


注:本文中的org.apache.http.impl.cookie.DateUtils.parseDate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。