public class MyApplication extends ResourceConfig {
public MyApplication() {
/* // Register resources and providers using package-scanning.
packages("com.keylesson.service");
// Register my custom provider - not needed if it's in my.package.
register(TestFilter.class);
register(TestFilter2.class);*/
}
}
取消注释后的上述代码能够执行两个过滤器类,但顺序是 TestFilter2,然后是 TestFilter。我不太喜欢这种 Resourceconfig 方法,我想为 Jersey2.3 使用旧式 web.xml。用于过滤器的 jersey 1.x init-params 在 jersey2.3 中不起作用。任何人都可以帮我提供 jersey2.3 的示例 web.xml 以保证过滤器的执行吗?并且还在序列 testfilter 中,然后是 testfilter2?
最佳答案
您可以为过滤器配置优先级。几个选项
使用 @Priority对于您的过滤器类,传入一个值(例如 @Priority(1))。数字越小,优先级越高(不需要在 web.xml 或 Application 子类中做任何特殊的事情)
@Priority(6000)
public class MyFilter1 ... {}
@Priority(6001)
public class MyFilter2 ... {}
参见 Priorities
通过可注入(inject)的 Configurable 以编程方式将其配置到应用程序中.有点像
@ApplicationPath("/")
public class MyApplication extends Application {
public MyApplication(@Context Configurable configurable) {
configurable.register(MyFilter1.class, 1000);
configurable.register(MyFilter2.class, 1001);
}
}
或者使用 ResourceConfig 简单地调用 register 而不注入(inject) Configurable。参见重载的 API register
public ResourceConfig register(Object component, int bindingPriority)
例如
public class MyApplication extends ResourceConfig {
public MyApplication() {
...
register(TestFilter.class, 6000);
register(TestFilter2.class, 6001);*/
}
}
仅供引用,Priorites 中有内置常量类。
public final class Priorities {
private Priorities() { }
public static final int AUTHENTICATION = 1000;
public static final int AUTHORIZATION = 2000;
public static final int HEADER_DECORATOR = 3000;
public static final int ENTITY_CODER = 4000;
public static final int USER = 5000;
}
这些由框架的一些内置组件使用,因此您在为优先级指定数字时可能需要考虑这些。你可以像这样使用它们
@Priority(Priorities.USER)
// or @Priority(Priorities.USER + 1)
public class MyFilter ... {}
关于java - Jersey 2.3 为 ContainerRequestFilter 设置优先级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26989608/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht