Skip to main content
Version: 3.14.x.x LTS

FileReaderServlet

The FileReaderServlet returns the content of a specified file. The incoming pathInfo will be taken as filename. The file has to be located in the configured root directory (RootDirectory attribute).

The FileReaderServlet can be used to make static files accessible to the frontend. You can also use this servlet to configure files in the ErrorFilter to get static error pages via a servlet.

Files can be added, modified, or removed in the root directory while nevisProxy is running.

caution

Do not put any sensitive files into the configured root directory. These files may become visible to the frontend if the FileReaderServlet is mapped to a public URL.

Classname:
ch::nevis::nevisproxy::servlet::file::FileReaderServlet

Library:
libNPFileServlets.so.1

Configuration

RootDirectory

Type: string
Usage Constraints: mandatory

Defines the directory where the files to be read are located. Usually the root directory is something like this:
/var/opt/nevisproxy/<instance>/files

Both absolute and relative paths are supported. If you configure a relative path, the path will be prefixed with <docBase>/WEB-INF/lib, where <docBase> refers to the configuration parameter docBase in the Context section of the navajo.xml configuration file.

Example of docBase configuration: docBase="/var/opt/nevisproxy/test/work"

Files

Type: string
Usage Constraints: optional, conditional, default pragma is 'Continue'.
Default:

^[^/]*\.ai$:application/postscript
^[^/]*\.aim$:application/x-aim
^[^/]*\.art$:image/x-jg
^[^/]*\.ico$:image/x-icon
^[^/]*\.bcpio$:application/x-bcpio
^[^/]*\.bin$:application/octet-stream
^[^/]*\.bmp$:image/bmp
^[^/]*\.body$:text/html
^[^/]*\.cer$:application/x-x509-ca-cert
^[^/]*\.class$:application/java
^[^/]*\.css$:text/css
^[^/]*\.dib$:image/bmp
^[^/]*\.doc$:application/msword
^[^/]*\.dtd$:text/plain
^[^/]*\.eps$:application/postscript
^[^/]*\.exe$:application/octet-stream
^[^/]*\.gif$:image/gif
^[^/]*\.gtar$:application/x-gtar
^[^/]*\.gz$:application/x-gzip
^[^/]*\.htm$:text/html
^[^/]*\.html$:text/html
^[^/]*\.ief$:image/ief
^[^/]*\.jar$:application/java-archive
^[^/]*\.java$:text/plain
^[^/]*\.jpe$:image/jpeg
^[^/]*\.jpeg$:image/jpeg
^[^/]*\.jpg$:image/jpeg
^[^/]*\.js$:text/javascript
^[^/]*\.jspf$:text/plain
^[^/]*\.latex$:application/x-latex
^[^/]*\.mpega$:audio/x-mpeg
^[^/]*\.mpg$:video/mpeg
^[^/]*\.pbm$:image/x-portable-bitmap
^[^/]*\.pct$:image/pict
^[^/]*\.pdf$:application/pdf
^[^/]*\.pgm$:image/x-portable-graymap
^[^/]*\.pic$:image/pict
^[^/]*\.pict$:image/pict
^[^/]*\.png$:image/png
^[^/]*\.pnm$:image/x-portable-anymap
^[^/]*\.ppm$:image/x-portable-pixmap
^[^/]*\.ps$:application/postscript
^[^/]*\.qti$:image/x-quicktime
^[^/]*\.qtif$:image/x-quicktime
^[^/]*\.ras$:image/x-cmu-raster
^[^/]*\.rgb$:image/x-rgb
^[^/]*\.swf$:application/x-shockwave-flash
^[^/]*\.tar$:application/x-tar
^[^/]*\.tif$:image/tiff
^[^/]*\.tiff$:image/tiff
^[^/]*\.txt$:text/plain
^[^/]*\.xbm$:image/x-xbitmap
^[^/]*\.xml$:text/xml
^[^/]*\.xpm$:image/x-xpixmap
^[^/]*\.xsl$:text/xml
^[^/]*\.svg$:image/svg+xml
^[^/]*\.Z$:application/x-compress
^[^/]*\.z$:application/x-compress
^[^/]*\.zip$:application/zip

Files specifies which files are served from the RootDirectory and which Content-Type is associated with them. Its syntax is as follows:

<filename regex>:<content-type>

  • <filename regex>: The frontend can request files whose filenames (starting from the configured root directory) match this regex
  • <content-type>: The Content-Type header of the response sent to the frontend

Example: ^[A-Za-z0-9]*\.xml$: text/xml

info

Be aware that the regex is a PCRE regex, not a wildcard one. An expression such as the following one will not work: *.xml. See also: Regular expressions.

The default configuration only allows to serve files directly located in the RootDirectory.

For example, proceed as follows to add the CSS files from the directory RootDirectory/css/ but not from its subdirectories:

  • Add the parameter Files to your FileReaderServlet
  • Copy the default configuration for Files
  • Optional: Remove the lines for the unnecessary file types
  • Add the following line: ^css/[^/]*\.css$:text/css
  • Restart nevisProxy