本文整理汇总了Java中org.apache.http.client.utils.DateUtils.formatDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.formatDate方法的具体用法?Java DateUtils.formatDate怎么用?Java DateUtils.formatDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.utils.DateUtils
的用法示例。
在下文中一共展示了DateUtils.formatDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConditionalRequestForEntryWithLastModifiedAndEtagIncludesBothAsValidators
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testConditionalRequestForEntryWithLastModifiedAndEtagIncludesBothAsValidators()
throws Exception {
final Date now = new Date();
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
final Date twentySecondsAgo = new Date(now.getTime() - 20 * 1000L);
final String lmDate = DateUtils.formatDate(twentySecondsAgo);
final String etag = "\"etag\"";
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Last-Modified", lmDate),
new BasicHeader("ETag", etag)
};
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertEquals(lmDate,
result.getFirstHeader("If-Modified-Since").getValue());
Assert.assertEquals(etag,
result.getFirstHeader("If-None-Match").getValue());
}
示例2: testNewHeadersAreAddedByMerge
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testNewHeadersAreAddedByMerge() throws IOException {
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(requestDate)),
new BasicHeader("ETag", "\"etag\"")};
entry = HttpTestUtils.makeCacheEntry(headers);
response.setHeaders(new Header[]{
new BasicHeader("Last-Modified", DateUtils.formatDate(responseDate)),
new BasicHeader("Cache-Control", "public"),});
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
new Date(), new Date(), response);
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
assertEquals(4, updatedHeaders.length);
headersContain(updatedHeaders, "Date", DateUtils.formatDate(requestDate));
headersContain(updatedHeaders, "ETag", "\"etag\"");
headersContain(updatedHeaders, "Last-Modified", DateUtils.formatDate(responseDate));
headersContain(updatedHeaders, "Cache-Control", "public");
}
示例3: testHeadersAreMergedCorrectly
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testHeadersAreMergedCorrectly() throws IOException {
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(responseDate)),
new BasicHeader("ETag", "\"etag\"")};
entry = HttpTestUtils.makeCacheEntry(headers);
response.setHeaders(new Header[]{});
final HttpCacheEntry updatedEntry = impl.updateCacheEntry(null, entry,
new Date(), new Date(), response);
final Header[] updatedHeaders = updatedEntry.getAllHeaders();
assertEquals(2, updatedHeaders.length);
headersContain(updatedHeaders, "Date", DateUtils.formatDate(responseDate));
headersContain(updatedHeaders, "ETag", "\"etag\"");
}
示例4: testSuitableIfCacheEntryIsHeuristicallyFreshEnough
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testSuitableIfCacheEntryIsHeuristicallyFreshEnough() {
final Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
final Date twentyOneSecondsAgo = new Date(now.getTime() - 21 * 1000L);
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(oneSecondAgo)),
new BasicHeader("Last-Modified", DateUtils.formatDate(twentyOneSecondsAgo)),
new BasicHeader("Content-Length", "128")
};
entry = HttpTestUtils.makeCacheEntry(oneSecondAgo, oneSecondAgo, headers);
final CacheConfig config = CacheConfig.custom()
.setHeuristicCachingEnabled(true)
.setHeuristicCoefficient(0.1f).build();
impl = new CachedResponseSuitabilityChecker(config);
Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
}
示例5: his2RundeckXO
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
private RundeckXO his2RundeckXO(SearchHit hit) {
String version = (String) hit.getSource().get("version");
List<Map<String, Object>> assets = (List<Map<String, Object>>) hit.getSource().get("assets");
Map<String, Object> attributes = (Map<String, Object>) assets.get(0).get("attributes");
Map<String, Object> content = (Map<String, Object>) attributes.get("content");
String lastModifiedTime = "null";
if (content != null && content.containsKey("last_modified")) {
Long lastModified = (Long) content.get("last_modified");
lastModifiedTime = DateUtils.formatDate(new Date(lastModified), "yyyy-MM-dd HH:mm:ss");
}
return RundeckXO.builder().name(version + " (" + lastModifiedTime + ")").value(version).build();
}
示例6: testNotSuitableForGETIfEntryDoesNotSpecifyARequestMethodOrEntity
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testNotSuitableForGETIfEntryDoesNotSpecifyARequestMethodOrEntity() {
impl = new CachedResponseSuitabilityChecker(CacheConfig.custom().build());
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600"),
new BasicHeader("Content-Length","128")
};
entry = HttpTestUtils.makeCacheEntryWithNoRequestMethodOrEntity(headers);
Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
}
示例7: entry1xxWarningsAreRemovedOnUpdate
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void entry1xxWarningsAreRemovedOnUpdate() throws Exception {
final Header[] headers = {
new BasicHeader("Warning", "110 fred \"Response is stale\""),
new BasicHeader("ETag", "\"old\""),
new BasicHeader("Date", DateUtils.formatDate(eightSecondsAgo))
};
entry = HttpTestUtils.makeCacheEntry(tenSecondsAgo, eightSecondsAgo, headers);
response.setHeader("ETag", "\"new\"");
response.setHeader("Date", DateUtils.formatDate(twoSecondsAgo));
final HttpCacheEntry updated = impl.updateCacheEntry(null, entry,
twoSecondsAgo, oneSecondAgo, response);
assertEquals(0, updated.getHeaders("Warning").length);
}
示例8: testSuitableIfFreshAndAgeIsUnderRequestMaxAge
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testSuitableIfFreshAndAgeIsUnderRequestMaxAge() {
request.addHeader("Cache-Control", "max-age=15");
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600"),
new BasicHeader("Content-Length","128")
};
entry = getEntry(headers);
Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
}
示例9: testMayNotReturnStaleIfErrorInResponseAndAfterResponseWindow
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testMayNotReturnStaleIfErrorInResponseAndAfterResponseWindow(){
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=5, stale-if-error=1")
};
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
final HttpRequest req = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
assertFalse(impl.mayReturnStaleIfError(req, entry, now));
}
示例10: testNotSuitableIfCacheEntryIsNotFresh
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testNotSuitableIfCacheEntryIsNotFresh() {
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=5"),
new BasicHeader("Content-Length","128")
};
entry = getEntry(headers);
Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
}
示例11: testSuitableIfFreshAndFreshnessLifetimeGreaterThanRequestMinFresh
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testSuitableIfFreshAndFreshnessLifetimeGreaterThanRequestMinFresh() {
request.addHeader("Cache-Control", "min-fresh=10");
final Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=3600"),
new BasicHeader("Content-Length","128")
};
entry = getEntry(headers);
Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
}
示例12: testBuildConditionalRequestWithETag
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testBuildConditionalRequestWithETag() throws ProtocolException {
final String theMethod = "GET";
final String theUri = "/theuri";
final String theETag = "this is my eTag";
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
basicRequest.addHeader("Accept-Encoding", "gzip");
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(new Date())),
new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())),
new BasicHeader("ETag", theETag) };
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
Assert.assertNotSame(basicRequest, newRequest);
Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod());
Assert.assertEquals(theUri, newRequest.getRequestLine().getUri());
Assert.assertEquals(basicRequest.getRequestLine().getProtocolVersion(), newRequest
.getRequestLine().getProtocolVersion());
Assert.assertEquals(3, newRequest.getAllHeaders().length);
Assert.assertEquals("Accept-Encoding", newRequest.getAllHeaders()[0].getName());
Assert.assertEquals("gzip", newRequest.getAllHeaders()[0].getValue());
Assert.assertEquals("If-None-Match", newRequest.getAllHeaders()[1].getName());
Assert.assertEquals(theETag, newRequest.getAllHeaders()[1].getValue());
}
示例13: testCacheEntryIsRevalidatableIfHeadersIncludeLastModifiedDate
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testCacheEntryIsRevalidatableIfHeadersIncludeLastModifiedDate() {
final Header[] headers = {
new BasicHeader("Expires", DateUtils.formatDate(new Date())),
new BasicHeader("Last-Modified", DateUtils.formatDate(new Date())) };
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
assertTrue(impl.isRevalidatable(entry));
}
示例14: testNegativeApparentAgeIsBroughtUpToZero
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testNegativeApparentAgeIsBroughtUpToZero() {
final Header[] headers = new Header[] { new BasicHeader("Date", DateUtils
.formatDate(sixSecondsAgo)) };
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now,tenSecondsAgo,headers);
assertEquals(0, impl.getApparentAgeSecs(entry));
}
示例15: testMayReturnStaleWhileRevalidatingIsTrueWhenWithinStaleness
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void testMayReturnStaleWhileRevalidatingIsTrueWhenWithinStaleness() {
final Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Cache-Control", "max-age=5, stale-while-revalidate=15")
};
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(now, now, headers);
assertTrue(impl.mayReturnStaleWhileRevalidating(entry, now));
}