Package overit.geocall.aws.servlet.wr
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
ConstructorsConstructorDescriptionS3WebResourceFactory(Company company) Create a factory instance reading the configuration of the passed company. -
Method Summary
Modifier and TypeMethodDescriptionvoidCopy a resource within the AWS S3 bucketvoidDelete a resource from the AWS S3 bucketvoidRetrieves 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> downloadContent(String key) Retrieves objects from Amazon S3getContentType(String key) Get the content-type of the resource identified by the passed keygetResource(String fullName, Long id) construct a hypothetical WebResource possibly without searching for it.software.amazon.awssdk.services.s3.model.S3ObjectGet theS3Objectinstance that point to the resource identified by the passed key.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 ofS3Objectwhose path starts with the passed prefix string.locateFolder(String fullName, boolean create) searches the WebResource storage area for a folder-resource and potentially creates itlocateResource(Long id) searches the WebResource storage area for a generic resource (folder or concrete)locateResource(String fullName) searches the WebResource storage area for a generic resource (folder or concrete)voidUpload a binary content into the position identified by the passed keyGenerate the URL that can be used to directly upload the resource from AWS S3 service without any further authentication.voidUpload a file (or directory) into the position identified by the passed keyvoidUpload anUpFileinto the position identified by the passed keyGenerate the URL that can be used to directly download the resource from AWS S3 service without any further authentication.
-
Constructor Details
-
S3WebResourceFactory
Create a factory instance reading the configuration of the passed company.- Parameters:
company- the company from which to extract the configuration
-
-
Method Details
-
upload
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
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
Upload anUpFileinto 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
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 ofS3Objectwhose 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
Get theS3Objectinstance 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
S3Objectreference, or null if there isn't any resource associated with the passed key.
-
getContentType
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
Retrieves objects from Amazon S3 and write the content into the passed file instance.- Parameters:
key- Object's keydestination- 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
ResponseInputStreamcontaining 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
Generate the URL that can be used to directly download the resource from AWS S3 service without any further authentication.- Parameters:
key- Object's keyduration- 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
Generate the URL that can be used to directly upload the resource from AWS S3 service without any further authentication.- Parameters:
key- Object's keyduration- 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
Delete a resource from the AWS S3 bucket- Parameters:
key- Object's key for which the delete action is intended.
-
copy
Copy a resource within the AWS S3 bucket- Parameters:
from- Object's key containing the start positionto- Object's key containing the destination position
-
locateFolder
Description copied from interface:overit.geocall.servlet.WebResourceFactorysearches the WebResource storage area for a folder-resource and potentially creates it- Specified by:
locateFolderin interfaceoverit.geocall.servlet.WebResourceFactory- Parameters:
fullName- the full-name of the resource to be searchedcreate- if true it creates the hierarchy for the requested folder- Returns:
- the WebResource (if already existing or if created) or null otherwise
-
locateResource
Description copied from interface:overit.geocall.servlet.WebResourceFactorysearches the WebResource storage area for a generic resource (folder or concrete)- Specified by:
locateResourcein interfaceoverit.geocall.servlet.WebResourceFactory- Parameters:
fullName- the full-name of the resource to be searched- Returns:
- the existing WebResource or null otherwise
-
locateResource
Description copied from interface:overit.geocall.servlet.WebResourceFactorysearches the WebResource storage area for a generic resource (folder or concrete)- Specified by:
locateResourcein interfaceoverit.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 anUnsupportedOperationException- Returns:
- the existing WebResource or null otherwise
-
getResource
Description copied from interface:overit.geocall.servlet.WebResourceFactoryconstruct 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:
getResourcein interfaceoverit.geocall.servlet.WebResourceFactory- Parameters:
fullName- the full-name of the resourceid- the identifier assigned to that resource ia any. Only same implementations supports id-naming of resources.- Returns:
- the WebResource also if this not exists
-