@Override public Header[] extractResult(HeadMethod method) throws IOException { if (method.getStatusCode() == SC_NOT_FOUND) { throw new FileNotFoundException("Not Found " + method.getURI()); } return method.getResponseHeaders(); }
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive. */ @Override protected FileType doGetType() throws Exception { // Use the HEAD method to probe the file. final int status = this.getHeadMethod().getStatusCode(); if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) { return FileType.FILE; } else if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { return FileType.IMAGINARY; } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } }
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive. */ @Override protected FileType doGetType() throws Exception { // Use the HEAD method to probe the file. final int status = this.getHeadMethod().getStatusCode(); if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) { return FileType.FILE; } else if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { return FileType.IMAGINARY; } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } }
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive. */ @Override protected FileType doGetType() throws Exception { // Use the HEAD method to probe the file. final int status = this.getHeadMethod().getStatusCode(); if (status == HttpURLConnection.HTTP_OK || status == HttpURLConnection.HTTP_BAD_METHOD /* method is bad, but resource exist */) { return FileType.FILE; } else if (status == HttpURLConnection.HTTP_NOT_FOUND || status == HttpURLConnection.HTTP_GONE) { return FileType.IMAGINARY; } else { throw new FileSystemException("vfs.provider.http/head.error", getName(), Integer.valueOf(status)); } }
/** {@inheritDoc} */ public boolean exists() throws ResourceException { HeadMethod headMethod = new HeadMethod(resourceUrl); headMethod.addRequestHeader("Connection", "close"); try { httpClient.executeMethod(headMethod); if (headMethod.getStatusCode() != HttpStatus.SC_OK) { return false; } return true; } catch (IOException e) { throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e); } finally { headMethod.releaseConnection(); } }
/** {@inheritDoc} */ public DateTime getLastModifiedTime() throws ResourceException { HeadMethod headMethod = new HeadMethod(resourceUrl); headMethod.addRequestHeader("Connection", "close"); try { httpClient.executeMethod(headMethod); if (headMethod.getStatusCode() != HttpStatus.SC_OK) { throw new ResourceException("Unable to retrieve resource URL " + resourceUrl + ", received HTTP status code " + headMethod.getStatusCode()); } Header lastModifiedHeader = headMethod.getResponseHeader("Last-Modified"); if (lastModifiedHeader != null && !DatatypeHelper.isEmpty(lastModifiedHeader.getValue())) { long lastModifiedTime = DateUtil.parseDate(lastModifiedHeader.getValue()).getTime(); return new DateTime(lastModifiedTime, ISOChronology.getInstanceUTC()); } return new DateTime(); } catch (IOException e) { throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e); } catch (DateParseException e) { throw new ResourceException("Unable to parse last modified date for resource:" + resourceUrl, e); } finally { headMethod.releaseConnection(); } }