Constructor based initialization

Merged
#7 · Created  · Last updated

Merged pull request

Merged in monowai/cors-filter (pull request #7)

656ac90·Author: ·Closed by: ·2014-10-05

Description

See https://bitbucket.org/thetransactioncompany/cors-filter/issue/24

Somewhere in your spring configuration files, you will init the bean similar to thus:

<bean id="corsFilter" class="com.myproject.filters.CorsSpringFilter" > <constructor-arg > <bean class="com.thetransactioncompany.cors.CORSConfiguration" > <constructor-arg> <!-- Init the CORS filter via Spring so that properties can be extracted from anywhere--> <props> <prop key="cors.allowOrigin">${cors.allowOrigin}</prop> <prop key="cors.allowSubdomains">${cors.allowSubdomains}</prop> <prop key="cors.supportedHeaders">${cors.supportedHeaders}</prop> <prop key="cors.exposedHeaders">${cors.exposedHeaders}</prop> <prop key="cors.supportedMethods">${cors.supportedMethods}</prop> <prop key="cors.supportsCredentials">${cors.supportsCredentials}</prop> <prop key="cors.maxAge">${cors.maxAge}</prop> <prop key="cors.tagRequests">${cors.tagRequests}</prop> </props> </constructor-arg> </bean> </constructor-arg> </bean>

Spring user still needs to developer a wrapping class along the lines of

@Component public class CorsSpringFilter implements javax.servlet.Filter { static CORSFilter corsFilter; public CorsSpringFilter(CORSConfiguration corsConfiguration) throws ServletException { corsFilter = new CORSFilter(corsConfiguration); } public CorsSpringFilter() { super(); } @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { corsFilter.doFilter(request, response, chain); } @Override public void destroy() { corsFilter.destroy(); } }

Which can be configured for deployment in web.xml thus:

<filter> <filter-name>corsFilter</filter-name> <filter-class> com.auditbucket.helper.CorsSpringFilter </filter-class> </filter>

0 attachments

0 comments

Loading commits...