Class S3WebResourceFactory

java.lang.Object
overit.geocall.aws.servlet.wr.S3WebResourceFactory
All Implemented Interfaces:
Serializable, overit.geocall.servlet.WebResourceFactory

public class S3WebResourceFactory extends Object implements overit.geocall.servlet.WebResourceFactory, Serializable
This class exposes some utilities to get the reference to a S3WebResource. More precisely, it provides the methods that help to get the reference of a folder or a file, extract some related information, compute a pre-signed URL that can be used to directly download or upload the content from/to the AWS S3 bucket.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a factory instance reading the configuration of the passed company.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    copy(String from, String to)
    Copy a resource within the AWS S3 bucket
    void
    Delete a resource from the AWS S3 bucket
    void
    download(String key, File destination)
    Retrieves objects from Amazon S3 and write the content into the passed file instance.
    software.amazon.awssdk.core.ResponseInputStream<software.amazon.awssdk.services.s3.model.GetObjectResponse>
    Retrieves objects from Amazon S3
    Get the content-type of the resource identified by the passed key
    getResource(String fullName, Long id)
    construct a hypothetical WebResource possibly without searching for it.
    software.amazon.awssdk.services.s3.model.S3Object
    info(String key)
    Get the S3Object instance that point to the resource identified by the passed key.
    list(String prefix, String sep, Integer max)
    Retrieve the list of resources whose path starts with the passed prefix string.
    List<software.amazon.awssdk.services.s3.model.S3Object>
    listObjects(String prefix, String sep, Integer max)
    Retrieve the list of S3Object whose path starts with the passed prefix string.
    locateFolder(String fullName, boolean create)
    searches the WebResource storage area for a folder-resource and potentially creates it
    searches the WebResource storage area for a generic resource (folder or concrete)
    searches the WebResource storage area for a generic resource (folder or concrete)
    void
    upload(String key, byte[] content)
    Upload a binary content into the position identified by the passed key
    upload(String key, long duration)
    Generate the URL that can be used to directly upload the resource from AWS S3 service without any further authentication.
    void
    upload(String key, File file)
    Upload a file (or directory) into the position identified by the passed key
    void
    upload(String key, UpFile uf)
    Upload an UpFile into the position identified by the passed key
    url(String key, long duration, String cacheControl, String contentDisposition)
    Generate the URL that can be used to directly download the resource from AWS S3 service without any further authentication.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • S3WebResourceFactory

      public S3WebResourceFactory(Company company)
      Create a factory instance reading the configuration of the passed company.
      Parameters:
      company - the company from which to extract the configuration
  • Method Details

    • upload

      public void upload(String key, File file) throws IOException
      Upload a file (or directory) into the position identified by the passed key
      Parameters:
      key - Object key for which the upload action was initiated.
      file - payload that will be saved into the key
      Throws:
      IOException - in case the file can not be read
    • upload

      public void upload(String key, byte[] content)
      Upload a binary content into the position identified by the passed key
      Parameters:
      key - Object key for which the upload action was initiated.
      content - payload that will be saved into the key
    • upload

      public void upload(String key, UpFile uf) throws IOException
      Upload an UpFile into the position identified by the passed key
      Parameters:
      key - Object key for which the upload action was initiated.
      uf - payload that will be saved into the key
      Throws:
      IOException - in case the file can not be read
    • list

      public List<String> list(String prefix, String sep, Integer max)
      Retrieve the list of resources whose path starts with the passed prefix string.
      Parameters:
      prefix - limits the response to keys that begin with the specified prefix.
      sep - a delimiter character used to group keys.
      max - maximum number of keys returned to the response
      Returns:
      a list with all object's paths belonging to the specified folder or empty list if none
    • listObjects

      public List<software.amazon.awssdk.services.s3.model.S3Object> listObjects(String prefix, String sep, Integer max)
      Retrieve the list of S3Object whose path starts with the passed prefix string.
      Parameters:
      prefix - limits the response to keys that begin with the specified prefix.
      sep - a delimiter character used to group keys.
      max - maximum number of keys returned to the response
      Returns:
      a list with all object belonging to the specified folder or empty list if none
    • info

      public software.amazon.awssdk.services.s3.model.S3Object info(String key)
      Get the S3Object instance that point to the resource identified by the passed key. This method aims to provide an instance that can be used to get some metadata information later.
      Parameters:
      key - Object's key
      Returns:
      the S3Object reference, or null if there isn't any resource associated with the passed key.
    • getContentType

      public String getContentType(String key)
      Get the content-type of the resource identified by the passed key
      Parameters:
      key - the object key
      Returns:
      A standard MIME type describing the format of the object data.
    • download

      public void download(String key, File destination)
      Retrieves objects from Amazon S3 and write the content into the passed file instance.
      Parameters:
      key - Object's key
      destination - file that response contents will be written to. The file must not exist or this method will throw an exception. If the file is not writable by the current user then an exception will be thrown.
    • downloadContent

      public software.amazon.awssdk.core.ResponseInputStream<software.amazon.awssdk.services.s3.model.GetObjectResponse> downloadContent(String key)
      Retrieves objects from Amazon S3
      Parameters:
      key - Object's key
      Returns:
      A ResponseInputStream containing data streamed from service. Note that this is an unmanaged reference to the underlying HTTP connection so great care must be taken to ensure all data if fully read from the input stream and that it is properly closed.
    • url

      public URL url(String key, long duration, String cacheControl, String contentDisposition)
      Generate the URL that can be used to directly download the resource from AWS S3 service without any further authentication.
      Parameters:
      key - Object's key
      duration - Specifies the duration (in millis) for which this pre-signed request should be valid. After this time has expired, attempting to use the pre-signed request will fail.
      cacheControl - the Cache-Control header that will be set to the response.
      contentDisposition - the Content-Disposition header will be set to the response
      Returns:
      the pre-signed URL
    • upload

      public URL upload(String key, long duration)
      Generate the URL that can be used to directly upload the resource from AWS S3 service without any further authentication.
      Parameters:
      key - Object's key
      duration - Specifies the duration (in millis) for which this pre-signed request should be valid. After this time has expired, attempting to use the pre-signed request will fail.
      Returns:
      the pre-signed URL
    • delete

      public void delete(String key)
      Delete a resource from the AWS S3 bucket
      Parameters:
      key - Object's key for which the delete action is intended.
    • copy

      public void copy(String from, String to)
      Copy a resource within the AWS S3 bucket
      Parameters:
      from - Object's key containing the start position
      to - Object's key containing the destination position
    • locateFolder

      public S3WebResource locateFolder(String fullName, boolean create)
      Description copied from interface: overit.geocall.servlet.WebResourceFactory
      searches the WebResource storage area for a folder-resource and potentially creates it
      Specified by:
      locateFolder in interface overit.geocall.servlet.WebResourceFactory
      Parameters:
      fullName - the full-name of the resource to be searched
      create - if true it creates the hierarchy for the requested folder
      Returns:
      the WebResource (if already existing or if created) or null otherwise
    • locateResource

      public S3WebResource locateResource(String fullName)
      Description copied from interface: overit.geocall.servlet.WebResourceFactory
      searches the WebResource storage area for a generic resource (folder or concrete)
      Specified by:
      locateResource in interface overit.geocall.servlet.WebResourceFactory
      Parameters:
      fullName - the full-name of the resource to be searched
      Returns:
      the existing WebResource or null otherwise
    • locateResource

      public WebResource locateResource(Long id)
      Description copied from interface: overit.geocall.servlet.WebResourceFactory
      searches the WebResource storage area for a generic resource (folder or concrete)
      Specified by:
      locateResource in interface overit.geocall.servlet.WebResourceFactory
      Parameters:
      id - the identifier assigned to that resource ia any. Only same implementations supports id-naming of resources. If the id-naming is not supported this method can throw an UnsupportedOperationException
      Returns:
      the existing WebResource or null otherwise
    • getResource

      public WebResource getResource(String fullName, Long id)
      Description copied from interface: overit.geocall.servlet.WebResourceFactory
      construct a hypothetical WebResource possibly without searching for it. Usually this method is used to build a WebResource without searching for it, because the existence is known
      Specified by:
      getResource in interface overit.geocall.servlet.WebResourceFactory
      Parameters:
      fullName - the full-name of the resource
      id - the identifier assigned to that resource ia any. Only same implementations supports id-naming of resources.
      Returns:
      the WebResource also if this not exists