+4420 3290 2266

info@coldcore.com

Project Haala

Documentation

Binary servlet Implementation details

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.

BinaryFile

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).
pureOutput
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.
fileame
File name user sees when downloading the content.
Required.
action
Specifies whether to display in browser (inline) or pop up save dialogue (attachment).
Default value determined by MIME type.
length
Content size in bytes user sees when downloading.
Required when binaryStream is used. Default size determined from supplued content object.
mimeType
Sets MIME type.
Default value determined from file name extension.

Cache

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.

404

When the binary servlet has no content to write into a response it sets proper response code and forwards to configured 404 page.

Workflow

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.

sitemap