Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Jetty Filters in Dropwizard

I'm attempting to add a custom header filter in my Dropwizard instance to check to see if the request's version is synced to the Dropwizard instance's version.

I see you can use FilterBuilder to add jetty CrossOriginFilters. However, I am having trouble figuring out how to set a custom filter.

Thanks

like image 562
jbenowitz Avatar asked Dec 01 '22 03:12

jbenowitz


1 Answers

Via the Environment class.

https://dropwizard.github.io/dropwizard/manual/core.html#environments

@Override
public void run(MyApplicationConfiguration configuration, Environment environment) {
    environment.servlets().addFilter("Custom-Filter-Name", new MyCustomFilter()).addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}

You can choose which Dispatch types by changing EnumSet.allOf(DispatcherType.class)

like image 177
dom farr Avatar answered Dec 15 '22 04:12

dom farr