Remote Download servlet v. 1.2


Simple component you may use for downloading files from other servers. For example it could be useful if you points in your applications (JSP pages) to mp3 files located on the remote host etc. How to use it:

1) download rdownloadPackage.jar and save it in WEB-INF/lib

2) describe RemoteDownload servlet in web.xml file  


    <servlet>
     <servlet-name>RemoteDownload</servlet-name>
     <servlet-class>com.jsos.download.RemoteDownloadServlet</servlet-class>
    </servlet>

3) define a mapping:
 


    <servlet-mapping>
     <servlet-name>RemoteDownload</servlet-name>
     <url-pattern>/servlet/RemoteDownload</url-pattern>
    </servlet-mapping>

and now you can use it:
 


http://your_host/servlet/RemoteDownload?http://some_uri_here

servlet will download this file from the remote host.

You may set initial parameters with proxy settings for your host. Names for parameters are proxyHost and proxyPort. For example:
 


    <servlet>
     <servlet-name>RemoteDownload</servlet-name>
     <servlet-class>com.jsos.download.RemoteDownload</servlet-class>
     <init-param>
      <param-name>proxyHost</param-name>
      <param-value>ip_address_for_your_proxy</param-value>
     </init-param>
     <init-param>
      <param-name>proxyPort</param-name>
      <param-value>8080</param-value>
     </init-param>
    </servlet>

You can provide the following additional parameters for this servlet:

gzip - enable/disable data compression during the downloading. Possible values are true and false. Default value is false
mime - enable/disable mime type detection. Possible values are true and false. If this value is true than servlet will set mime type according to the original settings on the remote host or according to file extension. Default value is false (mime type will be application/octet-stream).
error - lets you describe some URL users requests will be redirected to in case of missed files. If this parameter starts with http:// than servlet redirects the request. Otherwise servlet assumes the local resource and request will be forwarded. By default is empty (the standard error message will be provided).
expires - describes a caching time (in seconds) for the data (client side cache).

For example:
 


    <servlet>
     <servlet-name>RemoteDownload</servlet-name>
     <servlet-class>com.jsos.download.RemoteDownloadServlet</servlet-class>
     <init-param>
      <param-name>gzip</param-name>
      <param-value>true</param-value>
     </init-param>
    </servlet>

For downloading:

servlet: rdownloadPackage.jar  
 

 © Coldbeans    Comments?
 

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: