Dropwizard中的自定义码头过滤器 [英] Custom Jetty Filters in Dropwizard
本文介绍了Dropwizard中的自定义码头过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在我的Dropwizard实例中添加自定义标头过滤器,以查看请求的版本是否已同步到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.
我看到您可以使用FilterBuilder
添加码头CrossOriginFilters
.但是,我在弄清楚如何设置自定义过滤器时遇到了麻烦.
I see you can use FilterBuilder
to add jetty CrossOriginFilters
. However, I am having trouble figuring out how to set a custom filter.
谢谢
推荐答案
通过环境类.
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, "/*");
}
您可以通过更改EnumSet.allOf(DispatcherType.class)
这篇关于Dropwizard中的自定义码头过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文