private String toHttpDate(Date date) { SimpleDateFormat format = HttpUtils.getHttpDateFormat(); return format.format(date); }
public static Date getHttpDate(String value) { if (value == null) { return null; } try { return HttpUtils.getHttpDateFormat().parse(value); } catch (ParseException ex) { return null; } }
private void setResponseDate(MultivaluedMap<String, Object> headers, boolean firstTry) { if (!firstTry) { return; } SimpleDateFormat format = HttpUtils.getHttpDateFormat(); headers.putSingle(HttpHeaders.DATE, format.format(new Date())); }
/** * {@inheritDoc} */ @Override public Client modified(Date date, boolean ifNot) { SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); String hName = ifNot ? HttpHeaders.IF_UNMODIFIED_SINCE : HttpHeaders.IF_MODIFIED_SINCE; state.getRequestHeaders().putSingle(hName, dateFormat.format(date)); return this; }
/** * {@inheritDoc} */ @Override public Client modified(Date date, boolean ifNot) { SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); String hName = ifNot ? HttpHeaders.IF_UNMODIFIED_SINCE : HttpHeaders.IF_MODIFIED_SINCE; state.getRequestHeaders().putSingle(hName, dateFormat.format(date)); return this; }
@Override public boolean cancel(Date retryAfter) { return doCancel(HttpUtils.getHttpDateFormat().format(retryAfter)); }
private void setResponseDate(MultivaluedMap<String, Object> headers, boolean firstTry) { if (!firstTry || headers.containsKey(HttpHeaders.DATE)) { return; } SimpleDateFormat format = HttpUtils.getHttpDateFormat(); headers.putSingle(HttpHeaders.DATE, format.format(new Date())); }
/** * {@inheritDoc} */ public Client modified(Date date, boolean ifNot) { SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); String hName = ifNot ? HttpHeaders.IF_UNMODIFIED_SINCE : HttpHeaders.IF_MODIFIED_SINCE; state.getRequestHeaders().putSingle(hName, dateFormat.format(date)); return this; }
@Override public void cancel(Date retryAfter) { doCancel(HttpUtils.getHttpDateFormat().format(retryAfter)); }
private ResponseBuilder evaluateIfNotModifiedSince(Date lastModified) { List<String> ifNotModifiedSince = headers.getRequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE); if (ifNotModifiedSince == null || ifNotModifiedSince.isEmpty()) { return null; } SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); dateFormat.setLenient(false); Date dateSince = null; try { dateSince = dateFormat.parse(ifNotModifiedSince.get(0)); } catch (ParseException ex) { // invalid header value, request should continue return Response.status(Response.Status.PRECONDITION_FAILED); } if (dateSince.before(lastModified)) { return Response.status(Response.Status.PRECONDITION_FAILED); } return null; }
private ResponseBuilder evaluateIfNotModifiedSince(Date lastModified) { List<String> ifNotModifiedSince = headers.getRequestHeader(HttpHeaders.IF_UNMODIFIED_SINCE); if (ifNotModifiedSince == null || ifNotModifiedSince.size() == 0) { return null; } SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); dateFormat.setLenient(false); Date dateSince = null; try { dateSince = dateFormat.parse(ifNotModifiedSince.get(0)); } catch (ParseException ex) { // invalid header value, request should continue return Response.status(Response.Status.PRECONDITION_FAILED); } if (dateSince.before(lastModified)) { return Response.status(Response.Status.PRECONDITION_FAILED); } return null; }
private ResponseBuilder evaluateIfModifiedSince(Date lastModified) { List<String> ifModifiedSince = headers.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE); if (ifModifiedSince == null || ifModifiedSince.isEmpty()) { return null; } SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); dateFormat.setLenient(false); Date dateSince = null; try { dateSince = dateFormat.parse(ifModifiedSince.get(0)); } catch (ParseException ex) { // invalid header value, request should continue return Response.status(Response.Status.PRECONDITION_FAILED); } if (dateSince.before(lastModified)) { // request should continue return null; } return Response.status(Response.Status.NOT_MODIFIED); }
private ResponseBuilder evaluateIfModifiedSince(Date lastModified) { List<String> ifModifiedSince = headers.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE); if (ifModifiedSince == null || ifModifiedSince.size() == 0) { return null; } SimpleDateFormat dateFormat = HttpUtils.getHttpDateFormat(); dateFormat.setLenient(false); Date dateSince = null; try { dateSince = dateFormat.parse(ifModifiedSince.get(0)); } catch (ParseException ex) { // invalid header value, request should continue return Response.status(Response.Status.PRECONDITION_FAILED); } if (dateSince.before(lastModified)) { // request should continue return null; } return Response.status(Response.Status.NOT_MODIFIED); }
protected String createCookie(String name, String value, String path, String domain) { String contextCookie = name + "=" + value; // Setting a specific path restricts the browsers // to return a cookie only to the web applications // listening on that specific context path if (path != null) { contextCookie += ";Path=" + path; } // Setting a specific domain further restricts the browsers // to return a cookie only to the web applications // listening on the specific context path within a particular domain if (domain != null) { contextCookie += ";Domain=" + domain; } if (stateTimeToLive > 0) { // Keep the cookie across the browser restarts until it actually expires. // Note that the Expires property has been deprecated but apparently is // supported better than 'max-age' property by different browsers // (Firefox, IE, etc) Instant expires = Instant.ofEpochMilli(System.currentTimeMillis() + stateTimeToLive); String cookieExpires = HttpUtils.getHttpDateFormat().format(Date.from(expires.atZone(ZoneOffset.UTC).toInstant())); contextCookie += ";Expires=" + cookieExpires; } //TODO: Consider adding an 'HttpOnly' attribute return contextCookie; }