When a user requests a resource (eg. JPG file) the system fetches it from the database or its WAR package. Then the system has to pass it back to the user with proper MIME type, file name, length and in the form of a byte array or steram. All this data is fed to the binary servlet which does the rest.
This class delivers information and content data to the binary servlet, it is stored in request scope:
- data / stream / file / body
- Content which must be written into a response.
- Required (when omitted forwards to 404). Only one of the property must be set, differ by Java type: first is a byte array, second is an input stream, third is a file (Java file) and last a file body (domain object).
- If present then no headers will be written into a response (does not affect cache headers). The servlet just writes content for special clients such as FLEX applications which do not care for any of the headers.
- All the parameters described below will be ignored if pureOutput is set.
- File name user sees when downloading the content.
- Specifies whether to display in browser (inline) or pop up save dialogue (attachment).
- Default value determined by MIME type.
- Content size in bytes user sees when downloading.
- Required when binaryStream is used. Default size determined from supplued content object.
- Sets MIME type.
- Default value determined from file name extension.
The binary servlet tells a browser to cache all files for one year. This is done by setting response headers and by getLastModified method in the servlet itself. To forbid browser caching, another servlet instance must be created with no-cache parameter, it will set headers and alter getLastModified method so that the browser will not cache files received from this servlet instance.
Binary controller decides which servlet instance to use (with or without cache) for output judging by URL nc parameter.
When the binary servlet has no content to write into a response it sets proper response code and forwards to configured 404 page.
Browser issues GET request for JPG file. This request is handled by the binary controller which fetches the file from the database or its WAR package. The controller stores the file in request scope with required attributes and forwards to the binary servlet. The servlet extracts everything from the request, sets response headers and writes file data into the response. The JPG is accepted by the browser.