Setup
To use the Sophora Web App Framework's additional components, make sure to import the ComponentsSpringConfig
(e.g. via auto configuration) to load all spring classes of this module.
Maven dependency
<dependency>
<groupId>com.subshell.sophora.webapp</groupId>
<artifactId>sophora-webapp-components</artifactId>
<version>x.y.z</version>
</dependency>
Servlets
To have the servlets from the Sophora Web App Framework's additional components available, add the following ServletComponentScan
:
@ServletComponentScan("com.subshell.sophora.webapp.components.servlet")
ImageServlet
Serves images and their variants from an image document. Reads the variant via the 'v' parameter and tries to find the respective variant. If no variant parameter is given, the original variant is returned. Sample application.yml
entry:
- name: "sophora-content-nt:image"
types:
- name: default
servlet:
name: "/system/com.subshell.sophora.webapp.components.servlet.image.ImageServlet"
If the requested variant is disabled, unconfigured or for any other reason not available for the requested document, a Page Not Found (404) error is sent.
BinaryDataServlet
Serves binary data from a file document. Sample application.yml
entry:
- name: "sophora-content-nt:file"
types:
- name: default
servlet:
name: "/system/com.subshell.sophora.webapp.components.servlet.binary.BinaryDataServlet"
properties:
binaryProperty: sophora-content:binarydata
inline: true
Properties
Key | Description |
---|---|
binaryProperty | Name of the property to read the document's binary data from. |
inline | Determines the 'Content-Disposition' Header. If inline=true, then it is set to 'inline' (browsers will try to open the file within the browser), otherwise it will be set to 'attachment' (browsers will download the file). See also Mozilla Developer Documentation. |
Filters
Filters should by registered by providing a configuration class that creates the FilterRegistrationBean
s. Example:
@Configuration
public class FilterConfiguration {
@Bean
public FilterRegistrationBean<Filter> benchmarkFilter() {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
bean.setFilter(new BenchmarkFilter());
return bean;
}
@Bean
public FilterRegistrationBean<Filter> myFilter() {
FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();
bean.setFilter(new MyFilter());
return bean;
}
}
The following filters will be provided by the Web App's additional components.
Filter class | Description |
---|---|
com.subshell.sophora.webapp.components.filter.BenchmarkFilter | Logs the duration of a request. This is only done once per request. |