Package org.mockserver.mock.action.http
Class FileBodyMaterialiser
java.lang.Object
org.mockserver.mock.action.http.FileBodyMaterialiser
Materialises a
FileBody into a concrete BodyWithContentType (a StringBody or a
BinaryBody) by reading the referenced file, so the file CONTENTS - not the file path string -
reach the wire.
This is the single shared implementation of that logic, invoked from every response-producing funnel
(static response, object callback, class callback, response template, and forward responseOverride)
as well as from request-body matching against a FileBody. Keeping it here (the action-handler
layer) rather than in the codec keeps file I/O out of BodyDecoderEncoder while still giving the
caller access to the request (for templating) and the Configuration (for template engines).
- A supported
templateType(VELOCITY/MUSTACHE) with a request present -> the file is rendered through that engine against the request, preserving the declared content type. - No
templateType, an unsupported one (e.g. JavaScript), or no request available -> the file is served verbatim: a text content type yields aStringBody; a binary or absent content type yields aBinaryBodyof the raw bytes so binary files (images, PDFs, archives) are not charset-corrupted. - A missing / unreadable file ->
FileBodyExceptioncarrying the path for server-side logging.
- Author:
- jamesdbloom
-
Constructor Summary
ConstructorsConstructorDescriptionFileBodyMaterialiser(MockServerLogger mockServerLogger, Configuration configuration) -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisFileTemplatingSupported(HttpTemplate.TemplateType templateType) Only Velocity and Mustache are supported for templating aFileBody; any other type (e.g.materialise(FileBody fileBody, HttpRequest httpRequest) Materialises the givenFileBody.
-
Constructor Details
-
FileBodyMaterialiser
-
-
Method Details
-
materialise
Materialises the givenFileBody. WhenhttpRequestisnull(or the template type is unsupported/absent) the file is served verbatim; otherwise a supported template type renders the file against the request.- Throws:
FileBodyException- when the referenced file cannot be read
-
isFileTemplatingSupported
Only Velocity and Mustache are supported for templating aFileBody; any other type (e.g. JavaScript) ornullmeans the file is not template-rendered and is served verbatim.
-