GlassFish v2 Support
grizzly-sendfile was initially developed against grizzly 1.0.x which is used in Glassfish v2 and 2.1 and the the version 0.2 is the last v2 compatible version.
A lot has changed in between grizzly 1.0 and the most recent 1.9 series and it wasn't feasible to keep grizzly-sendfile compatible with both glassfish v2 and v3 without forking the code.
This page captures information related to setting up grizzly-sendfile with glassfish v2.
Basic Setup
Supposing that you have Glassfish v2 application server set up, you need to complete these simple steps to get going:
- download the grizzly-sendfile 0.2 jar
- move it into your
glassfish/lib/asgrizzly-sendfile.jar
You can now configure a few settings either visually via glassfish's admin console or by editing the domain.xml for your glassfish domain directly.
Configuration via the Admin Console:
1. Log in to the admin console (usually http://yourhost:4848).
2. Set up JVM classpath: Application Server > JVM Settings > Path Settings:
Classpath Prefix: ${com.sun.aas.installRoot}/lib/grizzly-sendfile.jar
3. Add these JVMs options via the admin console: Application Server > JVM Settings > JVM Options:
-Dcom.sun.enterprise.web.connector.grizzly.asyncHandlerClass=com.sun.enterprise.web.connector.grizzly.async.DefaultAsyncHandler -Dcom.sun.enterprise.web.connector.grizzly.asyncHandler.ports=<yourport> -Dcom.sun.enterprise.web.connector.grizzly.asyncFilters=com.igorminar.grizzlysendfile.SendfileFilter -Dcom.igorminar.grizzlysendfile.AllowedPaths=</path/to/your/files/*>Note: replace
<yourport> with your port (e.g. 8080) and </path/to/your/files/*> with your path (e.g. /app/myapp/files/*). See Advanced Configuration section below.
Configuration via editing domain.xml
Edit glassfish/domain/your_domain/config/domain.xml and add these config options:
- classpath-prefix:
<java-config classpath-prefix="${com.sun.aas.installRoot}/lib/grizzly-sendfile.jar" ...
- jvm-options:
<jvm-options>-Dcom.sun.enterprise.web.connector.grizzly.asyncHandlerClass=com.sun.enterprise.web.connector.grizzly.async.DefaultAsyncHandler</jvm-options> <jvm-options>-Dcom.sun.enterprise.web.connector.grizzly.asyncHandler.ports=8080</jvm-options><!-- (or other port that your app is deployed on) --> <jvm-options>-Dcom.sun.enterprise.web.connector.grizzly.asyncFilters=com.igorminar.grizzlysendfile.SendfileFilter</jvm-options> <jvm-options>-Dcom.igorminar.grizzlysendfile.AllowedPaths=/path/to/your/files/*</jvm-options>
Advanced Configuration of grizzly-sendfile 0.2
grizzly-sendfile's characteristics can be configured via different settings. Currently these settings should be specified as JVM options/parameters:
AllowedPaths
| jvm option | -Dcom.igorminar.grizzlysendfile.AllowedPaths |
|---|---|
| description | specifies path(s) from which grizzly-sendfile is allowed to serve files. This is a security measure that prevents system or otherwise restricted files to be served by grizzly-sendfile. |
| required | yes |
| default | - |
| notes | comma separated list of paths. In order to specify the entire directory always end the path with *, which is used for simple globbing |
| examples | -Dcom.igorminar.grizzlysendfile.AllowedPaths=/var/www/files/*-Dcom.igorminar.grizzlysendfile.AllowedPaths=/var/www/files/*,/var/www/images/*.jpg |
Algorithm
| jvm option | -Dcom.igorminar.grizzlysendfile.Algorithm |
|---|---|
| description | grizzly-sendfile algorithm used |
| required | no |
| default | com.igorminar.grizzlysendfile.algorithm.SimpleBlockingAlgorithm |
| examples | -Dcom.igorminar.grizzlysendfile.Algorithm=com.igorminar.grizzlysendfile.algorithm.EqualNonBlockingAlgorithm |
ThreadCount
| jvm option | -Dcom.igorminar.grizzlysendfile.ThreadCount |
|---|---|
| description | maximum number of worker threads in the thread pool |
| required | no |
| default | 50 |
| examples | -Dcom.igorminar.grizzlysendfile.ThreadCount=100 |
BufferSize
| jvm option | -Dcom.igorminar.grizzlysendfile.BufferSize |
|---|---|
| description | size of a buffer in bytes used as a temporary storage of data between reading the data from the file and sending it to the client |
| required | no |
| default | 16384 (16KB)
|
| examples | -Dcom.igorminar.grizzlysendfile.BufferSize=100 |
IdleConnectionTimeout
| jvm option | -Dcom.igorminar.grizzlysendfile.IdleConnectionTimeout |
|---|---|
| description | maximum duration in milliseconds that a connection can be idle before it is closed by grizzly-sendfile |
| required | no |
| default | 30000 (30sec)
|
| examples | -Dcom.igorminar.grizzlysendfile.IdleConnectionTimeout=60000 (60sec)-Dcom.igorminar.grizzlysendfile.IdleConnectionTimeout=-1 (unlimited)
|
Plugins
| jvm option | -Dcom.igorminar.grizzlysendfile.Plugins |
|---|---|
| description | comma separated list of plugins that grizzly-sendfile should load (order matters!) |
| required | no |
| default | - |
| examples | -Dcom.igorminar.grizzlysendfile.Plugins=com.igorminar.grizzlysendfile.plugin.DownloadResultSender-Dcom.igorminar.grizzlysendfile.Plugins=com.igorminar.grizzlysendfile.plugin.DownloadResultSender, foo.bar.BazPlugin |





