Skip to content

Configuring Servlet Filters

johnmcclean-aol edited this page Dec 10, 2015 · 4 revisions

Filters with Microservices and Micro-monoliths

Microserver services can all run in true Microservice stand-alone style, or Microserver allows multiple otherwise independent services to be bundled together at runtime to act as a 'micro'-monolith.

Autodiscovered Filters, are discovered within the shared Spring context, and thus (currently) become globally available to all bundled microservices. If you are not bundling services - this is not significant, but if you are, or are planning to - it is something to be mindful of.

Filters can be configured locally via the Module interface (when you start your Microservice),or by the Plugin interface.

Configuring Filters Globally

In order to automagically add a Filter to all bundled Microservices, implement the interface FilterConfiguration on a Spring bean. If the bean implementing FilterConfiguration, also implements Filter only the method getMapping() need be overriden.

    public String[] getMapping();

The following default methods are provided that can be overrided if needed

	default Class<? extends Filter> getFilter()

Default behaviour is use the class defining the configuration as the Filter

	default String getName()


	default Map<String,String> getInitParameters()

Configuring Local Filters

These Filters will only be available on the Microservice modules they are configured against.

In your Module object override

     public Map<String,Filters> getFilters()

To configure module local servlets and their contexts Urls .

     public Class<? extends FilterConfiguration>[] getFilterConfigurationClass()

Configuring Filters in a Plugin

Filters can be configured inside a plugin both as explicitly defined Filters, or as auto discovered Spring Beans that implement FilterConfiguration.

Override the filters method to provide a lookup function for the Filters

	public Function<ServerData,Map<String,Filter>> filters(){
		return serverData -> myMapOfFilters;
	}

or override springClasses and add your FilterConfiguration Spring beans there

        public Set<Class> springClasses(){
		return new HashSet<>();
	}