Web App Framework | Version 4

Routing Module

Configuration and code examples for processing requests and generating HTML for Sophora documents and static resources.

The task of the Routing Module is to process HTTP requests and to perform an appropriate HTTP response depending on the requested Sophora document. Corresponding entries of redirect documents will also be processed.

Setup

Make sure that the RoutingSpringConfig is imported (e.g. via Spring auto configuration) to load all spring classes of this module.

Maven Dependency

<dependency>
     <groupId>com.subshell.sophora.webapp</groupId>
     <artifactId>sophora-webapp-routing</artifactId>
     <version>x.y.z</version>
</dependency>

Routing Configuration

The routing configuration is done in the application.yml of the Sophora Web Application Framework. Here is a sample extract:

sophora:
  web: 
    routing:
      node-types:
        - name: all # special type for all node types 
          types:
            - name: print
              template: "/common/print.html"
        - name: "sophora-example-nt:image"
          types: 
            - name: default
              servlet:
                name: "/system/com.subshell.sophora.webapp.components.servlet.image.ImageServlet"
                properties: {}

Possible keys for list elements in sophora.web.routing.node-types

Possible keys for list elements in sophora.web.routing.node-types
KeyDescription
nameThe name of the node type to match. The special type all matches all node types if there is no specific mapping for a node type.
types.nameThe name of the mapping type in the request URL. If "default", the type has not to be specified in the URL. E.G. the mapping type in the following URL would be print: https://subshell.com/test/example-story100~print.html
types.templateThe path to the template file that should be used.
types.servlet.nameThe registered path of the servlet to use. Check out our predefined servlets in the Additional Components module.
types.servlet.propertiesGeneric map of individual properties for the specified servlet
types.forwardAny URL the request will be forwarded to.

Templates

Template routing is configured in the application.yml. The following sample would route /example-story100.html to the story.html template and /example-story100~print.html to the story-print.html template, assuming that example-story100 is of type sophora-example-nt:story.

node-types:
  - name: "sophora-example-nt:story"
    types:
      - name: default
        template: "/document/story.html"
      - name: print
        template: "/document/story-print.html"

Dynamic Content in Templates

Per default, the requested document and its properties are available in a template via the sophoraDocument attribute. The provided object is of type com.subshell.sophora.client.ISophoraDocument.

Additional attributes can be made available by implementing the IRoutingModelMapProvider interface. You will also have to provide a bean of the implementing class. All attributes returned by IRoutingModelMapProvider#getModelMap are then available in the document. If the map contains existing attributes, such as the sophoraDocument attribute, they are overwritten.

Redirects

Redirects are configured in redirect documents. No further configuration is needed in the WebApp.

Static Resources

The static resources of a WebApp must be located within the resources folder. You will also have to provide the site name:

sophora:
  web: 
    routing:
      site: mySite

StaticAssetUrlBuilder

If you want to generate URLs for your static resources, you may use the com.subshell.sophora.webapp.routing.asset.StaticAssetUrlBuilder. The StaticAssetUrlBuilder will generate URLs with the following format:

[domain]/[site]/<assetPath>
Explanation of the static resource URL parts
PartExplanation
domainThe configured domain of the URL module configuration. Will only be present when an absolute URL will be generated and if the domain-name is configured.
siteThe configured site name. Will only be present, when URL module configuration does not prohibit the site prefix.
assetPathThe relative path to the concrete asset the URL has been generated for. This should usually start with "/resources/"

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