List of usage examples for org.apache.http.client.utils DateUtils parseDate
public static Date parseDate(final String dateValue)
From source file:com.k42b3.quantum.handler.MessageHandler.java
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getMethod().equals("GET")) { response.setStatus(HttpServletResponse.SC_OK); response.setContentType("application/json;charset=utf-8"); baseRequest.setHandled(true);// ww w.j av a 2 s . com try { String modifiedSince = request.getHeader("If-Modified-Since"); Date date = null; if (modifiedSince != null && !modifiedSince.isEmpty()) { date = DateUtils.parseDate(modifiedSince); } response.getWriter() .print(container.getGson().toJson(container.getMessageRepository().getAll(date))); } catch (SQLException e) { this.handleException(response, e); } } else if (request.getMethod().equals("POST")) { Message message = container.getGson().fromJson(readRequestBody(request), Message.class); container.getEventPublisher().publish(null, message); response.setContentType("application/json;charset=utf-8"); response.setStatus(HttpServletResponse.SC_CREATED); response.getWriter().print(container.getGson().toJson(message)); } }
From source file:net.siegmar.japtproxy.fetcher.FetchedResourceHttp.java
/** * {@inheritDoc}// www . jav a2 s . c om */ @Override public long getLastModified() { final Header lastModifiedHeader = httpGet.getFirstHeader(HttpHeaderConstants.LAST_MODIFIED); if (lastModifiedHeader == null) { return 0; } final Date parsedDate = DateUtils.parseDate(lastModifiedHeader.getValue()); return parsedDate != null ? parsedDate.getTime() : 0L; }
From source file:com.gargoylesoftware.htmlunit.util.StringUtils.java
/** * Parses the specified date string, assuming that it is formatted according to RFC 1123, RFC 1036 or as an ANSI * C HTTP date header. This method returns {@code null} if the specified string is {@code null} or unparseable. * * @param s the string to parse as a date * @return the date version of the specified string, or {@code null} *///from ww w. ja va 2 s . c o m public static Date parseHttpDate(final String s) { if (s == null) { return null; } return DateUtils.parseDate(s); }
From source file:org.hawk.http.HTTPManager.java
protected String getRevision(CloseableHttpResponse response) { if (response.getStatusLine().getStatusCode() == 304) { // Not-Modified, as told by the server return lastETag; } else if (response.getStatusLine().getStatusCode() != 200) { // Request failed for some reason (4xx, 5xx: we already // handle 3xx redirects) return FIRST_REV; }//from w w w . ja va 2s .c o m final Header etagHeader = response.getFirstHeader(HEADER_ETAG); if (etagHeader != null) { lastETag = etagHeader.getValue(); return lastETag; } final Header lmHeader = response.getFirstHeader(HEADER_LAST_MODIFIED); if (lmHeader != null) { final Date lmDate = DateUtils.parseDate(lmHeader.getValue()); return lmDate.getTime() + ""; } final Header clHeader = response.getFirstHeader(HEADER_CONTENT_LENGTH); if (clHeader != null) { return clHeader.getValue(); } final HttpEntity entity = response.getEntity(); if (entity != null) { final long cLength = entity.getContentLength(); if (cLength >= 0) { return cLength + ""; } } return null; }
From source file:com.arpnetworking.configuration.triggers.UriTrigger.java
private boolean isLastModifiedChanged(final HttpResponse response) { final Header newLastModifiedHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED); if (newLastModifiedHeader != null) { final Date newLastModified = DateUtils.parseDate(newLastModifiedHeader.getValue()); if (newLastModified == null) { throw new IllegalArgumentException("Invalid last modified date"); }/*from w w w . j ava 2 s. c o m*/ if (!_previousLastModified.isPresent() || newLastModified.after(_previousLastModified.get())) { LOGGER.debug().setMessage("Uri last modified changed").addData("uri", _uri) .addData("newLastModified", newLastModified) .addData("previousLastModified", _previousLastModified).log(); _previousLastModified = Optional.of(newLastModified); return true; } } return false; }
From source file:piecework.content.concrete.RemoteResource.java
private synchronized void addDetails(CloseableHttpResponse response) { Header contentTypeHeader = response.getFirstHeader(HttpHeaders.CONTENT_TYPE); if (contentTypeHeader != null) this.contentType = contentTypeHeader.getValue(); Header contentLengthHeader = response.getFirstHeader(HttpHeaders.CONTENT_LENGTH); if (contentLengthHeader != null) { try {/*from w w w . ja v a2 s.c o m*/ this.contentLength = StringUtils.isNotEmpty(contentLengthHeader.getValue()) ? Long.valueOf(contentLengthHeader.getValue()) : -1; } catch (NumberFormatException nfe) { LOG.warn("Unable to format content length from " + contentLengthHeader.getValue() + " for " + uri.toString()); } } Header lastModifiedHeader = response.getFirstHeader(HttpHeaders.LAST_MODIFIED); if (lastModifiedHeader != null) { Date lastModifiedDate = StringUtils.isNotEmpty(lastModifiedHeader.getValue()) ? DateUtils.parseDate(lastModifiedHeader.getValue()) : null; if (lastModifiedDate != null) this.lastModified = lastModifiedDate.getTime(); } Header eTagHeader = response.getFirstHeader(HttpHeaders.ETAG); if (eTagHeader != null) this.eTag = StringUtils.isNotEmpty(eTagHeader.getValue()) ? eTagHeader.getValue() : null; this.initialized = true; }
From source file:com.apigee.callout.httpsignature.SignatureVerifierCallout.java
private long getRequestSecondsSinceEpoch(MessageContext msgCtxt) /* throws DateParseException */ { String dateString = msgCtxt.getVariable("request.header.date"); // Date header if (dateString == null) { return (new Date()).getTime() / 1000L; } // now//from w ww . java 2 s. com dateString = dateString.trim(); if (dateString.equals("")) { return (new Date()).getTime() / 1000L; } // now Date d1 = DateUtils.parseDate(dateString); long unixTime = d1.getTime() / 1000; return unixTime; // seconds since epoch }
From source file:net.es.sense.rm.api.SenseRmController.java
private long parseIfModfiedSince(String ifModifiedSince) { long ifms = 0; if (!Strings.isNullOrEmpty(ifModifiedSince)) { Date lastModified = DateUtils.parseDate(ifModifiedSince); if (lastModified != null) { ifms = lastModified.getTime(); }/* w w w . j av a 2 s . c o m*/ } return ifms; }
From source file:org.sonatype.nexus.repository.http.HttpConditions.java
@Nullable private static DateTime parseDateHeader(@Nullable final String httpDate) { if (!Strings.isNullOrEmpty(httpDate)) { final Date date = DateUtils.parseDate(httpDate); if (date != null) { return new DateTime(date.getTime()); }/*from w w w.j a v a2 s . c o m*/ } return null; }