enhancement: allow properties file instead of init-params

Create issue
Issue #4 resolved
Will Berry created an issue

Justification: If it were possible to specify a properties file in web.xml where this filter is configured, then web.xml could stay exactly the same for multiple deployments of a webapp with different CORS configuration (i.e. production and test). It is safer for automated deployment systems to generate an absent file than to replace one from the WAR; and while excluding web.xml from a WAR entirely is possible (with Maven anyway), it's not preferred.

I suggest something like this for web.xml:

<filter>
    <filter-name>CORS</filter-name>
    <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
    <init-param>
        <param-name>configuration.propertiesFile</param-name>
        <param-value>WEB-INF/config/corsFilter.properties</param-value>
    </init-param>
</filter>

And in the corsFilter.properties file:

cors.allowOrigin=http://mysite.com https://mysite.com
cors.allowSubdomains=true

And so on. Basically all the supported init-param names could occur in the properties file with the same semantics.

Comments (4)

  1. Vladimir Dzhuvinov

    Thanks for submitting this proposal, I'll think about it.

    Hybrid configuration - with init-params and properties - should actually work too.

  2. David Bellem

    I would prefer using an environment variable to indicate where to find the properties file. E.g. log4j does it this way.

  3. Vladimir Dzhuvinov

    The CORS configuration can now also be passed as a properties file which location is specified by a filter init parameter named "cors.configurationFile". See commits leading up to 6146293.

    <filter>
        <filter-name>CORS</filter-name>
        <filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
        <init-param>
            <param-name>cors.configurationFile</param-name>
            <param-value>WEB-INF/config/corsFilter.properties</param-value>
        </init-param>
    </filter>
    
  4. Log in to comment