Web App Framework 4

Additional Components

This module provides some convenient servlets, filters and utilities.

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

KeyDescription
binaryPropertyName of the property to read the document's binary data from.
inlineDetermines 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 FilterRegistrationBeans. 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.

Provided filters by the Web App's additional components
Filter classDescription
com.subshell.sophora.webapp.components.filter.BenchmarkFilterLogs the duration of a request. This is only done once per request.

Last modified on 9/3/21

The content of this page is licensed under the CC BY 4.0 License. Code samples are licensed under the MIT License.

Icon