org.apache.commons.httpclient.util.DateParseException Java Examples

The following examples show how to use org.apache.commons.httpclient.util.DateParseException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public long getHeaderFieldDate(String key, long def) throws IOException {
  HttpMethod res = getResult(true);
  Header head = res.getResponseHeader(key);

  if (head == null) {
    return def;
  }

  try {
    Date date = DateUtil.parseDate(head.getValue());
    return date.getTime();

  } catch (DateParseException e) {
    return def;
  }
}
 
Example #2
Source File: ARC2WCDX.java    From webarchive-commons with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: Listener.java    From oneops with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: HttpClientConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public long getDate() throws IOException {
  final HttpMethod res = getResult(true);
  final Header head = res.getResponseHeader("Date");

  if (head == null) {
    return 0;
  }

  try {
    return DateUtil.parseDate(head.getValue()).getTime();
  } catch (DateParseException e) {
    return 0;
  }
}
 
Example #5
Source File: HttpClientConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public long getExpiration() throws IOException {
  HttpMethod res = getResult(true);
  Header head = res.getResponseHeader("Expires");

  if (head == null) {
    return 0;
  }

  try {
    return DateUtil.parseDate(head.getValue()).getTime();
  } catch (DateParseException e) {
    return 0;
  }
}
 
Example #6
Source File: HttpClientConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public long getLastModified() throws IOException {
  HttpMethod res = getResult(true);
  Header head = res.getResponseHeader("Last-Modified");

  if (head != null) {
    try {
      return DateUtil.parseDate(head.getValue()).getTime();
    } catch (DateParseException e) {
      return 0;
    }
  }

  return 0;
}
 
Example #7
Source File: CacheableScanRule.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
private Date parseDate(String dateStr) {
    Date newDate = null;
    try {
        newDate = DateUtil.parseDate(dateStr);
    } catch (DateParseException dpe) {
        // There was an error parsing the date, leave the var null
    }
    return newDate;
}
 
Example #8
Source File: AbstractOrderExecutor.java    From oneops with Apache License 2.0 4 votes vote down vote up
private long getTimeElapsed(CmsWorkOrderSimpleBase wo) throws DateParseException {
  return System.currentTimeMillis() - DateUtil
      .parseDate(getSearchTag(wo, REQUEST_DEQUE_TS), SEARCH_TS_FORMATS).getTime();
}
 
Example #9
Source File: CookieSpecBase.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
  * Parse the cookie attribute and update the corresponsing {@link Cookie}
  * properties.
  *
  * @param attribute {@link HeaderElement} cookie attribute from the
  * <tt>Set- Cookie</tt>
  * @param cookie {@link Cookie} to be updated
  * @throws MalformedCookieException if an exception occurs during parsing
  */

public void parseAttribute(
    final NameValuePair attribute, final Cookie cookie)
    throws MalformedCookieException {
        
    if (attribute == null) {
        throw new IllegalArgumentException("Attribute may not be null.");
    }
    if (cookie == null) {
        throw new IllegalArgumentException("Cookie may not be null.");
    }
    final String paramName = attribute.getName().toLowerCase();
    String paramValue = attribute.getValue();

    if (paramName.equals("path")) {

        if ((paramValue == null) || (paramValue.trim().equals(""))) {
            paramValue = "/";
        }
        cookie.setPath(paramValue);
        cookie.setPathAttributeSpecified(true);

    } else if (paramName.equals("domain")) {

        if (paramValue == null) {
            throw new MalformedCookieException(
                "Missing value for domain attribute");
        }
        if (paramValue.trim().equals("")) {
            throw new MalformedCookieException(
                "Blank value for domain attribute");
        }
        cookie.setDomain(paramValue);
        cookie.setDomainAttributeSpecified(true);

    } else if (paramName.equals("max-age")) {

        if (paramValue == null) {
            throw new MalformedCookieException(
                "Missing value for max-age attribute");
        }
        int age;
        try {
            age = Integer.parseInt(paramValue);
        } catch (NumberFormatException e) {
            throw new MalformedCookieException ("Invalid max-age "
                + "attribute: " + e.getMessage());
        }
        cookie.setExpiryDate(
            new Date(System.currentTimeMillis() + age * 1000L));

    } else if (paramName.equals("secure")) {

        cookie.setSecure(true);

    } else if (paramName.equals("comment")) {

        cookie.setComment(paramValue);

    } else if (paramName.equals("expires")) {

        if (paramValue == null) {
            throw new MalformedCookieException(
                "Missing value for expires attribute");
        }

        try {
            cookie.setExpiryDate(DateUtil.parseDate(paramValue, this.datepatterns));
        } catch (DateParseException dpe) {
            LOG.debug("Error parsing cookie date", dpe);
            throw new MalformedCookieException(
                "Unable to parse expiration date parameter: " 
                + paramValue);
        }
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Unrecognized cookie attribute: " 
                + attribute.toString());
        }
    }
}