Skip to content

ConfigXml

Technology Consortium edited this page May 25, 2023 · 1 revision
  • Introduction
  • response-header-mapper
    • processorClass
  • mapping
    • url
    • processorClass
  • default
  • conditional
    • queryParamName
    • queryParamValue
  • response-headers

Introduction

The file response-header-filter.xml contains instructions for the filter to process requests. It basically contains a set of mappings which are internally processed as Rules. If an incoming request is found to be a match with one of the mappings, the corresponding Rules are applied to the response.

For a sample mapping file, click here The file content is processed according to these rules:

  1. The file should have response-header-mapper as the root node.

  2. Each node (in the xml) with the name mapping is identified as mapping rule and
    gets converted into a Rule.
    url is a mandatory attribute in the mapping node; mappings without a url are rejected.

  3. Subsequent mappings for the same url will OVERRIDE the previous Rule.
    Last Rule wins.

  4. Each mapping can have only one default response-header list.
    In cases of multiple such declarations, the Last <default> declaration wins.

  5. Each mapping can have any number of conditional mappings.
    All these rules are treated as mutually exclusive.

  6. Both, default and conditional nodes should have a <response-headers> node. In case of multiple such nodes, Last <response-headers> declaration wins.

  7. Each <response-headers> node may contain one or more <header> nodes. Each such node has to have two mandatory attributes, key and value.

  8. Both, queryParamName and queryParamValue, are required attributes in a conditional tag. They can't be left blank or undeclared.

  9. Values inside the queryParamValue attribute are parsed as a Pattern.

response-header-mapper

  • Description: This is the root node for the filter configuration file and is a expected node.

  • Required: Yes

  • Attributes:

    processorClass

    • Description: A fully qualified class name for the processor class, if you want to process the response headers on your own. You would need a processor class when setting the headers needs to be done after some sort of evaluation over the request and/or response.
      Your class should implement the com.avlesh.web.filter.responseheaderfilter.MappingProcessor interface.
    • Required: No
    • Default: com.avlesh.web.filter.responseheaderfilter.DefaultMappingProcessor

mapping

  • Description: A mapping node is set of rules for a matching url pattern.

  • Required: Yes

  • Attributes:

    url

    • Description: The base url to which the corresponding mapping should be applied to. This is only supposed to be the uri. To be able to use your request queryString, read the conditional node section.
    • Required: Yes
    • Example: <mapping url="/ajax/*.html">

    processorClass

  • Description: A fully qualified class name for the processor class for this particular mapping, if you want to process the response headers on your own or differently from other mappings. You would need a processor class when setting the headers needs to be done after some sort of evaluation over the request and/or response.
    Your class should implement the com.avlesh.web.filter.responseheaderfilter.MappingProcessor interface.

  • Required: No

  • Default: com.avlesh.web.filter.responseheaderfilter.DefaultMappingProcessor

  • Example: <mapping url="/ajax/*.html" processorClass="com.foo.MyAjaxProcessor">

default

  • Description: One of the possible child nodes for a mapping node. Rules specified under default is the default fallback in case of absence of conditional nodes. Each mapping can have only one default. If you specify multiple such default's the last one is respected.

  • Required: No

  • Example: <mapping url="/ajax/*.html"> <default> <response-headers> <header key="Content-Type" value="text/xml"/> <header key="Cache-Control" value="no-cache"/> </response-headers> </default> </mapping>

    conditional

  • Description: One of the possible child nodes for a mapping node. A mapping node may have many conditional nodes. The conditional nodes can be used to apply specific and different set of rules based on query parameters for the request.

  • Required: No

  • Attributes:

    queryParamName

    • Description: The query parameter based on which you want to have a conditional rule. e.g. you may want to apply different response headers to /site/log-analyzer.html?type=xxxx based on the type parameter. Your queryParamName in this case would be type.
    • Required: Yes

    queryParamValue

  • Description: In the above example, the value has to be specified in the queryParamValue attribute. This also takes a Pattern.

  • Required: Yes

  • Example: <mapping url="/ajax/*.html"> <conditional queryParamName="type" queryParamValue="(country|city)"> <response-headers> <header key="Content-Type" value="text/xml"/> <header key="Cache-Control" value="private, max-age=86400"/> </response-headers> </conditional> </mapping>

    • NOTE: Conditional rules are evaluated from bottom to top. Last matching rule (in the config) wins.

response-headers

Any default or conditional node is considered invalid without a list response-headers that needs to be applied for a particular mapping. A response-headers node comprises of a list of header nodes.

header

This the lowest unit in the configuration. Each header is a specific response header that needs to be applied to the response. A header comprises of key: To be specific, a response-header key.
value: The value for the above mentioned key.

Clone this wiki locally