List of usage examples for java.time.format DateTimeFormatter RFC_1123_DATE_TIME
DateTimeFormatter RFC_1123_DATE_TIME
To view the source code for java.time.format DateTimeFormatter RFC_1123_DATE_TIME.
Click Source Link
From source file:de.bytefish.fcmjava.client.tests.http.apache.utils.RetryHeaderUtilsTest.java
@Test public void headerFoundWithDateTimeInFutureContentTest() { // We assume the HTTP Header to contain an RFC1123-compliant DateTime value: DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; String formattedStringInFuture = formatter.format(DateUtils.getUtcNow().plusYears(1)); // Expectations when(headerMock.getValue()).thenReturn(formattedStringInFuture); when(httpResponseMock.getFirstHeader("Retry-After")).thenReturn(headerMock); // Holds the Result: OutParameter<Duration> result = new OutParameter<>(); // Try to get the Result: boolean success = RetryHeaderUtils.tryDetermineRetryDelay(httpResponseMock, result); // Assertions: Assert.assertEquals(true, success);//from www.ja v a 2 s . c o m Assert.assertNotEquals(0, result.get().getSeconds()); Assert.assertTrue(result.get().getSeconds() > 120); }
From source file:de.bytefish.fcmjava.client.tests.interceptors.response.utils.RetryHeaderUtilsTest.java
@Test public void headerFoundWithDateTimeInFutureContentTest() { // We assume the HTTP Header to contain an RFC1123-compliant DateTime value: DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; String formattedStringInFuture = formatter.format(DateUtils.getUtcNow().plusYears(1)); // Expectations when(headerMock.getValue()).thenReturn(formattedStringInFuture); when(httpResponseMock.getFirstHeader("Retry-After")).thenReturn(headerMock); // Holds the Result: OutParameter<Duration> result = new OutParameter<Duration>(); // Try to get the Result: boolean success = RetryHeaderUtils.tryDetermineRetryDelay(httpResponseMock, result); // Assertions: Assert.assertEquals(true, success);/*from w w w . java 2s . c o m*/ Assert.assertNotEquals(0, result.get().getSeconds()); Assert.assertTrue(result.get().getSeconds() > 120); }
From source file:eu.over9000.skadi.ui.dialogs.UpdateAvailableDialog.java
public UpdateAvailableDialog(RemoteVersionResult newVersion) { super(AlertType.INFORMATION, null, UPDATE_BUTTON_TYPE, IGNORE_BUTTON_TYPE); this.setTitle("Update available"); this.setHeaderText(newVersion.getVersion() + " is available"); Label lbChangeLog = new Label("Changelog:"); TextArea taChangeLog = new TextArea(newVersion.getChangeLog()); taChangeLog.setEditable(false);/*w w w . jav a2 s. c o m*/ taChangeLog.setWrapText(true); Label lbSize = new Label("Size:"); Label lbSizeValue = new Label(FileUtils.byteCountToDisplaySize(newVersion.getSize())); Label lbPublished = new Label("Published"); Label lbPublishedValue = new Label( ZonedDateTime.parse(newVersion.getPublished()).format(DateTimeFormatter.RFC_1123_DATE_TIME)); final GridPane grid = new GridPane(); RowConstraints vAlign = new RowConstraints(); vAlign.setValignment(VPos.TOP); grid.getRowConstraints().add(vAlign); grid.setHgap(10); grid.setVgap(10); grid.add(lbChangeLog, 0, 0); grid.add(taChangeLog, 1, 0); grid.add(lbPublished, 0, 1); grid.add(lbPublishedValue, 1, 1); grid.add(lbSize, 0, 2); grid.add(lbSizeValue, 1, 2); this.getDialogPane().setContent(grid); }
From source file:de.bytefish.fcmjava.client.http.apache.utils.RetryHeaderUtils.java
private static boolean tryToConvertToDate(String dateAsString, OutParameter<ZonedDateTime> result) { try {/*w w w. j a v a2 s . c om*/ // We assume the HTTP Header to contain an RFC1123-compliant DateTime value: DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME; // Try to parse and set it as the result: result.set(ZonedDateTime.parse(dateAsString, formatter)); return true; } catch (Exception e) { return false; } }
From source file:org.haiku.haikudepotserver.job.controller.JobController.java
/** * <p>This is helper-code that can be used to check to see if the data is stale and * will then enqueue the job, run it and then redirect the user to the data * download.</p>/*from w ww. ja v a 2 s .c o m*/ * @param response is the HTTP response to send the redirect to. * @param ifModifiedSinceHeader is the inbound header from the client. * @param lastModifyTimestamp is the actual last modified date for the data. * @param jobSpecification is the job that would be run if the data is newer than in the * inbound header. */ public static void handleRedirectToJobData(HttpServletResponse response, JobService jobService, String ifModifiedSinceHeader, Date lastModifyTimestamp, JobSpecification jobSpecification) throws IOException { if (!Strings.isNullOrEmpty(ifModifiedSinceHeader)) { try { Date requestModifyTimestamp = new Date(Instant .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifModifiedSinceHeader)).toEpochMilli()); if (requestModifyTimestamp.getTime() >= lastModifyTimestamp.getTime()) { response.setStatus(HttpStatus.NOT_MODIFIED.value()); return; } } catch (DateTimeParseException dtpe) { LOGGER.warn("bad [{}] header on request; [{}] -- will ignore", HttpHeaders.IF_MODIFIED_SINCE, StringUtils.abbreviate(ifModifiedSinceHeader, 128)); } } // what happens here is that we get the report and if it is too old, delete it and try again. JobSnapshot jobSnapshot = getJobSnapshotStartedAfter(jobService, lastModifyTimestamp, jobSpecification); Set<String> jobDataGuids = jobSnapshot.getDataGuids(); if (1 != jobDataGuids.size()) { throw new IllegalStateException("found [" + jobDataGuids.size() + "] job data guids related to the job [" + jobSnapshot.getGuid() + "] - was expecting 1"); } String lastModifiedValue = DateTimeFormatter.RFC_1123_DATE_TIME .format(ZonedDateTime.ofInstant(lastModifyTimestamp.toInstant(), ZoneOffset.UTC)); String destinationLocationUrl = UriComponentsBuilder.newInstance() .pathSegment(AuthenticationFilter.SEGMENT_SECURED).pathSegment(JobController.SEGMENT_JOBDATA) .pathSegment(jobDataGuids.iterator().next()).pathSegment(JobController.SEGMENT_DOWNLOAD) .toUriString(); response.addHeader(HttpHeaders.LAST_MODIFIED, lastModifiedValue); response.sendRedirect(destinationLocationUrl); }
From source file:com.esri.geoportal.harvester.waf.WafFile.java
/** * Reads last modified date./*from w ww . j a v a 2s. c o m*/ * @param response HTTP response * @return last modified date or <code>null</code> if unavailable */ private Date readLastModifiedDate(HttpResponse response) { try { Header lastModifedHeader = response.getFirstHeader("Last-Modified"); return lastModifedHeader != null ? Date.from(ZonedDateTime .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(lastModifedHeader.getValue())).toInstant()) : null; } catch (Exception ex) { return null; } }
From source file:org.springframework.session.web.http.DefaultCookieSerializer.java
@Override public void writeCookieValue(CookieValue cookieValue) { HttpServletRequest request = cookieValue.getRequest(); HttpServletResponse response = cookieValue.getResponse(); StringBuilder sb = new StringBuilder(); sb.append(this.cookieName).append('='); String value = getValue(cookieValue); if (value != null && value.length() > 0) { validateValue(value);/*from w w w . j a v a 2s. c om*/ sb.append(value); } int maxAge = getMaxAge(cookieValue); if (maxAge > -1) { sb.append("; Max-Age=").append(cookieValue.getCookieMaxAge()); OffsetDateTime expires = (maxAge != 0) ? OffsetDateTime.now().plusSeconds(maxAge) : Instant.EPOCH.atOffset(ZoneOffset.UTC); sb.append("; Expires=").append(expires.format(DateTimeFormatter.RFC_1123_DATE_TIME)); } String domain = getDomainName(request); if (domain != null && domain.length() > 0) { validateDomain(domain); sb.append("; Domain=").append(domain); } String path = getCookiePath(request); if (path != null && path.length() > 0) { validatePath(path); sb.append("; Path=").append(path); } if (isSecureCookie(request)) { sb.append("; Secure"); } if (this.useHttpOnlyCookie) { sb.append("; HttpOnly"); } if (this.sameSite != null) { sb.append("; SameSite=").append(this.sameSite); } response.addHeader("Set-Cookie", sb.toString()); }
From source file:net.dv8tion.jda.core.requests.ratelimit.BotRateLimiter.java
private void setTimeOffset(Headers headers) { //Store as soon as possible to get the most accurate time difference; long time = System.currentTimeMillis(); if (timeOffset == null) { //Get the date header provided by Discord. //Format: "date" : "Fri, 16 Sep 2016 05:49:36 GMT" String date = headers.get("Date"); if (date != null) { OffsetDateTime tDate = OffsetDateTime.parse(date, DateTimeFormatter.RFC_1123_DATE_TIME); long lDate = tDate.toInstant().toEpochMilli(); //We want to work in milliseconds, not seconds timeOffset = lDate - time; //Get offset in milliseconds. }//w w w .jav a2s. c o m } }
From source file:org.cryptomator.frontend.webdav.jackrabbitservlet.FilesystemResourceFactory.java
/** * @return <code>true</code> if a partial response should be generated according to an If-Range precondition. *//*from w ww .j av a 2s .c om*/ private boolean isIfRangeHeaderSatisfied(FileLocator file, String ifRangeHeader) throws DavException { if (ifRangeHeader == null) { // no header set -> satisfied implicitly return true; } else { try { Instant expectedTime = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifRangeHeader)); Instant actualTime = file.lastModified(); return expectedTime.compareTo(actualTime) == 0; } catch (DateTimeParseException e) { throw new DavException(DavServletResponse.SC_BAD_REQUEST, "Unsupported If-Range header: " + ifRangeHeader); } } }
From source file:org.cryptomator.frontend.webdav.servlet.DavNode.java
private Optional<DavProperty<?>> lastModifiedDateProperty(DavPropertyName name) { return attr.map(BasicFileAttributes::lastModifiedTime) // .map(FileTime::toInstant) // .map(creationTime -> OffsetDateTime.ofInstant(creationTime, ZoneOffset.UTC)) // .map(creationDate -> new DefaultDavProperty<>(name, DateTimeFormatter.RFC_1123_DATE_TIME.format(creationDate))); }