本文整理汇总了Java中org.apache.http.client.utils.DateUtils.parseDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateUtils.parseDate方法的具体用法?Java DateUtils.parseDate怎么用?Java DateUtils.parseDate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.utils.DateUtils
的用法示例。
在下文中一共展示了DateUtils.parseDate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pollInternal
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
public void pollInternal() {
HttpHeaders requestHeaders = new HttpHeaders();
if (lastModified != null) {
requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified));
}
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
ResponseEntity<Feed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Feed.class);
if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
log.trace("data has been modified");
Feed feed = response.getBody();
for (Entry entry : feed.getEntries()) {
if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
Invoice invoice = restTemplate
.getForEntity(entry.getContents().get(0).getSrc(), Invoice.class).getBody();
log.trace("saving invoice {}", invoice.getId());
invoiceService.generateInvoice(invoice);
}
}
if (response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED) != null) {
lastModified = DateUtils.parseDate(response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED));
log.trace("Last-Modified header {}", lastModified);
}
} else {
log.trace("no new data");
}
}
示例2: requestWithLastModifiedReturns304
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Test
public void requestWithLastModifiedReturns304() {
Order order = new Order();
order.setCustomer(customerRepository.findAll().iterator().next());
orderRepository.save(order);
ResponseEntity<Feed> response = restTemplate.exchange(feedUrl(), HttpMethod.GET, new HttpEntity(null),
Feed.class);
Date lastModified = DateUtils.parseDate(response.getHeaders().getFirst("Last-Modified"));
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("If-Modified-Since", DateUtils.formatDate(lastModified));
HttpEntity requestEntity = new HttpEntity(requestHeaders);
response = restTemplate.exchange(feedUrl(), HttpMethod.GET, requestEntity, Feed.class);
assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode());
}
示例3: pollInternal
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
public void pollInternal() {
HttpHeaders requestHeaders = new HttpHeaders();
if (lastModified != null) {
requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified));
}
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
ResponseEntity<Feed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Feed.class);
if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
log.trace("data has been modified");
Feed feed = response.getBody();
for (Entry entry : feed.getEntries()) {
if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
Shipment shipping = restTemplate
.getForEntity(entry.getContents().get(0).getSrc(), Shipment.class).getBody();
log.trace("saving shipping {}", shipping.getId());
shipmentService.ship(shipping);
}
}
if (response.getHeaders().getFirst("Last-Modified") != null) {
lastModified = DateUtils.parseDate(response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED));
log.trace("Last-Modified header {}", lastModified);
}
} else {
log.trace("no new data");
}
}
示例4: isLastModifiedChanged
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
private boolean isLastModifiedChanged(final HttpResponse response) {
final Header newLastModifiedHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED);
if (newLastModifiedHeader != null) {
final Date newLastModified = DateUtils.parseDate(newLastModifiedHeader.getValue());
if (newLastModified == null) {
throw new IllegalArgumentException("Invalid last modified date");
}
if (!_previousLastModified.isPresent() || newLastModified.after(_previousLastModified.get())) {
LOGGER.debug()
.setMessage("Uri last modified changed")
.addData("uri", _uri)
.addData("newLastModified", newLastModified)
.addData("previousLastModified", _previousLastModified)
.log();
_previousLastModified = Optional.of(newLastModified);
return true;
}
}
return false;
}
示例5: revalidationResponseIsTooOld
import org.apache.http.client.utils.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) {
final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
final Date respDate = DateUtils.parseDate(responseDateHeader.getValue());
if (entryDate == null || respDate == null) {
// 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;
}
if (respDate.before(entryDate)) {
return true;
}
}
return false;
}
示例6: alreadyHaveNewerCacheEntry
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
private boolean alreadyHaveNewerCacheEntry(final HttpHost target, final HttpRequestWrapper 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;
}
final Date entryDate = DateUtils.parseDate(entryDateHeader.getValue());
final Date responseDate = DateUtils.parseDate(responseDateHeader.getValue());
if (entryDate == null || responseDate == null) {
return false;
}
return responseDate.before(entryDate);
}
示例7: expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
private boolean expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl(
final HttpResponse response) {
if (response.getFirstHeader(HeaderConstants.CACHE_CONTROL) != null) {
return false;
}
final Header expiresHdr = response.getFirstHeader(HeaderConstants.EXPIRES);
final Header dateHdr = response.getFirstHeader(HTTP.DATE_HEADER);
if (expiresHdr == null || dateHdr == null) {
return false;
}
final Date expires = DateUtils.parseDate(expiresHdr.getValue());
final Date date = DateUtils.parseDate(dateHdr.getValue());
if (expires == null || date == null) {
return false;
}
return expires.equals(date) || expires.before(date);
}
示例8: lastModifiedValidatorMatches
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
/**
* Check entry against If-Modified-Since, if If-Modified-Since is in the future it is invalid as per
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
* @param request The current httpRequest being made
* @param entry the cache entry
* @param now right NOW in time
* @return boolean Does the last modified header match
*/
private boolean lastModifiedValidatorMatches(final HttpRequest request, final HttpCacheEntry entry, final Date now) {
final Header lastModifiedHeader = entry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
Date lastModified = null;
if (lastModifiedHeader != null) {
lastModified = DateUtils.parseDate(lastModifiedHeader.getValue());
}
if (lastModified == null) {
return false;
}
for (final Header h : request.getHeaders(HeaderConstants.IF_MODIFIED_SINCE)) {
final Date ifModifiedSince = DateUtils.parseDate(h.getValue());
if (ifModifiedSince != null) {
if (ifModifiedSince.after(now) || lastModified.after(ifModifiedSince)) {
return false;
}
}
}
return true;
}
示例9: poll
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
@Scheduled(fixedDelay = 15000)
public void poll() {
HttpHeaders requestHeaders = new HttpHeaders();
if (lastModified != null) {
requestHeaders.set("If-Modified-Since", DateUtils.formatDate(lastModified));
}
HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
ResponseEntity<Feed> response = restTemplate.exchange(creditDecisionFeed, HttpMethod.GET, requestEntity, Feed.class);
if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
Feed feed = response.getBody();
Date lastUpdateInFeed = null;
for (Entry entry : feed.getEntries()) {
String applicationNumber = entry.getSummary().getValue();
if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
log.info(applicationNumber + " is new, updating the status");
CreditApplicationStatus applicationStatus = repository.findByApplicationNumber(applicationNumber);
if (applicationStatus != null) {
applicationStatus.setApproved(true);
repository.save(applicationStatus);
}
if ((lastUpdateInFeed == null) || (entry.getUpdated().after(lastUpdateInFeed))) {
lastUpdateInFeed = entry.getUpdated();
}
}
}
if (response.getHeaders().getFirst("Last-Modified") != null) {
lastModified = DateUtils.parseDate(response.getHeaders().getFirst("Last-Modified"));
log.info("LastModified header {}", lastModified);
} else {
if (lastUpdateInFeed != null) {
lastModified = lastUpdateInFeed;
log.info("Last in feed {}", lastModified);
}
}
}
}
示例10: extractLastModified
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
private Date extractLastModified(final Artifact artifact, final String version, final List<String> repositoryUrls) throws IOException {
for (final String repositoryUrl : repositoryUrls) {
final URL url = new URL(generateUrl(artifact, version, repositoryUrl));
final URLConnection connection = url.openConnection();
String lastModified = connection.getHeaderField("Last-Modified");
if (lastModified != null) {
// Once found, return.
return DateUtils.parseDate(lastModified);
}
}
return null;
}
示例11: parse
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
public void parse(final SetCookie cookie, final String value)
throws MalformedCookieException {
Args.notNull(cookie, "Cookie");
if (value == null) {
throw new MalformedCookieException("Missing value for expires attribute");
}
final Date expiry = DateUtils.parseDate(value, this.datepatterns);
if (expiry == null) {
throw new MalformedCookieException("Unable to parse expires attribute: "
+ value);
}
cookie.setExpiryDate(expiry);
}
示例12: getLastModifiedHeaderValue
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
/**
* Get last modified header value as date, will fall back to current time if header is not set
*
* @param response
* the response of the image request
* @return the last modification date
*/
protected Date getLastModifiedHeaderValue(CloseableHttpResponse response) {
Header lastModifiedHeader = response.getLastHeader(HttpHeaders.LAST_MODIFIED);
Date lastModified = null;
if (lastModifiedHeader != null && lastModifiedHeader.getValue() != null) {
lastModified = DateUtils.parseDate(lastModifiedHeader.getValue());
}
if (lastModified == null) {
// take current time rounded to seconds because Last-Modified has only second precision
long now = (System.currentTimeMillis() / 1000) * 1000;
lastModified = new Date(now);
}
return lastModified;
}
示例13: parseDate
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
/**
* Find the "Date" response header and parse it into a java.util.Date
* @return the Date value of the header or null if the header is not present
*/
private Date parseDate() {
final Header dateHdr = getFirstHeader(HTTP.DATE_HEADER);
if (dateHdr == null) {
return null;
}
return DateUtils.parseDate(dateHdr.getValue());
}
示例14: getLastModifiedValue
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
protected Date getLastModifiedValue(final HttpCacheEntry entry) {
final Header dateHdr = entry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
if (dateHdr == null) {
return null;
}
return DateUtils.parseDate(dateHdr.getValue());
}
示例15: getExpirationDate
import org.apache.http.client.utils.DateUtils; //导入方法依赖的package包/类
protected Date getExpirationDate(final HttpCacheEntry entry) {
final Header expiresHeader = entry.getFirstHeader(HeaderConstants.EXPIRES);
if (expiresHeader == null) {
return null;
}
return DateUtils.parseDate(expiresHeader.getValue());
}