本文整理汇总了Java中org.apache.commons.httpclient.util.DateParseException类的典型用法代码示例。如果您正苦于以下问题:Java DateParseException类的具体用法?Java DateParseException怎么用?Java DateParseException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DateParseException类属于org.apache.commons.httpclient.util包,在下文中一共展示了DateParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restrictions
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
@Test
public void restrictions() throws IOException, DateParseException
{
String stagingUrl = staging.create();
// put a file to the folder1 content url
final File file = new File(getPathFromUrl(Attachments.get("avatar.png")));
Response response = staging.putFile(stagingUrl, AVATAR_PATH, file);
assertEquals(response.getHeader("ETag"), AVATAR_PNG_ETAG);
RequestSpecification notModified = staging.notModified();
notModified.header("If-None-Match", AVATAR_PNG_ETAG);
staging.get(notModified, stagingUrl, AVATAR_PATH);
response = staging.head(stagingUrl, AVATAR_PATH);
Date date = DateUtil.parseDate(response.header("Last-Modified"));
notModified = staging.notModified();
notModified.header("If-Modified-Since", DateUtil.formatDate(date));
staging.get(notModified, stagingUrl, AVATAR_PATH);
}
示例2: appendTimeField
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
protected static void appendTimeField(StringBuilder builder, Object obj) {
if(builder.length()>0) {
// prepend with delimiter
builder.append(' ');
}
if(obj==null) {
builder.append("-");
return;
}
if(obj instanceof Header) {
String s = ((Header)obj).getValue().trim();
try {
Date date = DateUtil.parseDate(s);
String d = ArchiveUtils.get14DigitDate(date);
if(d.startsWith("209")) {
d = "199"+d.substring(3);
}
obj = d;
} catch (DateParseException e) {
builder.append('e');
return;
}
}
builder.append(obj);
}
示例3: restrictions
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
@Test
public void restrictions() throws DateParseException
{
RequestSpecification notModified = staging.notModified();
notModified.header("If-None-Match", AVATAR_PNG_ETAG);
staging.file(notModified, ITEM_ID, AVATAR_PATH);
Response response = staging.headFile(ITEM_ID, AVATAR_PATH);
Date date = DateUtil.parseDate(response.header("Last-Modified"));
notModified = staging.notModified();
notModified.header("If-Modified-Since", DateUtil.formatDate(date));
staging.file(notModified, ITEM_ID, AVATAR_PATH);
}
示例4: uploadLarge
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
@Test(groups = "eps")
public void uploadLarge() throws IOException, DateParseException
{
String stagingUrl = staging.create();
File largeFile = File.createTempFile("large", "file");
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(largeFile));
Random random = new Random();
for( int i = 0; i < LARGE_FILE_SIZE; i++ )
{
out.write(random.nextInt());
}
out.close();
largeFile.deleteOnExit();
String uploadId = staging.startMultipart(stagingUrl, LARGE_PATH);
long offset = 0;
long length = largeFile.length();
int partNum = 1;
List<Integer> partNums = Lists.newArrayList();
List<String> etags = Lists.newArrayList();
while( offset < length )
{
long left = length - offset;
long size = Math.min(left, MIN_PART_SIZE);
partNums.add(partNum);
etags.add(staging.uploadPart(stagingUrl, LARGE_PATH, uploadId, largeFile, partNum++, offset, size));
offset += size;
}
String etag = staging.completeMultipart(stagingUrl, LARGE_PATH, uploadId, partNums, etags);
Response response = staging.head(stagingUrl, LARGE_PATH);
String lenHeader = response.getHeader("Content-Length");
assertEquals(Long.parseLong(lenHeader), largeFile.length());
assertEquals(response.getHeader("E-Tag"), etag);
File downloadFile = File.createTempFile("large", "file");
staging.downloadToFile(stagingUrl, LARGE_PATH, downloadFile);
assertEquals(Files.hash(downloadFile, Hashing.md5()), Files.hash(largeFile, Hashing.md5()));
}
示例5: getTimeDiff
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
private <T> long getTimeDiff(CmsWorkOrderSimpleBase<T> wo) throws DateParseException {
String currentDate = formatDate(new Date(), SEARCH_TS_PATTERN);
long currentTime = parseDate(currentDate, SEARCH_TS_FORMATS).getTime();
long requestEnqueTime = parseDate(wo.getSearchTags().get(REQUEST_ENQUE_TS), SEARCH_TS_FORMATS)
.getTime();
return currentTime - requestEnqueTime;
}
示例6: deserialize
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
public Date deserialize(JsonElement json, Type type, JsonDeserializationContext context) {
String str = json.getAsString();
try {
return DateUtil.parseDate(str);
} catch (DateParseException e) {
try {
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssz");
return df.parse(str);
} catch (ParseException e1) {
LOGGER.log(Level.WARNING, "An exception occurred on DateTypeConverter: {0}", e.getStackTrace());
throw new JsonParseException(e);
}
}
}
示例7: getDateHeader
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
private Date getDateHeader(HttpResponse resp, String name)
throws DateParseException {
Header hd = resp.getFirstHeader(name);
if (hd == null)
return new Date();
return DateUtil.parseDate(hd.getValue());
}
示例8: findLastModifiedDate
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
/**
* Finds last modified date.
* @param headers array of headers
* @return last modified date or <code>null</code> if date not found
*/
private static Date findLastModifiedDate(ResponseInfo responseInfo) {
Header lastModfiedHeader = responseInfo.getResponseHeader("Last-Modified");
if (lastModfiedHeader != null) {
try {
return DateUtil.parseDate(lastModfiedHeader.getValue());
} catch (DateParseException ex) {
return null;
}
}
return null;
}
示例9: findLastModifiedDate
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
/**
* Finds last modified date.
* @param headers array of headers
* @return last modified date or <code>null</code> if date not found
*/
private static Date findLastModifiedDate(ResponseInfo responseInfo) {
Header lastModfiedHeader = responseInfo.getResponseHeader("Last-Modified");
if (lastModfiedHeader!=null) {
try {
return DateUtil.parseDate(lastModfiedHeader.getValue());
} catch (DateParseException ex) {
return null;
}
}
return null;
}
示例10: nsa
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
@RequestMapping(value = "/nsa-discovery", method = RequestMethod.GET, produces = NsiHelper.NSA_MIMETYPE + ";charset=" + CHARSET)
@ResponseBody
public String nsa(HttpServletRequest request, HttpServletResponse response) throws JAXBException, DateParseException {
NsaType nsaType = nsiInfraDocumentsService.nsaDiscovery();
Date version = nsaType.getVersion().toGregorianCalendar().getTime();
return handleRequest(NsiConverters.DISCOVERY_CONVERTER.toXmlString(nsaType), version, request, response);
}
示例11: handleRequest
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
private String handleRequest(final String document, final Date version, final HttpServletRequest request, final HttpServletResponse response) throws DateParseException {
response.addHeader(HttpHeaders.LAST_MODIFIED, DateUtil.formatDate(version));
if (!isModifiedSince(request.getHeaders(HttpHeaders.IF_MODIFIED_SINCE), version)) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return null;
}
return document;
}
示例12: isModifiedSince
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
private boolean isModifiedSince(final Enumeration<String> ifModifiedSinceValues, final Date lastModified) throws DateParseException {
DateTime lastModifiedDateTime = new DateTime(lastModified);
if (ifModifiedSinceValues.hasMoreElements()) {
DateTime ifModifiedSince = new DateTime(DateUtil.parseDate(ifModifiedSinceValues.nextElement()));
return ifModifiedSince.isBefore(lastModifiedDateTime);
}
return true;
}
示例13: discovery
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
@RequestMapping(value = "/nsi-requester-offline/discovery", method = RequestMethod.GET, produces = NsiHelper.NSA_MIMETYPE)
@ResponseBody
public String discovery(HttpServletRequest request, HttpServletResponse response) throws JAXBException, DateParseException {
NsaType nsa = new NsaType()
.withId(environment.getLocalNsiProviderNsa())
.withVersion(version)
.withInterface(
new InterfaceType().withType(NsiHelper.PROVIDER_PROTOCOL_VERSION).withHref(environment.getExternalBodUrl() + "/nsi/v2/requester-offline/provider"),
new InterfaceType().withType(NsiHelper.TOPOLOGY_MIMETYPE).withHref(environment.getExternalBodUrl() + "/nsi-requester-offline/topology"));
return handleRequest(NsiConverters.DISCOVERY_CONVERTER.toXmlString(nsa), version.toGregorianCalendar().getTime(), request, response);
}
示例14: discoveryRemoteProvider
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
@RequestMapping(value = "/nsi-requester-offline/discovery/remote", method = RequestMethod.GET, produces = NsiHelper.NSA_MIMETYPE)
@ResponseBody
public String discoveryRemoteProvider(HttpServletRequest request, HttpServletResponse response) throws JAXBException, DateParseException {
NsaType nsa = new NsaType()
.withId(environment.getRemoteNsiProviderNsa().get())
.withVersion(version)
.withInterface(
new InterfaceType().withType(NsiHelper.PROVIDER_PROTOCOL_VERSION).withHref(environment.getExternalBodUrl() + "/nsi/v2/requester-offline/provider"),
new InterfaceType().withType(NsiHelper.TOPOLOGY_MIMETYPE).withHref(environment.getExternalBodUrl() + "/nsi-requester-offline/topology"));
return handleRequest(NsiConverters.DISCOVERY_CONVERTER.toXmlString(nsa), version.toGregorianCalendar().getTime(), request, response);
}
示例15: isModifiedSince
import org.apache.commons.httpclient.util.DateParseException; //导入依赖的package包/类
private boolean isModifiedSince (final Enumeration<String> ifModifiedSinceValues, final Date lastModified) throws DateParseException {
DateTime lastModifiedDateTime = new DateTime(lastModified);
if (ifModifiedSinceValues.hasMoreElements()) {
DateTime ifModifiedSince = new DateTime(DateUtil.parseDate(ifModifiedSinceValues.nextElement()));
return ifModifiedSince.isBefore(lastModifiedDateTime);
}
return true;
}