/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Formats the given date according to the RFC 1123 pattern. * * @param date The date to format. * @return An RFC 1123 formatted date string. * * @see #PATTERN_RFC1123 */ public static String formatDate(Date date) { return formatDate(date, PATTERN_RFC1123); }
/** * Generate an RFC 822 date for use in the Date HTTP header. * * @return The HTTP Date string. */ public static String createHttpDate() { /* final String DateFormat = "EEE, dd MMM yyyy HH:mm:ss Z"; final SimpleDateFormat format = new SimpleDateFormat(DateFormat, Locale.US); format.setTimeZone(TimeZone.getTimeZone("GMT")); return format.format(new Date()); */ return DateUtil.formatDate(new Date()); }
/** * Similar to setDateHeader but allows for multiple instances of the specified header */ public RequestOptions addDateHeader(String header, Date value) { if (value == null) return this; return addHeader(header, DateUtil.formatDate(value)); }
private Date applyLastModifiedHeader(ActionInvocation invocation, CacheControl cacheControl, HttpServletRequest request, HttpServletResponse response) { Date lastModifiedTime = invokeDateMethod(invocation, cacheControl.lastModifiedMethod()); if (lastModifiedTime == null) return null; String lastModifiedTimeAsString = DateUtil.formatDate(lastModifiedTime); response.setHeader("Last-Modified", lastModifiedTimeAsString); return lastModifiedTime; }
private Date applyLastModifiedHeader(ActionInvocation invocation, CacheControl cacheControl, HttpServletRequest request, HttpServletResponse response) { Date lastModifiedTime = invokeDateMethod(invocation, cacheControl.lastModifiedMethod()); if (lastModifiedTime == null) return null; String lastModifiedTimeAsString = DateUtil.formatDate(lastModifiedTime); response.setHeader("Last-Modified", lastModifiedTimeAsString); return lastModifiedTime; }
/** * Set the date value of the specified HTTP header */ public RequestOptions setDateHeader(String header, Date value) { return value != null ? setHeader(header, DateUtil.formatDate(value)) : removeHeaders(header); }
private void applyExpiresHeader(ActionInvocation invocation, CacheControl cacheControl, HttpServletRequest request, HttpServletResponse response) { Date expiresTime = null; if (cacheControl.expiresOffset() > 0) { expiresTime = new Date(System.currentTimeMillis() + cacheControl.expiresOffset()); } else { expiresTime = invokeDateMethod(invocation, cacheControl.expiresMethod()); } if (expiresTime == null) return; String expiresTimeAsString = DateUtil.formatDate(expiresTime); response.setHeader("Expires", expiresTimeAsString); }
/** * Content-Length is determined elsewhere * Content-Type is determined elsewhere * Last-Modified * ETag * @param String canonicalPath: the canonical path to a file system resource * @param lastModified lastModified: the date of last modification * @return */ private static Property[] getFileDatastreamHeaders(String canonicalPath, long lastModified) { Property[] result = new Property[3]; String eTag = MD5Utility.getBase16Hash(canonicalPath.concat(Long.toString(lastModified))); result[0] = new Property(HttpHeaders.ACCEPT_RANGES,"bytes"); result[1] = new Property(HttpHeaders.ETAG, eTag); result[2] = new Property(HttpHeaders.LAST_MODIFIED, DateUtil.formatDate(new Date(lastModified))); return result; }
/** * Content-Length is determined elsewhere * Content-Type is determined elsewhere * Last-Modified * ETag * @param String canonicalPath: the canonical path to a file system resource * @param lastModified lastModified: the date of last modification * @return */ private static Property[] getFileDatastreamHeaders(String canonicalPath, long lastModified) { Property[] result = new Property[3]; String eTag = MD5Utility.getBase16Hash(canonicalPath.concat(Long.toString(lastModified))); result[0] = new Property(HttpHeaders.ACCEPT_RANGES,"bytes"); result[1] = new Property(HttpHeaders.ETAG, eTag); result[2] = new Property(HttpHeaders.LAST_MODIFIED, DateUtil.formatDate(new Date(lastModified))); return result; }
private void applyExpiresHeader(ActionInvocation invocation, CacheControl cacheControl, HttpServletRequest request, HttpServletResponse response) { Date expiresTime = null; if (cacheControl.expiresOffset() > 0) { expiresTime = new Date(SystemTime.currentTimeMillis() + cacheControl.expiresOffset()); } else { expiresTime = invokeDateMethod(invocation, cacheControl.expiresMethod()); } if (expiresTime == null) return; String expiresTimeAsString = DateUtil.formatDate(expiresTime); response.setHeader("Expires", expiresTimeAsString); }
private void setConditionalGetHeaders(RawMap map, ConveyorTile cachedTile, GetMapRequest request, String etag) { map.setResponseHeader("ETag", etag); final long tileTimeStamp = cachedTile.getTSCreated(); final String ifModSinceHeader = request.getHttpRequestHeader("If-Modified-Since"); // commons-httpclient's DateUtil can encode and decode timestamps formatted as per RFC-1123, // which is one of the three formats allowed for Last-Modified and If-Modified-Since headers // (e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'). See // http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 final String lastModified = org.apache.commons.httpclient.util.DateUtil .formatDate(new Date(tileTimeStamp)); map.setResponseHeader("Last-Modified", lastModified); final Date ifModifiedSince; if (ifModSinceHeader != null && ifModSinceHeader.length() > 0) { try { ifModifiedSince = DateUtil.parseDate(ifModSinceHeader); // the HTTP header has second precision long ifModSinceSeconds = 1000 * (ifModifiedSince.getTime() / 1000); long tileTimeStampSeconds = 1000 * (tileTimeStamp / 1000); if (ifModSinceSeconds >= tileTimeStampSeconds) { throw new HttpErrorCodeException(HttpServletResponse.SC_NOT_MODIFIED); } } catch (DateParseException e) { if (LOGGER.isLoggable(Level.FINER)) { LOGGER.finer("Can't parse client's If-Modified-Since header: '" + ifModSinceHeader + "'"); } } } }
org.apache.commons.httpclient.util.DateUtil.formatDate(new Date(tileTimeStamp)); map.setResponseHeader("Last-Modified", lastModified);
/** * Content-Length is determined elsewhere * Content-Type is determined elsewhere * Last-Modified * ETag * @param ds * @return */ private static Property[] getDatastreamHeaders(String pid, Datastream ds) { Property[] result = new Property[3]; result[0] = new Property(HttpHeaders.ACCEPT_RANGES,"bytes"); result[1] = new Property(HttpHeaders.ETAG, Datastream.defaultETag(pid, ds)); result[2] = new Property(HttpHeaders.LAST_MODIFIED, DateUtil.formatDate(ds.DSCreateDT)); return result; }
/** * Content-Length is determined elsewhere * Content-Type is determined elsewhere * Last-Modified * ETag * @param ds * @return */ private static Property[] getDatastreamHeaders(String pid, Datastream ds) { Property[] result = new Property[3]; result[0] = new Property(HttpHeaders.ACCEPT_RANGES,"bytes"); result[1] = new Property(HttpHeaders.ETAG, Datastream.defaultETag(pid, ds)); result[2] = new Property(HttpHeaders.LAST_MODIFIED, DateUtil.formatDate(ds.DSCreateDT)); return result; }
try { Date versionDate = getDateFromVersion(currentVersion); String dateString = DateUtil.formatDate(versionDate); get.addRequestHeader("If-Modified-Since", dateString);
public void testDirectWMSIntegrationIfModifiedSinceSupport() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); final String path = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(path); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); String lastModifiedHeader = response.getHeader("Last-Modified"); assertNotNull(lastModifiedHeader); Date lastModified = DateUtil.parseDate(lastModifiedHeader); MockHttpServletRequest httpReq = createRequest(path); httpReq.setMethod("GET"); httpReq.setBodyContent(new byte[] {}); httpReq.setHeader("If-Modified-Since", lastModifiedHeader); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); // set the If-Modified-Since header to some point in the past of the last modified value Date past = new Date(lastModified.getTime() - 5000); String ifModifiedSince = DateUtil.formatDate(past); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); Date future = new Date(lastModified.getTime() + 5000); ifModifiedSince = DateUtil.formatDate(future); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); }