我正在使用一个websphere liberty profile webserver,我已经部署了几个应用程序。 这些应用程序正在发送请求消息,我想创建一个servlet过滤器而不更改应用程序 因此我可以看到应用程序正在发送和接收的内容。另外我想添加新的请求标题。创建一个servlet-filter websphere liberty配置文件?
0
A
回答
3
您可以使用ServletContainerInitializer来注册新的ServletFilters。增加了一个响应报头的示例实现可能是这样的:
public class SCI implements ServletContainerInitializer {
@Override
public void onStartup(Set<Class<?>> arg0, ServletContext arg1)
throws ServletException {
arg1.addFilter("myFilter", MyFilter.class).addMappingForUrlPatterns(null, false, "/*");
}
}
的MyFilter类是这样的:
public static class MyFilter implements Filter {
@Override
public void destroy() { }
@Override
public void doFilter(ServletRequest arg0, ServletResponse arg1,
FilterChain arg2) throws IOException, ServletException {
if (arg1 instanceof HttpServletResponse) {
((HttpServletResponse) arg1).addHeader("Test", "Test");
}
arg2.doFilter(arg0, arg1);
}
@Override
public void init(FilterConfig arg0) throws ServletException { }
}
然后,您需要此使用文件名为META-INF注册/服务/ ServletContainerInitializer应包含的Servlet容器初始化的完全限定类名称,例如:
test.SCI
通常你在一个罐子里我这些打包n中的应用程序,但因为你不想更新应用程序,而不是你配置的服务器是这样的:
<featureManager>
<feature>bells-1.0</feature>
</featureManager>
<library id="init">
<file name="path/to/jar"/>
</library>
<bell libraryRef="init"/>
的ServletContainerInitializer将被用于所有启动Web应用程序允许您添加过滤器。请注意,这将针对所有已启动的Web应用程序(包括集成到Liberty运行时的应用程序)调用,例如管理中心和REST连接器。
相关问题
- 1. WebSphere Liberty配置文件JAXBContext ClassCastException
- 2. Websphere Application Server Liberty 17.0.0.2 - 配置文件
- 3. WebSphere Liberty配置文件日志
- 4. 在Websphere Liberty配置文件中启用Gzip压缩liberty配置文件
- 5. Websphere Liberty配置文件 - 事务Websphere MQ连接工厂
- 6. 使用多个websphere liberty配置文件服务器而不是单个websphere 8?
- 7. 在Websphere Liberty配置文件中使用bouncycastle
- 8. 如何在Bluemix上启用verbosegc WebSphere Liberty配置文件
- 9. WebSphere Liberty配置文件:找不到上下文根
- 10. wasspmsclient不支持在websphere 8.5 liberty配置文件
- 11. 在WebSphere Liberty中配置env-entry值?
- 12. Websphere Liberty配置文件AdminCenter页面未加载
- 13. WebSphere Liberty配置文件和Subversion源代码管理
- 14. 替换为websphere中的WSCallHelper.clearStatementCache(连接)Liberty配置文件
- 15. java.lang.NoClassDefFoundError:javax/validation/groups/Websphere Liberty配置文件中的缺省值
- 16. Liberty配置文件配置问题(log4j2)
- 17. 如何在Websphere Liberty配置文件中启用wmqJmsClient-1.1功能?
- 18. WebSphere Liberty配置文件连接器端口
- 19. 在Websphere Liberty中配置多个出站SSL设置?
- 20. liberty配置文件的默认安装位置
- 21. 如何将安全角色映射到websphere Liberty配置文件中的ldap组
- 22. 如何在websphere liberty配置文件中设置绝对会话超时?
- 23. 在Websphere Liberty配置文件中使用ejb无状态的CODI 8.5.5
- 24. 基于Tomcat配置的Worklight WAS Liberty配置文件配置
- 25. 无法在Websphere 6.中创建配置文件,RAD 7.5 Windows 7
- 26. 以编程方式配置WebSphere 8.5 Liberty Profile的方法?
- 27. Liberty配置文件服务器
- 28. websphere liberty配置文件 - 将数据库连接错误添加到日志中
- 29. 当我启动websphere v8.5 liberty配置文件时出现跟随错误
- 30. 新创建的Websphere配置文件在创建后未在RAD中显示
这是我正在寻找,但对于一些reasen这是行不通的。 我是对的,我可以将类包装在一个罐子里? –
是的,您需要将类和META-INF打包到同一个jar文件中。上面的代码在我们2月份的测试版上进行了测试,它确实有效。如果没有日志,很难知道为什么它不能正常工作,但要确保安装了铃声-1.0功能。 – Alasdair
非常感谢。它现在正在工作,我的问题是maven没有正确地打包META-INF目录。 –