本文整理了Java中org.apache.commons.httpclient.util.DateUtil.formatDate()
方法的一些代码示例,展示了DateUtil.formatDate()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DateUtil.formatDate()
方法的具体详情如下:
包路径:org.apache.commons.httpclient.util.DateUtil
类名称:DateUtil
方法名:formatDate
[英]Formats the given date according to the RFC 1123 pattern.
[中]根据RFC1123模式设置给定日期的格式。
代码示例来源:origin: commons-httpclient/commons-httpclient
/**
* 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);
}
代码示例来源:origin: org.apache.commons/httpclient
/**
* 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);
}
代码示例来源:origin: org.wso2.commons-httpclient/commons-httpclient
/**
* 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);
}
代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient
/**
* 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);
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient
/**
* 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);
}
代码示例来源:origin: org.littleshoot/util
/**
* 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());
}
代码示例来源:origin: org.apache.abdera/abdera-client
/**
* 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));
}
代码示例来源:origin: OneBusAway/onebusaway-application-modules
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;
}
代码示例来源:origin: org.onebusaway/onebusaway-presentation
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;
}
代码示例来源:origin: org.apache.abdera/abdera-client
/**
* 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);
}
代码示例来源:origin: org.onebusaway/onebusaway-presentation
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);
}
代码示例来源:origin: org.fcrepo/fcrepo-server
/**
* 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;
}
代码示例来源:origin: fcrepo3/fcrepo
/**
* 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;
}
代码示例来源:origin: OneBusAway/onebusaway-application-modules
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);
}
代码示例来源:origin: org.geoserver/gwc
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 + "'");
}
}
}
}
代码示例来源:origin: org.geoserver/gs-gwc
org.apache.commons.httpclient.util.DateUtil.formatDate(new Date(tileTimeStamp));
map.setResponseHeader("Last-Modified", lastModified);
代码示例来源:origin: fcrepo3/fcrepo
/**
* 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;
}
代码示例来源:origin: org.fcrepo/fcrepo-server
/**
* 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;
}
代码示例来源:origin: digital-preservation/droid
try {
Date versiOnDate= getDateFromVersion(currentVersion);
String dateString = DateUtil.formatDate(versionDate);
get.addRequestHeader("If-Modified-Since", dateString);
代码示例来源:origin: org.geoserver/gwc
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());
}