Java 类org.apache.commons.httpclient.util.DateParseException 实例源码

项目:Equella    文件:StagingApiTest.java   
@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);
}
项目:webarchive-commons    文件:ARC2WCDX.java   
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);
}
项目:Equella    文件:ItemDownloadTest.java   
@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);
}
项目:Equella    文件:StagingApiTest.java   
@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()));
}
项目:oneops    文件:Listener.java   
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;
}
项目:sonar-gerrit-plugin    文件:DateTypeConverter.java   
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);
        }
    }
}
项目:persistenturls    文件:RemoteGraphSupport.java   
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());
}
项目:GeoprocessingAppstore    文件:TProxy.java   
/**
 * 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;
}
项目:GeoprocessingAppstore    文件:WafProxy.java   
/**
 * 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;
}
项目:bandwidth-on-demand    文件:NsiInfraDocumentsController.java   
@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);
}
项目:bandwidth-on-demand    文件:NsiInfraDocumentsController.java   
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;
}
项目:bandwidth-on-demand    文件:NsiInfraDocumentsController.java   
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;
}
项目:bandwidth-on-demand    文件:OfflineNsaController.java   
@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);
}
项目:bandwidth-on-demand    文件:OfflineNsaController.java   
@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);
}
项目:bandwidth-on-demand    文件:OfflineNsaController.java   
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;
}
项目:bandwidth-on-demand    文件:OfflineNsaController.java   
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;
}
项目:oneops    文件:AbstractOrderExecutor.java   
private long getTimeElapsed(CmsWorkOrderSimpleBase wo) throws DateParseException {
  return System.currentTimeMillis() - DateUtil
      .parseDate(getSearchTag(wo, REQUEST_DEQUE_TS), SEARCH_TS_FORMATS).getTime();
}
项目:linkbinder    文件:ProjectLogoManager.java   
/**
 * プロジェクトロゴファイルが変更されたか否かを判断する.
 *
 * @param projectId プロジェクトID
 * @param ifModifiedSince If-Modified-Since値
 * @return true:変更された false:変更されていない
 */
public boolean isModified(String projectId, String ifModifiedSince) {
    if (log.isDebugEnabled()) {
        log.debug("projectId[" + projectId + "]");
        log.debug("ifModifiedSince[" + ifModifiedSince + "]");
    }

    if (StringUtils.isEmpty(ifModifiedSince)) {
        // If-Modified-Sinceヘッダ(値)が無いならばtrue
        return true;
    }

    long ifModifiedSinceLongValue = 0;
    try {
        Date ifModifiedSinceDateValue = DateUtil.parseDate(ifModifiedSince);
        ifModifiedSinceLongValue = ifModifiedSinceDateValue.getTime();
        if (log.isDebugEnabled()) {
            log.debug("ifModifiedSinceDateValue[" + ifModifiedSinceDateValue + "]");
            log.debug("ifModifiedSinceLongValue[" + ifModifiedSinceLongValue + "]");
        }
    } catch (DateParseException e) {
        // 日付解析失敗なので変更されたと見なす
        log.warn("If-Modified-Since parse error[" + ifModifiedSince + "]", e);
        return true;
    }

    String logoFile = detectLogoFile(projectId);
    File f = new File(logoFile);
    if (log.isDebugEnabled()) {
        log.debug("f.exists[" + f.exists() + "]");
        log.debug("f.lastModified[" + f.lastModified() + "]");
    }

    // ミリ秒の値を秒単位で比較するため1/1000する(12:34:56.789と12:34:56.000は同じと見なす)
    //CHECKSTYLE:OFF
    if (!f.exists()
          || f.lastModified() / 1000 != ifModifiedSinceLongValue / 1000) {
        return true;
    }
    //CHECKSTYLE:ON

    if (log.isDebugEnabled()) {
        log.debug("return false");
    }
    return false;
}