Last updated February 05, 2009 05:45, by Igor Minar
= grizzly-sendfile Plugins =
grizzly-sendfile was designed to implement only the core download sending functionality, but allows additional functionality to be added to it in the form of plugins.
The plugin API is still currently very simple and still evolving. It's very likely that it will change slightly in the near future.
== DownloadResultSender Plugin ==
DownloadResultSender is a plugin that sends the result of a download back to the application that instructed grizzly-sendfile to send a file.
It might be important for the application to know if the download succeeded, but since the application has no control over the download execution after the X-Sendfile header was set, there isn't a synchronous way to to this.
DownloadResultSender plugin resolves this issue in an asynchronous way. Simply create an HTTP interface (servlet, rails action, etc) capable of accepting requests from this plugin and DownloadResultSender will send the result of a download to this interface.
Configuration of the DownloadResultSender is done similarly to grizzly-sendfile via JVM options/parameters:
{| border="1"
! jvm option
| <code>-Dcom.igorminar.grizzlysendfile.plugin.DownloadResultSender.DestinationUrl</code>
|-
! description
| url to send download results to
|-
! required
| yes
|-
! example
| <code>-Dcom.igorminar.grizzlysendfile.plugin.DownloadResultSender.DestinationUrl=http://myapp.com/results_receiver</code><br/><code>-Dcom.igorminar.grizzlysendfile.plugin.DownloadResultSender.DestinationUrl=http://localhost:8080/results_receiver</code>
|}
The result will be sent as an HTTP POST request with these HTTP parameters:
{| border="1"
! name
! description
|-
| <code>download_id</code>
| download id assigned to the download by the application or by grizzly-sendfile
|-
| <code>file_path</code>
| path of the file sent
|-
| <code>result</code>
| HTTP response code - one of [http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html standard] 200, 304, 403, 404 or custom 420 (client abort), 421 (client timeout)
|-
| <code>speed</code>
| average speed of the download in KB/s
|}
== Other Plugins ==
Currently the only other grizzly-sendfile plugin that was implemented is a GeoLocator plugin that denies download requests for IP addresses from [http://www.sun.com/sales/its/countries/Embargoed.html embargoed countries]. Because this plugin is specific to [http://mediacast.sun.com mediacast] and depends on a internal webservice, its source code is not publicly available.
== Plugin API ==
The plugin API is still under development and might change in the near future. The functionality will be preserved, only the API might change.
In order to write a plugin, one needs to implement <code>com.igorminar.grizzlysendfile.plugin.SendfilePlugin</code> interface.
Check out <code>com.igorminar.grizzlysendfile.plugin.DownloadResultSender</code> for an example plugin.





