Java Code Examples for org.apache.http.client.utils.DateUtils#parseDate()
The following examples show how to use
org.apache.http.client.utils.DateUtils#parseDate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastweixinTest.java From fastweixin with Apache License 2.0 | 6 votes |
public void getArticleData(ApiConfig config) { DataCubeAPI dataCubeAPI = new DataCubeAPI(config); String[] format = {"yyyy-MM-dd"}; Date beginDate = DateUtils.parseDate("2015-01-25", format); Date endDate = DateUtils.parseDate("2015-01-26", format); GetArticleSummaryResponse articleSummary = dataCubeAPI.getArticleSummary(endDate); GetArticleTotalResponse articleTotal = dataCubeAPI.getArticleTotal(endDate); GetUserReadResponse userRead = dataCubeAPI.getUserRead(beginDate, endDate); GetUserReadHourResponse userReadHour = dataCubeAPI.getUserReadHour(endDate); GetUserShareResponse userShare = dataCubeAPI.getUserShare(beginDate, endDate); GetUserShareHourResponse userShareHour = dataCubeAPI.getUserShareHour(endDate); LOG.debug("------------------articleSummary----------------------"); LOG.debug(articleSummary.toJsonString()); LOG.debug("------------------articleTotal----------------------"); LOG.debug(articleTotal.toJsonString()); LOG.debug("------------------userRead----------------------"); LOG.debug(userRead.toJsonString()); LOG.debug("------------------userReadHour----------------------"); LOG.debug(userReadHour.toJsonString()); LOG.debug("------------------userShare----------------------"); LOG.debug(userShare.toJsonString()); LOG.debug("------------------userShareHour----------------------"); LOG.debug(userShareHour.toJsonString()); }
Example 2
Source File: AtomClientTest.java From microservice-atom with Apache License 2.0 | 6 votes |
@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()); }
Example 3
Source File: BonusPoller.java From microservice-istio with Apache License 2.0 | 5 votes |
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<OrderFeed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, OrderFeed.class); if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) { log.trace("data has been modified"); OrderFeed feed = response.getBody(); for (OrderFeedEntry entry : feed.getOrders()) { if ((lastModified == null) || (entry.getUpdated().after(lastModified))) { Bonus bonus = restTemplate .getForEntity(entry.getLink(), Bonus.class).getBody(); log.trace("saving bonus {}", bonus.getId()); bonusService.calculateBonus(bonus); } } 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"); } }
Example 4
Source File: FastweixinTest.java From fastweixin with Apache License 2.0 | 5 votes |
public void getUserData(ApiConfig config) { DataCubeAPI dataAPI = new DataCubeAPI(config); String[] format = {"yyyy-MM-dd"}; Date beginDate = DateUtils.parseDate("2015-01-01", format); Date endDate = DateUtils.parseDate("2015-01-07", format); GetUserSummaryResponse response = dataAPI.getUserSummary(beginDate, endDate); GetUserCumulateResponse cumulateResponse = dataAPI.getUserCumulate(beginDate, endDate); LOG.debug("-----------------getUserSummary---------------------"); LOG.debug(response.toJsonString()); LOG.debug("-----------------getUserCumulate---------------------"); LOG.debug(cumulateResponse.toJsonString()); }
Example 5
Source File: HttpConditions.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Nullable private static DateTime parseDateHeader(@Nullable final String httpDate) { if (!Strings.isNullOrEmpty(httpDate)) { final Date date = DateUtils.parseDate(httpDate); if (date != null) { return new DateTime(date.getTime()); } } return null; }
Example 6
Source File: PartialFetchHandler.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
private static DateTime parseDateTime(final String stringValue) { if (!Strings.isNullOrEmpty(stringValue)) { final Date date = DateUtils.parseDate(stringValue); if (date != null) { return new DateTime(date.getTime()); } } return null; }
Example 7
Source File: Client.java From geoportal-server-harvester with Apache License 2.0 | 5 votes |
private Date getRetryAfter(HttpResponse response) { org.apache.http.Header retryAfterHeader = response.getFirstHeader("Retry-After"); if (retryAfterHeader != null) { Date parseDate = DateUtils.parseDate(retryAfterHeader.getValue()); if (parseDate!=null) { return parseDate; } try { return new Date(System.currentTimeMillis() + 1000L * Integer.valueOf(retryAfterHeader.getValue())); } catch (NumberFormatException e) { } } return null; }
Example 8
Source File: ShippingPoller.java From microservice-atom with Apache License 2.0 | 5 votes |
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"); } }
Example 9
Source File: InvoicePoller.java From microservice-atom with Apache License 2.0 | 5 votes |
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"); } }
Example 10
Source File: HtmlUnitExpiresHandler.java From htmlunit with Apache License 2.0 | 5 votes |
@Override public void parse(final SetCookie cookie, String value) throws MalformedCookieException { if (value.startsWith("\"") && value.endsWith("\"")) { value = value.substring(1, value.length() - 1); } value = value.replaceAll("[ ,:-]+", " "); Date startDate = null; String[] datePatterns = DEFAULT_DATE_PATTERNS; if (null != browserVersion_) { if (browserVersion_.hasFeature(HTTP_COOKIE_START_DATE_1970)) { startDate = HtmlUnitBrowserCompatCookieSpec.DATE_1_1_1970; } if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_1)) { datePatterns = EXTENDED_DATE_PATTERNS_1; } if (browserVersion_.hasFeature(HTTP_COOKIE_EXTENDED_DATE_PATTERNS_2)) { final Calendar calendar = Calendar.getInstance(Locale.ROOT); calendar.setTimeZone(DateUtils.GMT); calendar.set(1969, Calendar.JANUARY, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); startDate = calendar.getTime(); datePatterns = EXTENDED_DATE_PATTERNS_2; } } final Date expiry = DateUtils.parseDate(value, datePatterns, startDate); cookie.setExpiryDate(expiry); }
Example 11
Source File: Cache.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Parses and returns the specified date header of the specified response. This method * returns {@code null} if the specified header cannot be found or cannot be parsed as a date. * * @param response the response * @param headerName the header name * @return the specified date header of the specified response */ protected static Date parseDateHeader(final WebResponse response, final String headerName) { final String value = response.getResponseHeaderValue(headerName); if (value == null) { return null; } final Matcher matcher = DATE_HEADER_PATTERN.matcher(value); if (matcher.matches()) { return new Date(); } return DateUtils.parseDate(value); }
Example 12
Source File: FeedClientTest.java From microservice-istio with Apache License 2.0 | 5 votes |
@Test public void requestWithLastModifiedReturns304() { ResponseEntity<OrderFeed> response = restTemplate.exchange(feedUrl(), HttpMethod.GET, new HttpEntity(null), OrderFeed.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, OrderFeed.class); assertEquals(HttpStatus.NOT_MODIFIED, response.getStatusCode()); }
Example 13
Source File: InvoicePoller.java From microservice-istio with Apache License 2.0 | 5 votes |
public void pollInternal() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.ACCEPT, "*/*"); if (lastModified != null) { requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified)); } HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); ResponseEntity<OrderFeed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, OrderFeed.class); if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) { log.trace("data has been modified"); OrderFeed feed = response.getBody(); for (OrderFeedEntry entry : feed.getOrders()) { if ((lastModified == null) || (entry.getUpdated().after(lastModified))) { Invoice invoice = restTemplate .getForEntity(entry.getLink(), 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"); } }
Example 14
Source File: ShippingPoller.java From microservice-istio with Apache License 2.0 | 5 votes |
public void pollInternal() { HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.set(HttpHeaders.ACCEPT, "*/*"); if (lastModified != null) { requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified)); } HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); ResponseEntity<OrderFeed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, OrderFeed.class); if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) { log.trace("data has been modified"); OrderFeed feed = response.getBody(); for (OrderFeedEntry entry : feed.getOrders()) { if ((lastModified == null) || (entry.getUpdated().after(lastModified))) { Shipment shipping = restTemplate .getForEntity(entry.getLink(), 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"); } }
Example 15
Source File: CreditDecisionPoller.java From event-driven-spring-boot with Apache License 2.0 | 4 votes |
@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); } } } }
Example 16
Source File: CreditAgencyPoller.java From ddd-with-spring with Apache License 2.0 | 4 votes |
@Scheduled(fixedDelay = 30000) public void poll() { HttpHeaders requestHeaders = new HttpHeaders(); if (lastModified != null) { requestHeaders.set("If-Modified-Since", DateUtils.formatDate(lastModified)); } HttpEntity<?> requestEntity = new HttpEntity(requestHeaders); log.info("Polling Credit Agency for new ratings"); ResponseEntity<Feed> response = restTemplate.exchange(creditAgencyFeed, HttpMethod.GET, requestEntity, Feed.class); if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) { Feed feed = response.getBody(); Date lastUpdateInFeed = null; ObjectMapper mapper = new ObjectMapper(); for (Entry entry : feed.getEntries()) { String ratingAsJson = entry.getSummary().getValue(); if ((lastModified == null) || (entry.getUpdated().after(lastModified))) { log.info(entry.getTitle() + " is new, processing"); try { AgencyRating agencyRating = mapper.readValue(ratingAsJson, AgencyRating.class); scoringApplicationService.scoreAgencyResult(agencyRating.getFirstName(), agencyRating.getLastName(), agencyRating.getStreet(), agencyRating.getPostCode(), agencyRating.getCity(), agencyRating.getPoints()); lastUpdateInFeed = entry.getUpdated(); } catch (IOException e) { //we should handle this exception more properly e.printStackTrace(); } } } 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); } } } }
Example 17
Source File: FileNameComparator.java From AthenaServing with Apache License 2.0 | 4 votes |
@Override public int compare(String o1, String o2) { Date date1 = DateUtils.parseDate(o1, dateFormats); Date date2 = DateUtils.parseDate(o2, dateFormats); return date2.compareTo(date1); }
Example 18
Source File: StringUtils.java From htmlunit with Apache License 2.0 | 3 votes |
/** * Parses the specified date string, assuming that it is formatted according to RFC 1123, RFC 1036 or as an ANSI * C HTTP date header. This method returns {@code null} if the specified string is {@code null} or unparseable. * * @param s the string to parse as a date * @return the date version of the specified string, or {@code null} */ public static Date parseHttpDate(final String s) { if (s == null) { return null; } return DateUtils.parseDate(s); }