A Plume File module to help serve file with Jersey. It can be done with or without a java data cache. This dependency also includes a Webservice that serves the file.
- Install Maven dependency:
<dependency>
<groupId>com.coreoz</groupId>
<artifactId>plume-file-web-download-jersey</artifactId>
</dependency>
- In the
ApplicationModule
class, install the following Guice module:
install(new GuiceFileDownloadModule());
for serving files without a cache
- Declare the FileWs in the
JerseyConfigProvider
config.resource(FileWs.class);
install(new GuiceFileCacheDownloadModule());
for serving files with the FileCacheServiceGuava
cache service.
You can override these values in your configuration file :
// configures the "Cache-Control" max-age header
file.cache.http.max-age = "365 days"
The default values are shown.
// configures the expiration of the java data cache
file.cache.data.expires-after-access-duration = "1 day"
// configures the maximum size of the java data cache in bytes
file.cache.data.max-cache-size = "10 MB"
// configures the expiration of the java metadata cache
file.cache.metadata.expires-after-access-duration = "1 day"
// configures the maximum elements in the java metadata cache
file.cache.metadata.max-elements = 10000
The default values are shown.
This module can be used with your own implementation of the FileCacheService
interface.
Then add this code in your ApplicationModule
bind(FileDownloadJerseyService.class).to(FileCacheDownloadService.class);
bind(FileCacheService.class).to(YourFileCacheService.class);