@Override public InputStream getInputStream() throws ResourceException { try { return springDelegate.getInputStream(); } catch (IOException e) { throw new ResourceException(e); } }
@Override public InputStream getInputStream() throws ResourceException { try { return springDelegate.getInputStream(); } catch (IOException e) { throw new ResourceException(e); } }
/** * Constructor. * * @param resourceURI file: URI to the file * * @throws ResourceException thrown if the resource path is null or empty * * @since 1.2.0 */ public FilesystemResource(URI resourceURI) throws ResourceException { super(); if (resourceURI == null) { throw new ResourceException("Resource URL may not be null"); } resource = new File(resourceURI); }
/** * Constructor. * * @param resourceURI the file: URI to the file for this resource * @param resourceFilter filter to apply to this resource * * @throws ResourceException thrown if the resource path is null or empty * * @since 1.2.0 * @deprecated use {@link #setResourceFilter(ResourceFilter)} instead */ public FilesystemResource(URI resourceURI, ResourceFilter resourceFilter) throws ResourceException { super(resourceFilter); if (resourceURI == null) { throw new ResourceException("Resource URI may not be null"); } resource = new File(resourceURI); }
/** * Saves a resource to the backing file. * * @param resource the string representation of the resource * * @throws ResourceException thrown if the resource backing file can not be written to */ protected void saveToResourceFile(byte[] resource) throws ResourceException { try { FileOutputStream out = new FileOutputStream(resourceFile); out.write(resource); } catch (IOException e) { throw new ResourceException("Unable to write resource to backing file " + resourceFile.getAbsolutePath(), e); } } }
/** {@inheritDoc} */ public DateTime getLastModifiedTime() throws ResourceException { if (!resource.exists()) { throw new ResourceException("Resource file does not exist: " + resource.getAbsolutePath()); } return new DateTime(resource.lastModified(), ISOChronology.getInstanceUTC()); }
@Override public DateTime getLastModifiedTime() throws ResourceException { try { return new DateTime(springDelegate.lastModified()); } catch (IOException e) { throw new ResourceException(e); } }
/** {@inheritDoc} */ public InputStream getInputStream() throws ResourceException { try { FileInputStream ins = new FileInputStream(resource); return applyFilter(ins); } catch (FileNotFoundException e) { throw new ResourceException("Resource file does not exist: " + resource.getAbsolutePath()); } }
/** {@inheritDoc} */ public InputStream getInputStream() throws ResourceException { try { InputStream ins = resource.openStream(); return applyFilter(ins); } catch (IOException e) { throw new ResourceException("Unable to open resource: " + resource); } }
@Override public DateTime getLastModifiedTime() throws ResourceException { try { return new DateTime(springDelegate.lastModified()); } catch (IOException e) { throw new ResourceException(e); } }
public SpringResourceWrapperOpenSAMLResource(Resource springDelegate) throws ResourceException { this.springDelegate = springDelegate; if (!exists()) { throw new ResourceException("Wrapper resource does not exist: " + springDelegate); } }
/** * Constructor. * * @param path the path to the file for this resource * * @throws ResourceException thrown if the resource path is null or empty or if the resource does not exist */ public ClasspathResource(String path) throws ResourceException { super(); if (DatatypeHelper.isEmpty(path)) { throw new ResourceException("Resource path may not be null or empty"); } resource = getClass().getResource(path); if (resource == null) { throw new ResourceException("Classpath resource does not exist: " + path); } lastModTime = new DateTime(); }
/** * Constructor. * * @param resourcePath the path to the file for this resource * * @throws ResourceException thrown if the resource path is null or empty */ public FilesystemResource(String resourcePath) throws ResourceException { super(); if (DatatypeHelper.isEmpty(resourcePath)) { throw new ResourceException("Resource path may not be null or empty"); } resource = new File(resourcePath); }
/** * Constructor. * * @param resourcePath the path to the file for this resource * @param resourceFilter filter to apply to this resource * * @throws ResourceException thrown if the resource path is null or empty * * @deprecated use {@link #setResourceFilter(ResourceFilter)} instead */ public FilesystemResource(String resourcePath, ResourceFilter resourceFilter) throws ResourceException { super(resourceFilter); if (DatatypeHelper.isEmpty(resourcePath)) { throw new ResourceException("Resource path may not be null or empty"); } resource = new File(resourcePath); }
/** {@inheritDoc} */ public InputStream getInputStream() throws ResourceException { checkoutOrUpdateResource(); try { return applyFilter(new FileInputStream(getResourceFile())); } catch (IOException e) { String erroMsg = "Unable to read resource file " + resourceFileName + " from local working copy " + workingCopyDirectory.getAbsolutePath(); log.error(erroMsg, e); throw new ResourceException(erroMsg, e); } }
/** {@inheritDoc} */ public DateTime getLastModifiedTime() throws ResourceException { try { return super.getLastModifiedTime(); } catch (ResourceException e) { log.warn("HTTP resource '{}' was inaccessible for getLastModifiedTime(), trying backing file '{}'", getLocation(), resourceFile.getAbsolutePath()); long lastModifiedTime = resourceFile.lastModified(); if (lastModifiedTime == 0) { throw new ResourceException("URL resource is not reachable and backing file is not readable"); } return new DateTime(lastModifiedTime, ISOChronology.getInstanceUTC()); } }
/** * Gets remote resource. * * @return the remove resource * * @throws ResourceException thrown if the resource could not be fetched */ protected GetMethod getResource() throws ResourceException { GetMethod getMethod = new GetMethod(resourceUrl); getMethod.addRequestHeader("Connection", "close"); try { httpClient.executeMethod(getMethod); if (getMethod.getStatusCode() != HttpStatus.SC_OK) { throw new ResourceException("Unable to retrieve resource URL " + resourceUrl + ", received HTTP status code " + getMethod.getStatusCode()); } return getMethod; } catch (IOException e) { throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e); } }
/** {@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 InputStream getInputStream() throws ResourceException { InputStream ins = null; try { GetMethod getMethod = super.getResource(); byte[] response = getMethod.getResponseBody(); saveToResourceFile(response); ins = getMethod.getResponseBodyAsStream(); } catch (Exception e) { try { log.warn("HTTP resource '{}' was inaccessible for getInputStream(), trying backing file '{}'", getLocation(), resourceFile.getAbsolutePath()); ins = new FileInputStream(resourceFile); } catch (IOException ioe) { throw new ResourceException("Unable to read resource URL or backing file " + resourceFile.getAbsolutePath(), ioe); } } return applyFilter(ins); }
/** {@inheritDoc} */ public InputStream getInputStream() throws ResourceException { GetMethod getMethod = getResource(); try { return new ConnectionClosingInputStream(getMethod, applyFilter(getMethod.getResponseBodyAsStream())); } catch (IOException e) { throw new ResourceException("Unable to read response", e); } }