use of org.apache.commons.httpclient.util.DateParseException in project eclipse-integration-commons by spring-projects.
the class HttpClientTransportService method getLastModified.
/**
* Verify availability of resources at the given web locations. Normally
* this would be done using an HTTP HEAD.
*
* @param locations the locations of the resource to verify
* @param one indicate if only one of the resources must exist
* @param progressMonitor the monitor
* @return true if the resource exists
*/
public long getLastModified(java.net.URI uri, IProgressMonitor progressMonitor) throws CoreException {
WebLocation location = new WebLocation(uri.toString());
SubMonitor monitor = SubMonitor.convert(progressMonitor);
monitor.subTask(NLS.bind("Fetching {0}", location.getUrl()));
try {
HttpClient client = new HttpClient();
// $NON-NLS-1$
org.eclipse.mylyn.commons.net.WebUtil.configureHttpClient(client, "");
HeadMethod method = new HeadMethod(location.getUrl());
try {
HostConfiguration hostConfiguration = org.eclipse.mylyn.commons.net.WebUtil.createHostConfiguration(client, location, monitor);
int result = org.eclipse.mylyn.commons.net.WebUtil.execute(client, hostConfiguration, method, monitor);
if (result == HttpStatus.SC_OK) {
// $NON-NLS-1$
Header lastModified = method.getResponseHeader("Last-Modified");
if (lastModified != null) {
try {
return DateUtil.parseDate(lastModified.getValue()).getTime();
} catch (DateParseException e) {
// fall through
}
}
return 0;
} else {
throw toException(location, result);
}
} catch (IOException e) {
throw toException(location, e);
} finally {
method.releaseConnection();
}
} finally {
monitor.done();
}
}
use of org.apache.commons.httpclient.util.DateParseException in project onebusaway-application-modules by camsys.
the class CacheControlInterceptor method intercept.
@Override
public String intercept(ActionInvocation invocation) throws Exception {
CacheControl cacheControl = getCacheControlAnnotation(invocation);
if (cacheControl == null)
return invocation.invoke();
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
applyCacheControlHeader(invocation, cacheControl, request, response);
applyExpiresHeader(invocation, cacheControl, request, response);
applyETagHeader(invocation, cacheControl, request, response);
Date lastModifiedTime = applyLastModifiedHeader(invocation, cacheControl, request, response);
Map<String, String> requestCacheControl = parseRequestCacheControl(request);
boolean bypassCache = bypassCache(requestCacheControl);
if (lastModifiedTime != null && !bypassCache) {
String modifiedSinceValue = request.getHeader("if-modified-since");
if (modifiedSinceValue != null) {
try {
Date modifiedSince = DateUtil.parseDate(modifiedSinceValue);
if (!lastModifiedTime.after(modifiedSince)) {
response.setStatus(304);
return null;
}
} catch (DateParseException ex) {
}
}
}
/**
* If we have a HEAD request and the action has specified a short-circuit
* response, skip the rest of the action chain
*/
String method = request.getMethod();
if (cacheControl.shortCircuit() && "HEAD".equals(method))
return null;
return invocation.invoke();
}
Aggregations